Some cleanup/fixes for HTTP Context related deployments
authorSergey Beryozkin <sergeyb@apache.org>
Mon, 16 Jan 2012 16:02:57 +0000 (16:02 +0000)
committerSergey Beryozkin <sergeyb@apache.org>
Mon, 16 Jan 2012 16:02:57 +0000 (16:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/cxf/dosgi/trunk@1232046 13f79535-47bb-0310-9956-ffa450edef68

distribution/multi-bundle/pom.xml
distribution/multi-bundle/src/main/resources/distro_bundles.xml
distribution/single-bundle/pom.xml
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManager.java
parent/pom.xml

index b19108e..c59be1f 100644 (file)
     <dependency>
       <groupId>org.ops4j.pax.web</groupId>
       <artifactId>pax-web-spi</artifactId>
-      <version>1.0.8</version>
+      <version>${pax.web.version}</version>
     </dependency>
     <dependency>
       <groupId>org.ops4j.pax.web</groupId>
       <artifactId>pax-web-runtime</artifactId>
-      <version>1.0.8</version>
+      <version>${pax.web.version}</version>
     </dependency>
     <dependency>
       <groupId>org.ops4j.pax.web</groupId>
       <artifactId>pax-web-jetty</artifactId>
-      <version>1.0.8</version>
+      <version>${pax.web.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.servicemix.specs</groupId>
index 23bcbf2..87885e5 100644 (file)
@@ -20,9 +20,9 @@
   <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/spring-osgi-core-${spring.osgi.version}.jar</bundle>
   <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/spring-osgi-extender-${spring.osgi.version}.jar</bundle>
   <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/jetty-all-server-${jetty.version}.jar</bundle>
-  <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/pax-web-spi-1.0.8.jar</bundle>
-  <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/pax-web-runtime-1.0.8.jar</bundle>
-  <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/pax-web-jetty-1.0.8.jar</bundle>
+  <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/pax-web-spi-${pax.web.version}.jar</bundle>
+  <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/pax-web-runtime-${pax.web.version}.jar</bundle>
+  <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/pax-web-jetty-${pax.web.version}.jar</bundle>
   <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/org.apache.servicemix.bundles.jaxb-impl-${jaxbimpl.bundle.version}.jar</bundle>
   <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/org.apache.servicemix.bundles.wsdl4j-${wsdl4j.bundle.version}.jar</bundle>
   <bundle>cxf-dosgi-ri-multibundle-distribution-${project.version}-dir/apache-cxf-dosgi-ri-${project.version}/dosgi_bundles/org.apache.servicemix.bundles.xmlsec-${xmlsec.bundle.version}.jar</bundle>
index 9788aec..c9ccc4d 100644 (file)
     <dependency>
       <groupId>org.ops4j.pax.web</groupId>
       <artifactId>pax-web-runtime</artifactId>
-      <version>1.0.8</version>
+      <version>${pax.web.version}</version>
     </dependency>
     <dependency>
       <groupId>org.eclipse.jetty.aggregate</groupId>
     <dependency>
       <groupId>org.ops4j.pax.web</groupId>
       <artifactId>pax-web-jetty</artifactId>
-      <version>1.0.8</version>
+      <version>${pax.web.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.servicemix.specs</groupId>
index 92e79e2..b9cd3c7 100644 (file)
@@ -42,6 +42,7 @@ public class Constants {
     public static final String SERVICE_NAME = WSDL_CONFIG_PREFIX + ".service.name";
     public static final String PORT_NAME = WSDL_CONFIG_PREFIX + ".port.name";
     public static final String WSDL_LOCATION = WSDL_CONFIG_PREFIX + ".location";
+    public static final String WSDL_HTTP_SERVICE_CONTEXT = WSDL_CONFIG_PREFIX + ".httpservice.context";
     // Provider prefix
     public static final String PROVIDER_PREFIX = "org.apache.cxf";
     
index b3db45c..3e91742 100644 (file)
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -36,7 +35,6 @@ import org.apache.cxf.dosgi.dsw.Constants;
 import org.apache.cxf.dosgi.dsw.OsgiUtils;
 import org.apache.cxf.dosgi.dsw.qos.IntentMap;
 import org.apache.cxf.endpoint.AbstractEndpointFactory;
-import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.frontend.ServerFactoryBean;
@@ -75,17 +73,6 @@ public abstract class AbstractPojoConfigurationTypeHandler extends AbstractConfi
       }
     }
 
-    Map<String, String> registerPublication(Server server, String[] intents) {
-        Map<String, String> publicationProperties = new HashMap<String, String>();
-        publicationProperties.put(Constants.EXPORTED_CONFIGS, Constants.WS_CONFIG_TYPE);
-
-        String intentsValue = OsgiUtils.formatIntents(intents);
-        if (intentsValue.length() > 0) {
-            publicationProperties.put(Constants.INTENTS, intentsValue);
-        }
-        return publicationProperties;
-    }
-
     String [] applyIntents(BundleContext dswContext,
                            BundleContext callingContext,
                            List<AbstractFeature> features,
index 59fcc58..8913bc7 100644 (file)
@@ -36,8 +36,6 @@ import org.apache.cxf.dosgi.dsw.Constants;
 import org.apache.cxf.dosgi.dsw.OsgiUtils;
 import org.apache.cxf.dosgi.dsw.service.ExportRegistrationImpl;
 import org.apache.cxf.endpoint.Server;
-import org.apache.cxf.endpoint.ServerLifeCycleListener;
-import org.apache.cxf.endpoint.ServerLifeCycleManager;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.jaxb.JAXBDataBinding;
@@ -130,18 +128,7 @@ public class HttpServiceConfigurationTypeHandler extends AbstractPojoConfigurati
             return;
         }
 
-        CXFNonSpringServlet cxf = new CXFNonSpringServlet();
-        HttpService httpService = getHttpService();
-        try {
-            httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(), 
-                                       getHttpContext(dswContext, httpService));
-            registerUnexportHook(exportRegistration, contextRoot);
-            
-            LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot);
-        } catch (Exception e) {
-            throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e);
-        }
-        Bus bus = cxf.getBus();
+        Bus bus = registerServletAndGetBus(contextRoot, dswContext, exportRegistration);
         final ServiceReference sref = exportRegistration.getExportedService();
         DataBinding databinding;
         String dataBindingImpl = (String)exportRegistration.getExportedService()
