You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2012/11/08 05:10:34 UTC
svn commit: r1406916 - in /cxf/branches/2.5.x-fixes: ./
osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/
osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/internal/
osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/
Author: ffang
Date: Thu Nov 8 04:10:33 2012
New Revision: 1406916
URL: http://svn.apache.org/viewvc?rev=1406916&view=rev
Log:
Merged revisions 1406914 via svnmerge from
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
................
r1406914 | ffang | 2012-11-08 12:02:42 +0800 (四, 08 11 2012) | 9 lines
Merged revisions 1406907 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1406907 | ffang | 2012-11-08 11:47:26 +0800 (四, 08 11 2012) | 1 line
[CXF-4622]cxf:list-endpoints - Add option to list the full url of the service
........
................
Modified:
cxf/branches/2.5.x-fixes/ (props changed)
cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/CXFController.java
cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java
cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFControllerImpl.java
cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml
Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/trunk:r1406907
Merged /cxf/branches/2.6.x-fixes:r1406914
Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/CXFController.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/CXFController.java?rev=1406916&r1=1406915&r2=1406916&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/CXFController.java (original)
+++ cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/CXFController.java Thu Nov 8 04:10:33 2012
@@ -22,6 +22,7 @@ package org.apache.cxf.karaf.commands;
import java.util.List;
import org.apache.cxf.Bus;
+import org.osgi.service.cm.ConfigurationAdmin;
/**
*
@@ -31,5 +32,7 @@ public interface CXFController {
List<Bus> getBusses();
Bus getBus(String name);
+
+ ConfigurationAdmin getConfigAdmin();
}
Modified: cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java?rev=1406916&r1=1406915&r2=1406916&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java (original)
+++ cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java Thu Nov 8 04:10:33 2012
@@ -19,15 +19,22 @@
package org.apache.cxf.karaf.commands;
+import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.apache.cxf.Bus;
+import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.endpoint.ServerRegistry;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
/**
*
@@ -43,6 +50,10 @@ public class ListEndpointsCommand extend
required = false, multiValued = false)
String name;
+ @Option(name = "-f", aliases = {"--fulladdress" },
+ description = "Display full address of an endpoint ", required = false, multiValued = false)
+ boolean fullAddress;
+
private CXFController cxfController;
public void setController(CXFController controller) {
@@ -71,10 +82,83 @@ public class ListEndpointsCommand extend
String qname = serv.getEndpoint().getEndpointInfo().getName().getLocalPart();
String started = serv.isStarted() ? "Started" : "Stopped";
String address = serv.getEndpoint().getEndpointInfo().getAddress();
+ if (fullAddress) {
+ address = toFullAddress(address);
+ }
String busId = b.getId();
System.out.println(String.format(OUTPUT_FORMAT, qname, started, address, busId));
}
}
return null;
- }
+ }
+
+ private String toFullAddress(String address) throws IOException, InvalidSyntaxException {
+ ConfigurationAdmin configAdmin = getConfigurationAdmin();
+ if (address.startsWith("/") && configAdmin != null) {
+ String httpPort = null;
+ String cxfContext = null;
+ httpPort = extractConfigProperty(configAdmin, "org.ops4j.pax.web", "org.osgi.service.http.port");
+ cxfContext = extractConfigProperty(configAdmin, "org.apache.cxf.osgi", "org.apache.cxf.servlet.context");
+ if (StringUtils.isEmpty(cxfContext)) {
+ cxfContext = getCXFOSGiServletContext();
+ }
+ if (StringUtils.isEmpty(httpPort)) {
+ httpPort = getHttpOSGiServicePort();
+ }
+ if (!StringUtils.isEmpty(httpPort) && !StringUtils.isEmpty(cxfContext)) {
+ address = "http://localhost:" + httpPort + cxfContext + address;
+ }
+ }
+ return address;
+ }
+
+ private String extractConfigProperty(ConfigurationAdmin configAdmin,
+ String pid, String propertyName) throws IOException,
+ InvalidSyntaxException {
+ String ret = null;
+ Configuration[] configs = configAdmin.listConfigurations("(service.pid=" + pid + ")");
+ if (configs != null && configs.length > 0) {
+ Configuration configuration = configs[0];
+ if (configuration != null) {
+ ret = (String)configuration.getProperties().get(propertyName);
+ }
+ }
+ return ret;
+ }
+
+ private ConfigurationAdmin getConfigurationAdmin() {
+ return cxfController.getConfigAdmin();
+ }
+
+ private String getCXFOSGiServletContext() throws InvalidSyntaxException {
+ String ret = null;
+ String filter = "(&(" + "objectclass=" + "javax.servlet.Servlet"
+ + ")(servlet-name=cxf-osgi-transport-servlet))";
+
+ ServiceReference ref = getBundleContext().getServiceReferences(null, filter)[0];
+
+ if (ref != null) {
+ ret = (String)ref.getProperty("alias");
+ }
+
+ return ret;
+
+ }
+
+ private String getHttpOSGiServicePort() throws InvalidSyntaxException {
+ String ret = null;
+ String filter = "(&(" + "objectclass=" + "org.osgi.service.http.HttpService"
+ + "))";
+
+ ServiceReference ref = getBundleContext().getServiceReferences(null, filter)[0];
+
+ if (ref != null) {
+ ret = (String)ref.getProperty("org.osgi.service.http.port");
+ }
+
+ return ret;
+
+ }
+
+
}
Modified: cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFControllerImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFControllerImpl.java?rev=1406916&r1=1406915&r2=1406916&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFControllerImpl.java (original)
+++ cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFControllerImpl.java Thu Nov 8 04:10:33 2012
@@ -30,6 +30,7 @@ import org.apache.cxf.common.logging.Log
import org.apache.cxf.karaf.commands.CXFController;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationAdmin;
/**
@@ -38,6 +39,7 @@ public class CXFControllerImpl implement
private static final Logger LOG = LogUtils.getL7dLogger(CXFControllerImpl.class);
private BundleContext bundleContext;
+ private ConfigurationAdmin configAdmin;
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
@@ -82,6 +84,14 @@ public class CXFControllerImpl implement
return null;
}
+ public ConfigurationAdmin getConfigAdmin() {
+ return configAdmin;
+ }
+
+ public void setConfigAdmin(ConfigurationAdmin configAdmin) {
+ this.configAdmin = configAdmin;
+ }
+
}
Modified: cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml?rev=1406916&r1=1406915&r2=1406916&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml (original)
+++ cxf/branches/2.5.x-fixes/osgi/karaf/commands/src/main/resources/OSGI-INF/blueprint/cxf-karaf-commands.xml Thu Nov 8 04:10:33 2012
@@ -40,9 +40,10 @@
</command>
</command-bundle>
-
+ <reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />
<bean id="cxfController" class="org.apache.cxf.karaf.commands.internal.CXFControllerImpl">
<property name="bundleContext" ref="blueprintBundleContext"/>
+ <property name="configAdmin" ref="configAdmin"/>
</bean>
-</blueprint>
\ No newline at end of file
+</blueprint>