cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1187471 - in /cxf/trunk: osgi/karaf/features/src/main/resources/ rt/core/src/main/java/org/apache/cxf/bus/extension/ rt/core/src/main/java/org/apache/cxf/bus/osgi/ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ rt/trans...
Date Fri, 21 Oct 2011 17:13:31 GMT
Author: dkulp
Date: Fri Oct 21 17:13:31 2011
New Revision: 1187471

URL: http://svn.apache.org/viewvc?rev=1187471&view=rev
Log:
Update wsn to allow specifying the full root url instead of just the
port so you can bind to just a specific address or set to "" to make it
use the pax-web servlet based transport.

Bunch of updates to allow "pure jaxws" Endpoint.publish calls to get a
Bus that can be OSGi monitored and use the pax-web servlet.

Modified:
    cxf/trunk/osgi/karaf/features/src/main/resources/features.xml
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
    cxf/trunk/rt/transports/http/src/main/resources/META-INF/spring/osgiservlet.xml
    cxf/trunk/services/wsn/wsn-osgi/src/main/resources/OSGI-INF/blueprint/cxf-wsn.xml

Modified: cxf/trunk/osgi/karaf/features/src/main/resources/features.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/osgi/karaf/features/src/main/resources/features.xml?rev=1187471&r1=1187470&r2=1187471&view=diff
==============================================================================
--- cxf/trunk/osgi/karaf/features/src/main/resources/features.xml (original)
+++ cxf/trunk/osgi/karaf/features/src/main/resources/features.xml Fri Oct 21 17:13:31 2011
@@ -144,7 +144,8 @@
 
         <config name="org.apache.cxf.wsn">
             cxf.wsn.activemq = vm:localhost
-            cxf.wsn.port = 8182
+            cxf.wsn.rootUrl = http://0.0.0.0:8182
+            cxf.wsn.context = /wsn
         </config>
 
         <feature version="[5.4,6)">activemq</feature>

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java?rev=1187471&r1=1187470&r2=1187471&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java Fri Oct 21
17:13:31 2011
@@ -131,6 +131,9 @@ public class Extension {
         return namespaces;
     }
     