@@ -181,9 +168,6 @@ public class HttpServiceConfigurationTypeHandler extends AbstractPojoConfigurati
             Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
             Server server = factory.create();
             
-            // TODO: does this still make sense ?!? 
-            registerStopHook(bus, httpService, server, contextRoot, Constants.WS_HTTP_SERVICE_CONTEXT);
-            
             endpdDesc = new EndpointDescription(endpointProps);
             exportRegistration.setServer(server);
      
@@ -197,11 +181,21 @@ public class HttpServiceConfigurationTypeHandler extends AbstractPojoConfigurati
         
      
     }
-
-    protected Map<String, String> registerPublication(Server server, String[] intents, String address) {
-        Map<String, String> publicationProperties = super.registerPublication(server, intents);
-        publicationProperties.put(Constants.WS_ADDRESS_PROPERTY, address);
-        return publicationProperties;
+    
+    protected Bus registerServletAndGetBus(String contextRoot, BundleContext dswContext,
+               ExportRegistrationImpl exportRegistration) {
+       CXFNonSpringServlet cxf = new CXFNonSpringServlet();
+        HttpService httpService = getHttpService();
+        try {
+            httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(), 
+                                       getHttpContext(dswContext, httpService));
+            registerUnexportHook(exportRegistration, contextRoot);
+            
+            LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot);
+        } catch (Exception e) {
+            throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e);
+        }
+        return cxf.getBus();
     }
 
     protected String constructAddress(BundleContext ctx, String contextRoot) {
@@ -238,10 +232,13 @@ public class HttpServiceConfigurationTypeHandler extends AbstractPojoConfigurati
     }
 
     protected String getServletContextRoot(Map sd, Class<?> iClass) {
-        String context = OsgiUtils.getProperty(sd, Constants.WS_HTTP_SERVICE_CONTEXT);
+       String context = OsgiUtils.getProperty(sd, Constants.WS_HTTP_SERVICE_CONTEXT);
         if (context == null) {
             context = OsgiUtils.getProperty(sd, Constants.WS_HTTP_SERVICE_CONTEXT_OLD);
         }
+        if (context == null) {
+            context = OsgiUtils.getProperty(sd, Constants.WSDL_HTTP_SERVICE_CONTEXT);
+        }
 
         if (context == null) {
             context = "/" + iClass.getName().replace('.', '/');
@@ -250,29 +247,6 @@ public class HttpServiceConfigurationTypeHandler extends AbstractPojoConfigurati
         return context;
     }
 
-    protected void registerStopHook(Bus bus, final HttpService httpService, Server theServer,
-                                    final String contextRoot, final String propertyName) {
-        if (bus != null) {
-            theServer.getEndpoint().put(propertyName, contextRoot);
-            ServerLifeCycleListener stopHook = new ServerLifeCycleListener() {
-                public void stopServer(Server s) {
-                    Object contextProperty = s.getEndpoint().get(propertyName);
-                    if (contextProperty != null && contextProperty.equals(contextRoot)) {
-                        httpService.unregister(contextRoot);
-                    }
-                }
-
-                public void startServer(Server s) {
-                }
-            };
-            ServerLifeCycleManager mgr = bus.getExtension(ServerLifeCycleManager.class);
-            if (mgr != null) {
-                mgr.registerListener(stopHook);
-            }
-        }
-    }
-
-
     protected HttpContext getHttpContext(BundleContext bundleContext, HttpService httpService) {
 
         HttpContext httpContext = httpService.createDefaultHttpContext();
index c8f7fb4..d25385c 100644 (file)
  */
 package org.apache.cxf.dosgi.dsw.handlers;
 
-import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
@@ -34,22 +31,14 @@ import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.UserResource;
-import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.http.HttpContext;
-import org.osgi.service.http.HttpService;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 
 public class JaxRSHttpServiceConfigurationTypeHandler extends HttpServiceConfigurationTypeHandler {
     private static final Logger LOG = LogUtils.getL7dLogger(JaxRSHttpServiceConfigurationTypeHandler.class);
 
-    Set<ServiceReference> httpServiceReferences = new CopyOnWriteArraySet<ServiceReference>();
-
     protected JaxRSHttpServiceConfigurationTypeHandler(BundleContext dswBC,
-
-    Map<String, Object> handlerProps) {
+                                                       Map<String, Object> handlerProps) {
         super(dswBC, handlerProps);
     }
 
@@ -63,17 +52,7 @@ public class JaxRSHttpServiceConfigurationTypeHandler extends HttpServiceConfigu
             return;
         }
 
-        CXFNonSpringServlet cxf = new CXFNonSpringServlet();
-        HttpService httpService = getHttpService();
-        try {
-            HttpContext httpContext = getHttpContext(dswContext, httpService);
-            httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(), httpContext);
-            registerUnexportHook(exportRegistration, contextRoot);
-            LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot);
-        } catch (Exception e) {
-            throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e);
-        }
-        Bus bus = cxf.getBus();
+        Bus bus = registerServletAndGetBus(contextRoot, dswContext, exportRegistration);
 
         JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
         factory.setBus(bus);