+    public void setArgs(Object a[]) {
+        args = a;
+    }
     
     public Class<?> getClassObject(ClassLoader cl) {
         if (clazz == null) {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java?rev=1187471&r1=1187470&r2=1187471&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java Fri
Oct 21 17:13:31 2011
@@ -22,6 +22,8 @@ package org.apache.cxf.bus.osgi;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
@@ -35,11 +37,14 @@ import java.util.logging.Logger;
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.extension.Extension;
 import org.apache.cxf.bus.extension.ExtensionFragmentParser;
+import org.apache.cxf.bus.extension.ExtensionManagerImpl;
 import org.apache.cxf.bus.extension.ExtensionRegistry;
 import org.apache.cxf.bus.osgi.OSGiAutomaticWorkQueue.WorkQueueList;
 import org.apache.cxf.buslifecycle.BusLifeCycleListener;
 import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.configuration.ConfiguredBeanLocator;
+import org.apache.cxf.configuration.ConfiguredBeanLocator.BeanLoaderListener;
 import org.apache.cxf.workqueue.AutomaticWorkQueueImpl;
 import org.apache.cxf.workqueue.WorkQueueManager;
 import org.osgi.framework.Bundle;
@@ -83,7 +88,7 @@ public class OSGiExtensionLocator implem
     public void start(BundleContext context) throws Exception {
         context.addBundleListener(this);
         id = context.getBundle().getBundleId();
-        registerBusListener();
+        registerBusListener(context);
         for (Bundle bundle : context.getBundles()) {
             if ((bundle.getState() == Bundle.RESOLVED 
                 || bundle.getState() == Bundle.STARTING 
@@ -134,8 +139,9 @@ public class OSGiExtensionLocator implem
         }
         workQueues.queues.clear();
     }
-    private void registerBusListener() {
+    private void registerBusListener(final BundleContext context) {
         listener = new Extension(OSGIBusListener.class);
+        listener.setArgs(new Object[] {context});
         ExtensionRegistry.addExtensions(Collections.singletonList(listener));
     }
     private void unregisterBusListener() {
@@ -182,10 +188,24 @@ public class OSGiExtensionLocator implem
         
         Bus bus;
         ServiceRegistration service;
+        BundleContext defaultContext;
  
         public OSGIBusListener(Bus b) {
+            this(b, null);
+        }
+        public OSGIBusListener(Bus b, Object args[]) {
             bus = b;
+            if (args != null && args.length > 0 
+                && args[0] instanceof BundleContext) {
+                defaultContext = (BundleContext)args[0];
+            }
             bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
+            final ConfiguredBeanLocator cbl = bus.getExtension(ConfiguredBeanLocator.class);
+            if (cbl instanceof ExtensionManagerImpl) {
+                // wire in the OSGi things
+                bus.setExtension(new OSGiBeanLocator(cbl, defaultContext), 
+                                 ConfiguredBeanLocator.class);
+            }
         }
         private Version getBundleVersion(Bundle bundle) {
             Dictionary headers = bundle.getHeaders();
@@ -224,6 +244,51 @@ public class OSGiExtensionLocator implem
         }
     }
     
+    public static class OSGiBeanLocator implements ConfiguredBeanLocator {
+        final ConfiguredBeanLocator cbl;
+        final BundleContext context;
+        public OSGiBeanLocator(ConfiguredBeanLocator c, BundleContext ctx) {
+            cbl = c;
+            context = ctx;
+        }
+        public <T> T getBeanOfType(String name, Class<T> type) {
+            return cbl.getBeanOfType(name, type);
+        }
+        public <T> Collection<? extends T> getBeansOfType(Class<T> type)
{
+            Collection<? extends T> ret = cbl.getBeansOfType(type);
+            
+            if (ret == null || ret.isEmpty()) {
+                List<T> list = new ArrayList<T>();
+                try {
+                    ServiceReference refs[] = context.getServiceReferences(type.getName(),
null);
+                    if (refs != null) {
+                        for (ServiceReference r : refs) {
+                            list.add(type.cast(context.getService(r)));
+                        }
+                    }
+                    if (!list.isEmpty()) {
+                        return list;
+                    }
+                } catch (Exception ex) {
+                    //ignore, just don't support the OSGi services
+                    LOG.info("Try to find the Bean with type:" + type 
+                        + " from OSGi services and get error: " + ex);  
+                }
+            }
+            return ret;
+        }
+        public <T> boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T>
listener) {
+            return cbl.loadBeansOfType(type, listener);
+        }
+        public boolean hasConfiguredPropertyValue(String beanName, String propertyName,
+                                                  String value) {
+            return cbl.hasConfiguredPropertyValue(beanName, propertyName, value);
+        }
+        public List<String> getBeanNamesOfType(Class<?> type) {
+            return cbl.getBeanNamesOfType(type);
+        }
+    }
+    
     public class OSGiExtension extends Extension {
         final Bundle bundle;
         public OSGiExtension(Extension e, Bundle b) {

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java?rev=1187471&r1=1187470&r2=1187471&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
Fri Oct 21 17:13:31 2011
@@ -43,28 +43,36 @@ public class CXFNonSpringServlet extends
     private Bus bus;
     private ServletController controller;
     private ClassLoader loader;
+    private boolean loadBus = true;
     
     public CXFNonSpringServlet() {
     }
 
     public CXFNonSpringServlet(DestinationRegistry destinationRegistry) {
+        this(destinationRegistry, true);
+    }
+    public CXFNonSpringServlet(DestinationRegistry destinationRegistry,
+                               boolean loadBus) {
         this.destinationRegistry = destinationRegistry;
+        this.loadBus = loadBus;
     }
 
     @Override
     public void init(ServletConfig sc) throws ServletException {
         super.init(sc);
-        if (this.bus == null) {
+        if (this.bus == null && loadBus) {
             loadBus(sc);
         }
-        loader = bus.getExtension(ClassLoader.class);
-        ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
-        resourceManager.addResourceResolver(new ServletContextResourceResolver(
-                                               sc.getServletContext()));
-
-        if (destinationRegistry == null) {
-            this.destinationRegistry = getDestinationRegistryFromBus(this.bus);
+        if (this.bus != null) {
+            loader = bus.getExtension(ClassLoader.class);
+            ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
+            resourceManager.addResourceResolver(new ServletContextResourceResolver(
+                                                   sc.getServletContext()));
+            if (destinationRegistry == null) {
+                this.destinationRegistry = getDestinationRegistryFromBus(this.bus);
+            }
         }
+
         this.controller = createServletController(sc);
     }
 
@@ -112,7 +120,9 @@ public class CXFNonSpringServlet extends
             if (loader != null) {
                 origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
             }
-            BusFactory.setThreadDefaultBus(bus);
+            if (bus != null) {
+                BusFactory.setThreadDefaultBus(bus);
+            }
             controller.invoke(request, response);
         } finally {
             BusFactory.setThreadDefaultBus(null);
@@ -136,6 +146,8 @@ public class CXFNonSpringServlet extends
     }
     
     public void destroyBus() {
-        bus.shutdown(true);
+        if (bus != null) {
+            bus.shutdown(true);
+        }
     }
 }

Modified: cxf/trunk/rt/transports/http/src/main/resources/META-INF/spring/osgiservlet.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/resources/META-INF/spring/osgiservlet.xml?rev=1187471&r1=1187470&r2=1187471&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/resources/META-INF/spring/osgiservlet.xml (original)
+++ cxf/trunk/rt/transports/http/src/main/resources/META-INF/spring/osgiservlet.xml Fri Oct
21 17:13:31 2011
@@ -47,6 +47,7 @@ http://www.springframework.org/schema/co
 
     <bean id="osgiServlet" class="org.apache.cxf.transport.servlet.CXFNonSpringServlet">
         <constructor-arg ref="destinationRegistry"/>
+        <constructor-arg value="false"/>
     </bean>
 
     <osgi:service ref="osgiServlet" interface="javax.servlet.Servlet">

Modified: cxf/trunk/services/wsn/wsn-osgi/src/main/resources/OSGI-INF/blueprint/cxf-wsn.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/services/wsn/wsn-osgi/src/main/resources/OSGI-INF/blueprint/cxf-wsn.xml?rev=1187471&r1=1187470&r2=1187471&view=diff
==============================================================================
--- cxf/trunk/services/wsn/wsn-osgi/src/main/resources/OSGI-INF/blueprint/cxf-wsn.xml (original)
+++ cxf/trunk/services/wsn/wsn-osgi/src/main/resources/OSGI-INF/blueprint/cxf-wsn.xml Fri
Oct 21 17:13:31 2011
@@ -24,7 +24,8 @@
     <cm:property-placeholder persistent-id="org.apache.cxf.wsn" update-strategy="reload">
         <cm:default-properties>
             <cm:property name="cxf.wsn.activemq" value="vm:localhost"/>
-            <cm:property name="cxf.wsn.port" value="8182" />
+            <cm:property name="cxf.wsn.rootUrl" value="http://0.0.0.0:8182" />
+            <cm:property name="cxf.wsn.context" value="/wsn" />
         </cm:default-properties>
     </cm:property-placeholder>
 
@@ -37,11 +38,11 @@
     <bean id="notificationBroker" class="org.apache.cxf.wsn.jaxws.JaxwsNotificationBroker"
init-method="init" destroy-method="destroy">
         <argument value="NotificationBroker" />
         <argument ref="activemq" />
-        <property name="address" value="http://0.0.0.0:${cxf.wsn.port}/wsn/NotificationBroker"
/>
+        <property name="address" value="${cxf.wsn.rootUrl}${cxf.wsn.context}/NotificationBroker"
/>
     </bean>
     <service ref="notificationBroker" interface="org.oasis_open.docs.wsn.brw_2.NotificationBroker">
         <service-properties>
-            <entry key="address" value="http://0.0.0.0:${cxf.wsn.port}/wsn/NotificationBroker"
/>
+            <entry key="address" value="${cxf.wsn.rootUrl}${cxf.wsn.context}/NotificationBroker"
/>
         </service-properties>
     </service>
 
@@ -49,11 +50,11 @@
     <bean id="createPullPoint" class="org.apache.cxf.wsn.jaxws.JaxwsCreatePullPoint" init-method="init"
destroy-method="destroy">
         <argument value="org.apache.cxf.wsn.client.CreatePullPoint" />
         <argument ref="activemq" />
-        <property name="address" value="http://0.0.0.0:${cxf.wsn.port}/wsn/CreatePullPoint"
/>
+        <property name="address" value="${cxf.wsn.rootUrl}${cxf.wsn.context}/CreatePullPoint"
/>
     </bean>
     <service ref="createPullPoint" interface="org.oasis_open.docs.wsn.bw_2.CreatePullPoint">
         <service-properties>
-            <entry key="address" value="http://0.0.0.0:${cxf.wsn.port}/wsn/CreatePullPoint"
/>
+            <entry key="address" value="${cxf.wsn.rootUrl}${cxf.wsn.context}/CreatePullPoint"
/>
         </service-properties>
     </service>
 



Mime
View raw message