@@ -95,8 +74,6 @@ public class JaxRSHttpServiceConfigurationTypeHandler extends HttpServiceConfigu
 
         String address = constructAddress(dswContext, contextRoot);
 
-        
-
         ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
         try {
             String[] intents = new String[] {
@@ -112,7 +89,6 @@ public class JaxRSHttpServiceConfigurationTypeHandler extends HttpServiceConfigu
             
             Thread.currentThread().setContextClassLoader(JAXRSServerFactoryBean.class.getClassLoader());
             Server server = factory.create();
-            registerStopHook(bus, httpService, server, contextRoot, Constants.RS_HTTP_SERVICE_CONTEXT);
 
             endpdDesc = new EndpointDescription(endpointProps);
             exportRegistration.setServer(server);
index 724f830..1fb2731 100644 (file)
@@ -26,6 +26,7 @@ import java.util.logging.Logger;
 import javax.xml.namespace.QName;
 import javax.xml.ws.Service;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.databinding.DataBinding;
@@ -40,7 +41,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 
-public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeHandler {
+public class WsdlConfigurationTypeHandler extends HttpServiceConfigurationTypeHandler {
     private static final String CONFIGURATION_TYPE = "wsdl";
     private static final Logger LOG = LogUtils.getL7dLogger(WsdlConfigurationTypeHandler.class);
     
@@ -144,19 +145,28 @@ public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeH
        }
         
        String address = getPojoAddress(sd, iClass);
+       String contextRoot = null;
         if (address == null) {
-            LOG.warning("Remote address is unavailable");
+               contextRoot = getServletContextRoot(sd, iClass);
+            if (contextRoot == null) {
+                LOG.warning("Remote address is unavailable");
+            }
             exportRegistration.setException(new Throwable("Remote address is unavailable"));
             return;
         }
 
         LOG.info("Creating a " + iClass.getName() + " endpoint from CXF PublishHook, address is " + address);
 
+        Bus bus = null;
+        if (contextRoot != null) {
+               bus = registerServletAndGetBus(contextRoot, dswContext, exportRegistration);
+        }
+        
         DataBinding databinding = new JAXBDataBinding();
         JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
 
         factory.setServiceClass(iClass);
-        factory.setAddress(address);
+        factory.setAddress(address != null ? address : "/");
         factory.getServiceFactory().setDataBinding(databinding);
         factory.setServiceBean(serviceBean);
 
@@ -169,6 +179,9 @@ public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeH
         }
         
         factory.setWsdlURL(wsdlURL.toString());
+        if (bus != null) {
+               factory.setBus(bus);
+        }
         
         ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
         try {
index 100119a..0429f2f 100644 (file)
@@ -120,10 +120,7 @@ public class ExportRegistrationImpl implements ExportRegistration {
     }
     
     public EndpointDescription getEndpointDescription() {
-        if (!closed)
-            return endpointDescription;
-        else
-            return null;
+        return endpointDescription;
     }
 
     public Throwable getException() {
@@ -183,10 +180,12 @@ public class ExportRegistrationImpl implements ExportRegistration {
     }
 
     public ExportReference getExportReference() {
-        if(exportReference==null){
-            exportReference = new ExportReferenceImpl(this);
-        }
-        return exportReference;
+       synchronized (this) {
+               if(exportReference==null){
+                   exportReference = new ExportReferenceImpl(this);
+               }
+               return exportReference;
+       }
     }
 
     protected EndpointDescription getEndpointDescriptionAlways() {
index 52dbf47..57c39e7 100644 (file)
@@ -366,7 +366,9 @@ public class TopologyManager {
             for (ExportRegistration exReg : exportRegistrations) {
 
                 // FIXME!!!!!!!!!!!!! There needs to be a better way ?!?!?!
-                Map props = exReg.getExportReference().getExportedEndpoint().getProperties();
+               ExportReference ref = exReg.getExportReference(); 
+               EndpointDescription endpoint = ref.getExportedEndpoint(); 
+                Map props = endpoint.getProperties();
                 Dictionary d = new Hashtable(props);
 
                 for (Filter filter : filters) {
index 9e4d9da..00d23da 100644 (file)
@@ -33,7 +33,7 @@
         <remote.service.admin.interfaces.version>1.0.0</remote.service.admin.interfaces.version>
 
         <servicemix.specs.version>1.9.0</servicemix.specs.version>
-
+        <pax.web.version>1.0.3</pax.web.version>
         <servlet.version>3.0</servlet.version>
         <log4j.version>1.2.15</log4j.version>
         <jetty.version>7.4.2.v20110526</jetty.version>