cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r736345 - in /cxf/sandbox/dosgi/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/ main/java/org/apache/cxf/dosgi/dsw/handlers/ main/java/org/apache/cxf/dosgi/dsw/hooks/ test/java/org/apache/cxf/dosgi/dsw/ test/java/org/apache/cxf/dosgi/d...
Date Wed, 21 Jan 2009 17:15:19 GMT
Author: davidb
Date: Wed Jan 21 09:15:19 2009
New Revision: 736345

URL: http://svn.apache.org/viewvc?rev=736345&view=rev
Log:
Added capability to use the OSGi HttpService instead of creating a Jetty server from CXF.
This can be useful if the same HTTP host & port need to be shared across applications running in the same OSGi container.

This feature is part of the 'pojo' configuration type and enabled by setting the following OSGi service property on the to-be-exposed service:
  osgi.remote.configuration.pojo.httpservice.context=/myContext
this property is mutually exclusive with 
  osgi.remote.configuration.pojo.address=http://localhost:4321/auction

Note that with the HttpService configuration, you can't specify the port, as this comes from the HttpService. 
Unit tests included.



Added:
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java   (contents, props changed)
      - copied, changed from r735998, cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java   (with props)
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java   (with props)
Modified:
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java Wed Jan 21 09:15:19 2009
@@ -42,15 +42,16 @@
     // WSDL
     public static final String WSDL_CONFIG_TYPE = "wsdl";
     public static final String WSDL_CONFIG_PREFIX = 
-        REMOTE_PROPERTY_PREFIX + CONFIGURATION_PROPERTY + ".wsdl";
+        REMOTE_PROPERTY_PREFIX + CONFIGURATION_PROPERTY + "." + WSDL_CONFIG_TYPE;
     public static final String SERVICE_NAMESPACE = WSDL_CONFIG_PREFIX + ".service.ns";
     
     // POJO
     public static final String POJO_CONFIG_TYPE = "pojo";
     public static final String POJO_CONFIG_PREFIX = 
-        REMOTE_PROPERTY_PREFIX + CONFIGURATION_PROPERTY + ".pojo";
-    public static final String POJO_ADDRESS_PROPERTY =  POJO_CONFIG_PREFIX + ".address";
-    
+        REMOTE_PROPERTY_PREFIX + CONFIGURATION_PROPERTY + "." + POJO_CONFIG_TYPE;
+    public static final String POJO_ADDRESS_PROPERTY = POJO_CONFIG_PREFIX + ".address";
+    public static final String POJO_HTTP_SERVICE_CONTEXT = POJO_CONFIG_PREFIX + ".httpservice.context"; 
+        
     // Common Configuration Properties
     public static final String CHECK_BUNDLE = "check.bundle";
     public static final String DEFAULT_PORT_CONFIG = "default.port";

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java Wed Jan 21 09:15:19 2009
@@ -24,19 +24,22 @@
 import org.apache.cxf.dosgi.dsw.Constants;
 import org.apache.cxf.dosgi.dsw.OsgiUtils;
 import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
+import org.osgi.framework.BundleContext;
 
 public abstract class AbstractConfigurationHandler implements ConfigurationTypeHandler {
     private final CxfDistributionProvider distributionProvider;
-    private final Map<String, Object> handlerProps;
+    final Map<String, Object> handlerProps;
+    protected BundleContext bundleContext;
     
-    protected AbstractConfigurationHandler(CxfDistributionProvider dp, 
+    protected AbstractConfigurationHandler(BundleContext dswBC,
+                                           CxfDistributionProvider dp, 
                                            Map<String, Object> handlerProps) {
+        this.bundleContext = dswBC;
         this.distributionProvider = dp;
         this.handlerProps = handlerProps;
     }
     
-    protected String getDefaultAddress(Class<?> type) {
-        
+    protected String getDefaultAddress(Class<?> type) {        
         String host = handlerProps.get(Constants.DEFAULT_HOST_CONFIG).toString();
         String port = handlerProps.get(Constants.DEFAULT_PORT_CONFIG).toString();
         StringBuilder buf = new StringBuilder();
@@ -63,6 +66,5 @@
         return Proxy.newProxyInstance(iType.getClassLoader(),
                       new Class[] {iType},
                       new ServiceInvocationHandler(serviceProxy, iType));
-    }
-    
+    }    
 }

Copied: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java (from r735998, cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java)
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java?p2=cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java&p1=cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java&r1=735998&r2=736345&rev=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java Wed Jan 21 09:15:19 2009
@@ -28,10 +28,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.apache.cxf.aegis.databinding.AegisDatabinding;
 import org.apache.cxf.binding.BindingConfiguration;
 import org.apache.cxf.dosgi.dsw.Constants;
 import org.apache.cxf.dosgi.dsw.OsgiUtils;
@@ -43,17 +41,18 @@
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
 import org.osgi.service.discovery.ServiceEndpointDescription;
 
-public class PojoConfigurationTypeHandler extends AbstractConfigurationHandler {
-    private static final Logger LOG = Logger.getLogger(PojoConfigurationTypeHandler.class.getName());
+public abstract class AbstractPojoConfigurationTypeHandler extends AbstractConfigurationHandler {
+    private static final Logger LOG = Logger.getLogger(AbstractPojoConfigurationTypeHandler.class.getName());
     private static final String PROVIDED_INTENT_VALUE = "PROVIDED";
     
     private IntentMap masterMap;
     
-    public PojoConfigurationTypeHandler(CxfDistributionProvider dp, Map<String, Object> handlerProps) {
-        super(dp, handlerProps);
+    public AbstractPojoConfigurationTypeHandler(BundleContext dswBC, 
+                                                CxfDistributionProvider dp, 
+                                                Map<String, Object> handlerProps) {
+        super(dswBC, dp, handlerProps);
     }
 
     // Isolated so that it can be substituted for testing
@@ -66,80 +65,7 @@
         return new ServerFactoryBean();
     }
 
-    public Object createProxy(ServiceReference serviceReference,
-                              BundleContext dswContext,
-                              BundleContext callingContext,
-                              Class<?> iClass, ServiceEndpointDescription sd) 
-                              throws IntentUnsatifiedException {
-        
-        
-        String address = getPojoAddress(sd, iClass);
-        if (address == null) {
-            LOG.warning("Remote address is unavailable");
-            return null;
-        }
-        
-        LOG.info("Creating a " + sd.getInterfaceNames().toArray()[0]
-                 + " client, endpoint address is " + address);
-
-
-        try {
-            ClientProxyFactoryBean factory = createClientProxyFactoryBean();
-            factory.setServiceClass(iClass);
-            factory.setAddress(address);
-            factory.getServiceFactory().setDataBinding(new AegisDatabinding());
-
-            applyIntents(dswContext,
-                                 callingContext, 
-                         factory.getFeatures(),
-                         factory.getClientFactoryBean(),
-                         sd);
-
-            Object proxy = getProxy(factory.create(), iClass);
-            getDistributionProvider().addRemoteService(serviceReference);
-            return proxy;
-        } catch (Exception e) {
-            LOG.log(Level.WARNING, "proxy creation failed", e);
-        }
-        return null;
-    }
-
-    public Server createServer(ServiceReference serviceReference,
-                               BundleContext dswContext,
-                               BundleContext callingContext, 
-                               ServiceEndpointDescription sd, 
-                               Class<?> iClass,
-                               Object serviceBean) throws IntentUnsatifiedException {        
-        String address = getPojoAddress(sd, iClass);
-        if (address == null) {
-            LOG.warning("Remote address is unavailable");
-            return null;
-        }
-        
-        LOG.info("Creating a " + sd.getInterfaceNames().toArray()[0]
-            + " endpoint from CXF PublishHook, address is " + address);
-        
-        ServerFactoryBean factory = createServerFactoryBean();
-        factory.setServiceClass(iClass);
-        factory.setAddress(address);
-        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
-        factory.setServiceBean(serviceBean);
-
-        try {
-            String [] intents = applyIntents(
-                dswContext, callingContext, factory.getFeatures(), factory, sd);
-
-            Server server = factory.create();
-            getDistributionProvider().addExposedService(serviceReference, registerPublication(server, intents));
-            return server;
-        } catch (IntentUnsatifiedException iue) {
-            getDistributionProvider().intentsUnsatisfied(serviceReference);
-            throw iue;
-        }
-    }
-
-
-    private Map<String, String> registerPublication(Server server, String[] intents) {
+    Map<String, String> registerPublication(Server server, String[] intents) {
         Map<String, String> publicationProperties = new HashMap<String, String>();
         publicationProperties.put(Constants.CONFIG_TYPE_PROPERTY, Constants.POJO_CONFIG_TYPE);
         publicationProperties.put(Constants.POJO_ADDRESS_PROPERTY, 
@@ -279,16 +205,5 @@
             }
         }
         return intentMap;
-    }
-    
-    private String getPojoAddress(ServiceEndpointDescription sd, Class<?> iClass) {
-        String address = OsgiUtils.getProperty(sd, Constants.POJO_ADDRESS_PROPERTY);
-        if (address == null) {
-            address = getDefaultAddress(iClass);
-            if (address != null) {
-                LOG.info("Using a default address : " + address);
-            }
-        }
-        return address;
-    }
+    }    
 }

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java Wed Jan 21 09:15:19 2009
@@ -24,6 +24,7 @@
 import org.apache.cxf.dosgi.dsw.Constants;
 import org.apache.cxf.dosgi.dsw.OsgiUtils;
 import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.discovery.ServiceEndpointDescription;
 
 public final class ConfigTypeHandlerFactory {
@@ -31,15 +32,13 @@
     private static final Logger LOG = Logger.getLogger(ConfigTypeHandlerFactory.class.getName());
     private static final ConfigTypeHandlerFactory FACTORY = new ConfigTypeHandlerFactory();
     
-    private ConfigTypeHandlerFactory() {
-        
-    }
+    private ConfigTypeHandlerFactory() {}
     
     public static ConfigTypeHandlerFactory getInstance() {
         return FACTORY;
     }
     
-    public ConfigurationTypeHandler getHandler(ServiceEndpointDescription sd, 
+    public ConfigurationTypeHandler getHandler(BundleContext dswBC, ServiceEndpointDescription sd, 
                                                CxfDistributionProvider dp,
                                                Map<String, Object> handlerProperties) {
         String type = OsgiUtils.getProperty(sd, Constants.CONFIG_TYPE_PROPERTY);
@@ -47,9 +46,20 @@
             if (type == null) {
                 LOG.info("Defaulting to pojo configuration type ");
             }
-            return new PojoConfigurationTypeHandler(dp, handlerProperties);
+            
+            if (OsgiUtils.getProperty(sd, Constants.POJO_HTTP_SERVICE_CONTEXT) != null) {
+                if (OsgiUtils.getProperty(sd, Constants.POJO_ADDRESS_PROPERTY) != null) {
+                    
+                    
+                    return null;
+                }
+                
+                return new HttpServiceConfigurationTypeHandler(dswBC, dp, handlerProperties);                
+            } else {
+                return new PojoConfigurationTypeHandler(dswBC, dp, handlerProperties);
+            }
         } else if (Constants.WSDL_CONFIG_TYPE.equalsIgnoreCase(type)) {
-            return new WsdlConfigurationTypeHandler(dp, handlerProperties);
+            return new WsdlConfigurationTypeHandler(dswBC, dp, handlerProperties);
         }
         
         LOG.info("Configuration type " + type + " is not supported");

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java?rev=736345&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java Wed Jan 21 09:15:19 2009
@@ -0,0 +1,135 @@
+/** 
+  * Licensed to the Apache Software Foundation (ASF) under one 
+  * or more contributor license agreements. See the NOTICE file 
+  * distributed with this work for additional information 
+  * regarding copyright ownership. The ASF licenses this file 
+  * to you under the Apache License, Version 2.0 (the 
+  * "License"); you may not use this file except in compliance 
+  * with the License. You may obtain a copy of the License at 
+  * 
+  * http://www.apache.org/licenses/LICENSE-2.0 
+  * 
+  * Unless required by applicable law or agreed to in writing, 
+  * software distributed under the License is distributed on an 
+  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+  * KIND, either express or implied. See the License for the 
+  * specific language governing permissions and limitations 
+  * under the License. 
+  */
+package org.apache.cxf.dosgi.dsw.handlers;
+
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.logging.Logger;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.ServerFactoryBean;
+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.discovery.ServiceEndpointDescription;
+import org.osgi.service.http.HttpService;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class HttpServiceConfigurationTypeHandler extends AbstractPojoConfigurationTypeHandler {
+    private static final Logger LOG = Logger.getLogger(HttpServiceConfigurationTypeHandler.class.getName());
+
+    Set<ServiceReference> httpServiceReferences = new CopyOnWriteArraySet<ServiceReference>(); 
+
+    protected HttpServiceConfigurationTypeHandler(BundleContext dswBC,
+                                                  CxfDistributionProvider dp,
+                                                  Map<String, Object> handlerProps) {
+        super(dswBC, dp, handlerProps);
+
+        ServiceTracker st = new ServiceTracker(dswBC, HttpService.class.getName(), null) {
+            @Override
+            public Object addingService(ServiceReference reference) {
+                httpServiceReferences.add(reference);
+                return super.addingService(reference);
+            }
+
+            @Override
+            public void removedService(ServiceReference reference, Object service) {
+                httpServiceReferences.remove(reference);
+                super.removedService(reference, service);
+            }                        
+        };
+        st.open();
+    }
+
+    public Object createProxy(ServiceReference serviceReference,
+            BundleContext dswContext, BundleContext callingContext,
+            Class<?> iClass, ServiceEndpointDescription sd) {
+        // This handler doesn't make sense on the client side
+        return null;
+    }
+
+    public Server createServer(ServiceReference serviceReference,
+                               BundleContext dswContext, 
+                               BundleContext callingContext,
+                               ServiceEndpointDescription sd, 
+                               Class<?> iClass, 
+                               Object serviceBean) {
+        String context = getServletContext(sd, iClass);
+        if (context == null) {
+            LOG.warning("Remote address is unavailable");
+            return null;
+        }
+
+        CXFNonSpringServlet cxf = new CXFNonSpringServlet();
+        HttpService httpService = getHttpService();
+        try {
+            httpService.registerServlet(context, cxf, new Hashtable<String, String>(), null);
+            LOG.info("Successfully registered CXF DOSGi servlet at " + context);
+        } catch (Exception e) {
+            throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e);
+        }        
+        Bus bus = cxf.getBus();
+        
+        ServerFactoryBean factory = createServerFactoryBean();
+        factory.setBus(bus);
+        factory.setServiceClass(iClass);
+        factory.setAddress("/");
+        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
+        factory.setServiceBean(serviceBean);
+
+        try {
+            String [] intents = 
+                applyIntents(dswContext, callingContext, factory.getFeatures(), factory, sd);
+
+            Server server = factory.create();
+            getDistributionProvider().addExposedService(serviceReference, registerPublication(server, intents));
+            return server;
+        } catch (IntentUnsatifiedException iue) {
+            getDistributionProvider().intentsUnsatisfied(serviceReference);
+            throw iue;
+        }       
+    }
+
+    private HttpService getHttpService() {
+        for (ServiceReference sr : httpServiceReferences) {
+            Object svc = bundleContext.getService(sr);
+            if (svc instanceof HttpService) {
+                return (HttpService) svc;
+            }
+        }
+        throw new ServiceException("CXF DOSGi: No HTTP Service could be found to publish CXF endpoint in.");
+    }
+
+    private String getServletContext(ServiceEndpointDescription sd, Class<?> iClass) {
+        String context = OsgiUtils.getProperty(sd, Constants.POJO_HTTP_SERVICE_CONTEXT);
+        if (context == null) {
+            context = iClass.getName().replace('.', '/');
+            LOG.info("Using a default address : " + context);
+        }
+        return context;
+    }
+}
\ No newline at end of file

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java Wed Jan 21 09:15:19 2009
@@ -18,70 +18,45 @@
   */
 package org.apache.cxf.dosgi.dsw.handlers;
 
-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;
 import java.util.Map;
-import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.cxf.aegis.databinding.AegisDatabinding;
-import org.apache.cxf.binding.BindingConfiguration;
 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.dosgi.dsw.service.CxfDistributionProvider;
-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;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.discovery.ServiceEndpointDescription;
 
-public class PojoConfigurationTypeHandler extends AbstractConfigurationHandler {
+public class PojoConfigurationTypeHandler extends AbstractPojoConfigurationTypeHandler {
     private static final Logger LOG = Logger.getLogger(PojoConfigurationTypeHandler.class.getName());
-    private static final String PROVIDED_INTENT_VALUE = "PROVIDED";
-    
-    private IntentMap masterMap;
-    
-    public PojoConfigurationTypeHandler(CxfDistributionProvider dp, Map<String, Object> handlerProps) {
-        super(dp, handlerProps);
-    }
-
-    // Isolated so that it can be substituted for testing
-    ClientProxyFactoryBean createClientProxyFactoryBean() {
-        return new ClientProxyFactoryBean();
-    }
 
-    // Isolated so that it can be substituted for testing
-    ServerFactoryBean createServerFactoryBean() {
-        return new ServerFactoryBean();
+    public PojoConfigurationTypeHandler(BundleContext dswBC,
+                                        CxfDistributionProvider dp, 
+                                        Map<String, Object> handlerProps) {
+        super(dswBC, dp, handlerProps);
     }
 
     public Object createProxy(ServiceReference serviceReference,
-                              BundleContext dswContext,
+                              BundleContext dswContext, 
                               BundleContext callingContext,
-                              Class<?> iClass, ServiceEndpointDescription sd) 
+                              Class<?> iClass, 
+                              ServiceEndpointDescription sd)
                               throws IntentUnsatifiedException {
-        
-        
+
         String address = getPojoAddress(sd, iClass);
         if (address == null) {
             LOG.warning("Remote address is unavailable");
             return null;
         }
-        
-        LOG.info("Creating a " + sd.getInterfaceNames().toArray()[0]
-                 + " client, endpoint address is " + address);
 
+        LOG.info("Creating a " + sd.getInterfaceNames().toArray()[0]
+                + " client, endpoint address is " + address);
 
         try {
             ClientProxyFactoryBean factory = createClientProxyFactoryBean();
@@ -89,10 +64,10 @@
             factory.setAddress(address);
             factory.getServiceFactory().setDataBinding(new AegisDatabinding());
 
-            applyIntents(dswContext,
-                                 callingContext, 
+            applyIntents(dswContext, 
+                         callingContext, 
                          factory.getFeatures(),
-                         factory.getClientFactoryBean(),
+                         factory.getClientFactoryBean(), 
                          sd);
 
             Object proxy = getProxy(factory.create(), iClass);
@@ -103,183 +78,41 @@
         }
         return null;
     }
-
+    
     public Server createServer(ServiceReference serviceReference,
                                BundleContext dswContext,
                                BundleContext callingContext, 
                                ServiceEndpointDescription sd, 
                                Class<?> iClass,
                                Object serviceBean) throws IntentUnsatifiedException {        
-        String address = getPojoAddress(sd, iClass);
-        if (address == null) {
-            LOG.warning("Remote address is unavailable");
-            return null;
-        }
-        
-        LOG.info("Creating a " + sd.getInterfaceNames().toArray()[0]
-            + " endpoint from CXF PublishHook, address is " + address);
-        
-        ServerFactoryBean factory = createServerFactoryBean();
-        factory.setServiceClass(iClass);
-        factory.setAddress(address);
-        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
-        factory.setServiceBean(serviceBean);
-
-        try {
-            String [] intents = applyIntents(
-                dswContext, callingContext, factory.getFeatures(), factory, sd);
-
-            Server server = factory.create();
-            getDistributionProvider().addExposedService(serviceReference, registerPublication(server, intents));
-            return server;
-        } catch (IntentUnsatifiedException iue) {
-            getDistributionProvider().intentsUnsatisfied(serviceReference);
-            throw iue;
-        }
-    }
-
-
-    private Map<String, String> registerPublication(Server server, String[] intents) {
-        Map<String, String> publicationProperties = new HashMap<String, String>();
-        publicationProperties.put(Constants.CONFIG_TYPE_PROPERTY, Constants.POJO_CONFIG_TYPE);
-        publicationProperties.put(Constants.POJO_ADDRESS_PROPERTY, 
-                server.getDestination().getAddress().getAddress().getValue());
-
-        String intentsValue = OsgiUtils.formatIntents(intents);
-        if (intentsValue.length() > 0) {
-            publicationProperties.put(Constants.INTENTS_PROPERTY, intentsValue);
-        }
-        return publicationProperties;
-    }
-
-    String [] applyIntents(BundleContext dswContext,
-                           BundleContext callingContext,
-                           List<AbstractFeature> features,
-                           AbstractEndpointFactory factory,
-                           ServiceEndpointDescription sd) throws IntentUnsatifiedException {
-        String[] requestedIntents = getRequestedIntents(sd);
-        Set<String> appliedIntents = new HashSet<String>(Arrays.asList(requestedIntents));
-        
-        IntentMap intentMap = getIntentMap(callingContext);        
-        if (useMasterMap()) {
-            intentMap = mergeWithMaster(dswContext, intentMap);
-        }
-        appliedIntents.addAll(reverseLookup(intentMap, PROVIDED_INTENT_VALUE));
-        
-        boolean bindingConfigAdded = false;
-        for (String requestedName : requestedIntents) {
-            bindingConfigAdded 
-                |= processIntent(appliedIntents, features, factory, requestedName, intentMap);
-        }
-        
-        if (!bindingConfigAdded && getDefaultBindingIntent() != null) {
-            // If no binding config was specified, add SOAP
-            processIntent(appliedIntents, features, factory, getDefaultBindingIntent(), intentMap);
-        }
-
-        appliedIntents.addAll(addSynonymIntents(appliedIntents, intentMap));        
-        return appliedIntents.toArray(new String[0]);
-    }
-
-    private boolean processIntent(Set<String> appliedIntents,
-                                  List<AbstractFeature> features,
-                                  AbstractEndpointFactory factory, String intentName,
-                                  IntentMap intentMap) throws IntentUnsatifiedException {
-        boolean rc = processIntent(features, factory, intentName, intentMap);
-        appliedIntents.add(intentName);
-        return rc;
+    String address = getPojoAddress(sd, iClass);
+    if (address == null) {
+        LOG.warning("Remote address is unavailable");
+        return null;
     }
     
-    private boolean processIntent(List<AbstractFeature> features,
-                                  AbstractEndpointFactory factory, String intentName,
-                                  IntentMap intentMap) throws IntentUnsatifiedException {
-        Object intent = intentMap.get(intentName);
-        if (intent instanceof String) {
-            if (PROVIDED_INTENT_VALUE.equalsIgnoreCase((String) intent)) {
-                return false;
-            }
-        } else if (intent instanceof AbstractFeature) {
-            AbstractFeature feature = (AbstractFeature)intent;
-            LOG.info("Applying intent: " + intentName
-                     + " via feature: " + feature);
-            features.add(feature);
-            return false;
-        } else if (intent instanceof BindingConfiguration) {
-            BindingConfiguration bindingCfg = (BindingConfiguration)intent;
-            LOG.info("Applying intent: " + intentName
-                     + " via binding config: " + bindingCfg);
-            factory.setBindingConfig(bindingCfg);
-            return true;
-        } else {
-            LOG.info("No mapping for intent: " + intentName);
-            throw new IntentUnsatifiedException(intentName);
-        }
-        return false;
-    }
+    LOG.info("Creating a " + sd.getInterfaceNames().toArray()[0]
+        + " endpoint from CXF PublishHook, address is " + address);
     
-
-    private Collection<String> addSynonymIntents(Collection<String> appliedIntents, IntentMap intentMap) {
-        // E.g. SOAP and SOAP.1_1 are synonyms
-        List<Object> values = new ArrayList<Object>();
-        for (String key : appliedIntents) {
-            values.add(intentMap.get(key));
-        }
-        return reverseLookup(intentMap, values);
-    }
-
-    private Collection<String> reverseLookup(IntentMap intentMap, Object obj) {
-        return reverseLookup(intentMap, Collections.singleton(obj));
-    }
-    
-    private Collection<String> reverseLookup(IntentMap intentMap, Collection<? extends Object> objs) {
-        Set<String> intentsFound = new HashSet<String>();
-        for (Map.Entry<String, Object> entry : intentMap.getIntents().entrySet()) {
-            if (objs.contains(entry.getValue())) {
-                intentsFound.add(entry.getKey());
-            }
-        }
-        return intentsFound;
-    }
-    
-    String getDefaultBindingIntent() {
-        return "SOAP";
-    }
-
-    IntentMap getIntentMap(BundleContext callingContext) {
-        return OsgiUtils.getIntentMap(callingContext);
-    }
-
-    private static String[] getRequestedIntents(ServiceEndpointDescription sd) {
-        String property = 
-            OsgiUtils.getProperty(sd, Constants.REQUIRES_INTENTS_PROPERTY);
-        String[] intents = OsgiUtils.parseIntents(property);
-        for (int i = 0; i < intents.length; i++) {
-            LOG.fine("Intent asserted: " + intents[i]);
-        } 
-        return intents;
+    ServerFactoryBean factory = createServerFactoryBean();
+    factory.setServiceClass(iClass);
+    factory.setAddress(address);
+    factory.getServiceFactory().setDataBinding(new AegisDatabinding());
+    factory.setServiceBean(serviceBean);
+    
+    try {
+        String [] intents = applyIntents(
+            dswContext, callingContext, factory.getFeatures(), factory, sd);
+    
+        Server server = factory.create();
+        getDistributionProvider().addExposedService(serviceReference, registerPublication(server, intents));
+        return server;
+    } catch (IntentUnsatifiedException iue) {
+        getDistributionProvider().intentsUnsatisfied(serviceReference);
+        throw iue;
     }
+}
     
-    private IntentMap mergeWithMaster(BundleContext dswContext, IntentMap intentMap) {
-        synchronized (this) {
-            if (masterMap == null) {
-                LOG.fine("Loading master intent map");
-                masterMap = getIntentMap(dswContext);
-            }
-        }
-        if (masterMap != null) {
-            Iterator<String> masterKeys = masterMap.getIntents().keySet().iterator();
-            while (masterKeys.hasNext()) {
-                String masterKey = masterKeys.next();
-                if (intentMap.get(masterKey) == null) {
-                    LOG.fine("Merging in master intent map entry: " + masterKey);
-                    intentMap.getIntents().put(masterKey, masterMap.get(masterKey));
-                } else {
-                    LOG.fine("Overridden master intent map entry: " + masterKey);
-                }
-            }
-        }
-        return intentMap;
-    }
     
     private String getPojoAddress(ServiceEndpointDescription sd, Class<?> iClass) {
         String address = OsgiUtils.getProperty(sd, Constants.POJO_ADDRESS_PROPERTY);
@@ -291,4 +124,5 @@
         }
         return address;
     }
+    
 }

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java Wed Jan 21 09:15:19 2009
@@ -39,9 +39,10 @@
 
     private static final Logger LOG = Logger.getLogger(WsdlConfigurationTypeHandler.class.getName());
     
-    public WsdlConfigurationTypeHandler(CxfDistributionProvider dp,
+    public WsdlConfigurationTypeHandler(BundleContext dswBC,
+                                        CxfDistributionProvider dp,
                                         Map<String, Object> handlerProps) {
-        super(dp, handlerProps);
+        super(dswBC, dp, handlerProps);
     }
     
     public Object createProxy(ServiceReference serviceReference,

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java Wed Jan 21 09:15:19 2009
@@ -72,7 +72,7 @@
             }
             
             ConfigurationTypeHandler handler = 
-                ServiceHookUtils.getHandler(sd, getDistributionProvider(), getHandlerProperties());
+                ServiceHookUtils.getHandler(getContext(), sd, getDistributionProvider(), getHandlerProperties());
             if (handler == null) {
                 continue;
             }

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java Wed Jan 21 09:15:19 2009
@@ -18,7 +18,6 @@
   */
 package org.apache.cxf.dosgi.dsw.hooks;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Dictionary;

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java Wed Jan 21 09:15:19 2009
@@ -132,6 +132,6 @@
     
     protected ConfigurationTypeHandler getHandler(ServiceEndpointDescription sd,
                                                   Map<String, Object> props) {
-        return ServiceHookUtils.getHandler(sd, getDistributionProvider(), props);
+        return ServiceHookUtils.getHandler(getContext(), sd, getDistributionProvider(), props);
     }
 }

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java Wed Jan 21 09:15:19 2009
@@ -136,10 +136,11 @@
         }
     }
     
-    public static ConfigurationTypeHandler getHandler(ServiceEndpointDescription sd,
+    public static ConfigurationTypeHandler getHandler(BundleContext dswBC,
+                                                      ServiceEndpointDescription sd,
                                                       CxfDistributionProvider dp,
                                                       Map<String, Object> dswProperties) {
-        return ConfigTypeHandlerFactory.getInstance().getHandler(sd, dp,
+        return ConfigTypeHandlerFactory.getInstance().getHandler(dswBC, sd, dp,
                                                                  dswProperties);
     }
     

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java Wed Jan 21 09:15:19 2009
@@ -27,19 +27,17 @@
 
 public final class TestUtils {
     private TestUtils() {
-        
     }
 
     public static ServiceEndpointDescription mockServiceDescription(String... interfaceNames) {
         List<String> iList = new ArrayList<String>();
         for (String iName : interfaceNames) {
-	    iList.add(iName);
-	}
+            iList.add(iName);
+        }
+        
         ServiceEndpointDescription sd = EasyMock.createNiceMock(ServiceEndpointDescription.class);
         sd.getInterfaceNames();
         EasyMock.expectLastCall().andReturn(iList);
         return sd;
     }
-    
-    
 }

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java Wed Jan 21 09:15:19 2009
@@ -42,7 +42,7 @@
         
         ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("MyInterface");
         CxfDistributionProvider dp = new DistributionProviderImpl(bc);
-        ConfigurationTypeHandler handler = f.getHandler(sd, dp, new HashMap<String, Object>());
+        ConfigurationTypeHandler handler = f.getHandler(bc, sd, dp, new HashMap<String, Object>());
         assertTrue(handler instanceof PojoConfigurationTypeHandler);        
         assertSame(dp, ((PojoConfigurationTypeHandler) handler).getDistributionProvider());
     }
@@ -59,11 +59,64 @@
                 Collections.singletonList("MyInterface"), sdProps);
 
         CxfDistributionProvider dp = new DistributionProviderImpl(bc);
-        ConfigurationTypeHandler handler = f.getHandler(sd, dp, new HashMap<String, Object>());
+        ConfigurationTypeHandler handler = f.getHandler(bc, sd, dp, new HashMap<String, Object>());
         assertTrue(handler instanceof PojoConfigurationTypeHandler);        
         assertSame(dp, ((PojoConfigurationTypeHandler) handler).getDistributionProvider());
     }
+    
+    public void testGetPojoHandler2() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bc);
 
+        ConfigTypeHandlerFactory f = ConfigTypeHandlerFactory.getInstance();
+        
+        Map<String, Object> sdProps = new HashMap<String, Object>();
+        // use default for this: sdProps.put(Constants.CONFIG_TYPE_PROPERTY, Constants.POJO_CONFIG_TYPE);
+        sdProps.put(Constants.POJO_ADDRESS_PROPERTY, "http://localhost:9876/abcd");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(
+                Collections.singletonList("MyInterface"), sdProps);
+
+        CxfDistributionProvider dp = new DistributionProviderImpl(bc);
+        ConfigurationTypeHandler handler = f.getHandler(bc, sd, dp, new HashMap<String, Object>());
+        assertTrue(handler instanceof PojoConfigurationTypeHandler);        
+        assertSame(dp, ((PojoConfigurationTypeHandler) handler).getDistributionProvider());
+    }
+
+    public void testGetHttpServiceHandler() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bc);
+        
+        ConfigTypeHandlerFactory f = ConfigTypeHandlerFactory.getInstance();
+        
+        Map<String, Object> sdProps = new HashMap<String, Object>();
+        sdProps.put(Constants.CONFIG_TYPE_PROPERTY, Constants.POJO_CONFIG_TYPE);
+        sdProps.put(Constants.POJO_HTTP_SERVICE_CONTEXT, "/abc");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(
+                Collections.singletonList("MyInterface"), sdProps);
+        
+        CxfDistributionProvider dp = new DistributionProviderImpl(bc);
+        ConfigurationTypeHandler handler = f.getHandler(bc, sd, dp, new HashMap<String, Object>());
+        assertTrue(handler instanceof HttpServiceConfigurationTypeHandler);
+        assertSame(dp, ((HttpServiceConfigurationTypeHandler) handler).getDistributionProvider());                
+    }
+    
+    public void testGetPojoAddressHttpServicesConflictSituation() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bc);
+        
+        ConfigTypeHandlerFactory f = ConfigTypeHandlerFactory.getInstance();
+        
+        Map<String, Object> sdProps = new HashMap<String, Object>();
+        sdProps.put(Constants.CONFIG_TYPE_PROPERTY, Constants.POJO_CONFIG_TYPE);
+        sdProps.put(Constants.POJO_ADDRESS_PROPERTY, "http://localhost:9876/abcd");
+        sdProps.put(Constants.POJO_HTTP_SERVICE_CONTEXT, "/abc");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(
+                Collections.singletonList("MyInterface"), sdProps);
+        
+        assertNull("Should not get a handler as this is a conflict situation", 
+                f.getHandler(bc, sd, null, new HashMap<String, Object>()));
+    }
+    
     public void testGetWSDLHandler() {
         BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
         EasyMock.replay(bc);
@@ -76,8 +129,23 @@
                 Collections.singletonList("MyInterface"), sdProps);
         
         CxfDistributionProvider dp = new DistributionProviderImpl(bc);
-        ConfigurationTypeHandler handler = f.getHandler(sd, dp, new HashMap<String, Object>());
+        ConfigurationTypeHandler handler = f.getHandler(bc, sd, dp, new HashMap<String, Object>());
         assertTrue(handler instanceof WsdlConfigurationTypeHandler);        
         assertSame(dp, ((WsdlConfigurationTypeHandler) handler).getDistributionProvider());
     }
+    
+    public void testUnsupportedConfiguration() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bc);
+        
+        ConfigTypeHandlerFactory f = ConfigTypeHandlerFactory.getInstance();
+        
+        Map<String, Object> sdProps = new HashMap<String, Object>();
+        sdProps.put(Constants.CONFIG_TYPE_PROPERTY, "foobar");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(
+                Collections.singletonList("MyInterface"), sdProps);
+        
+        assertNull("Should not get a handler as this an unsupported config type", 
+                f.getHandler(bc, sd, null, new HashMap<String, Object>()));        
+    }
 }

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java?rev=736345&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java Wed Jan 21 09:15:19 2009
@@ -0,0 +1,146 @@
+package org.apache.cxf.dosgi.dsw.handlers;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.dosgi.dsw.TestUtils;
+import org.apache.cxf.dosgi.dsw.service.DistributionProviderImpl;
+import org.apache.cxf.endpoint.AbstractEndpointFactory;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.easymock.IAnswer;
+import org.easymock.classextension.EasyMock;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.ServiceEndpointDescription;
+import org.osgi.service.http.HttpService;
+
+public class HttpServiceConfigurationTypeHandlerTest extends TestCase {
+    public void testServer() {
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        HttpService httpService = EasyMock.createNiceMock(HttpService.class);
+        // expect that the cxf servlet is registered
+        EasyMock.replay(httpService);
+        
+        ServiceReference httpSvcSR = EasyMock.createNiceMock(ServiceReference.class);
+        EasyMock.replay(httpSvcSR);
+        EasyMock.expect(dswContext.getService(httpSvcSR)).andReturn(httpService).anyTimes();
+        EasyMock.replay(dswContext);
+        
+        final ServerFactoryBean sfb = createMockServerFactoryBean();
+        
+        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
+        Map<String, Object> handlerProps = new HashMap<String, Object>();
+        HttpServiceConfigurationTypeHandler h = 
+            new HttpServiceConfigurationTypeHandler(dswContext, dp, handlerProps) {
+                @Override
+                ServerFactoryBean createServerFactoryBean() {
+                    return sfb;
+                }
+
+                @Override
+                String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
+                        List<AbstractFeature> features, AbstractEndpointFactory factory, 
+                        ServiceEndpointDescription sd) {
+                    return new String [] {"a.b.c"};
+                }            
+        };
+        h.httpServiceReferences.add(httpSvcSR);
+        
+        Runnable myService = new Runnable() {
+            public void run() {
+                System.out.println("blah");
+            }            
+        };
+                
+        ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
+        BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
+        ServiceEndpointDescription sd = TestUtils.mockServiceDescription(Runnable.class.getName());
+        EasyMock.replay(sr);
+        EasyMock.replay(callingContext);
+        EasyMock.replay(sd);        
+        
+        assertEquals("Precondition failed", 0, dp.getExposedServices().size());
+        h.createServer(sr, dswContext, callingContext, sd, Runnable.class, myService);
+        assertEquals(1, dp.getExposedServices().size());
+        assertSame(sr, dp.getExposedServices().iterator().next());
+        
+        Map<String, String> expected = new HashMap<String, String>();
+        expected.put("osgi.remote.configuration.type", "pojo");
+        // The following doesn't work yet.
+        // expected.put("osgi.remote.configuration.pojo.address", "http://somehost:54321/myRunnable");
+        expected.put("osgi.remote.configuration.pojo.address", "/"); // temporary
+        expected.put("osgi.intents", "a.b.c");
+        assertEquals(expected, dp.getExposedProperties(sr));
+    }
+    
+    private ServerFactoryBean createMockServerFactoryBean() {
+        ReflectionServiceFactoryBean sf = EasyMock.createNiceMock(ReflectionServiceFactoryBean.class);
+        EasyMock.replay(sf);
+        
+        final StringBuilder serverURI = new StringBuilder();
+        
+        ServerFactoryBean sfb = EasyMock.createNiceMock(ServerFactoryBean.class);
+        Server server = createMockServer(sfb);    
+        
+        EasyMock.expect(sfb.getServiceFactory()).andReturn(sf).anyTimes();
+        EasyMock.expect(sfb.create()).andReturn(server);
+        sfb.setAddress((String) EasyMock.anyObject());
+        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+            public Object answer() throws Throwable {
+                serverURI.setLength(0);
+                serverURI.append(EasyMock.getCurrentArguments()[0]);
+                return null;
+            }            
+        });
+        EasyMock.expect(sfb.getAddress()).andAnswer(new IAnswer<String>() {
+            public String answer() throws Throwable {
+                return serverURI.toString();
+            }            
+        });
+        EasyMock.replay(sfb);
+        return sfb;
+    }
+
+    private Server createMockServer(final ServerFactoryBean sfb) {
+        AttributedURIType addr = EasyMock.createMock(AttributedURIType.class);
+        EasyMock.expect(addr.getValue()).andAnswer(new IAnswer<String>() {
+            public String answer() throws Throwable {
+                return sfb.getAddress();
+            }            
+        });
+        EasyMock.replay(addr);
+
+        EndpointReferenceType er = EasyMock.createMock(EndpointReferenceType.class);
+        EasyMock.expect(er.getAddress()).andReturn(addr);
+        EasyMock.replay(er);
+        
+        Destination destination = EasyMock.createMock(Destination.class);
+        EasyMock.expect(destination.getAddress()).andReturn(er);
+        EasyMock.replay(destination);        
+                
+        Server server = EasyMock.createNiceMock(Server.class);
+        EasyMock.expect(server.getDestination()).andReturn(destination);
+        EasyMock.replay(server);
+        return server;
+    }
+
+    public void testNoHttpService() {
+        
+    }
+    
+    public void testHttpServiceDynamism() {
+        
+    }
+    
+    public void testServletUnregistration() {        
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java Wed Jan 21 09:15:19 2009
@@ -77,7 +77,7 @@
         EasyMock.replay(cpfb);
         
         DistributionProviderImpl dp = new DistributionProviderImpl(bc);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(bc, dp, handlerProps) {
             @Override
             ClientProxyFactoryBean createClientProxyFactoryBean() {
                 return cpfb;
@@ -113,7 +113,7 @@
         final ServerFactoryBean sfb = createMockServerFactoryBean();
         
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             ServerFactoryBean createServerFactoryBean() {
                 return sfb;
@@ -211,7 +211,7 @@
         control.replay();
 
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        AbstractPojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             IntentMap getIntentMap(BundleContext callingContext) {
                 return intentMap;
@@ -247,7 +247,7 @@
         control.replay();
 
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             IntentMap getIntentMap(BundleContext callingContext) {
                 return intentMap;
@@ -283,7 +283,7 @@
         control.replay();
 
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             IntentMap getIntentMap(BundleContext callingContext) {
                 return intentMap;
@@ -321,7 +321,7 @@
         control.replay();
         
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             IntentMap getIntentMap(BundleContext callingContext) {
                 return intentMap;
@@ -365,7 +365,7 @@
         control.replay();
         
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             IntentMap getIntentMap(BundleContext callingContext) {
                 return intentMap;
@@ -404,7 +404,7 @@
         control.replay();
         
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             IntentMap getIntentMap(BundleContext callingContext) {
                 return intentMap;
@@ -483,7 +483,7 @@
         props.put(Constants.REQUIRES_INTENTS_PROPERTY, requestedIntents);
         ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props);
         
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             IntentMap getIntentMap(BundleContext ctx) {
                 if (ctx == callingContext) {
@@ -532,7 +532,7 @@
         props.put(Constants.REQUIRES_INTENTS_PROPERTY, "B A");
         ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props);
         
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             IntentMap getIntentMap(BundleContext ctx) {
                 if (ctx == callingContext) {
@@ -584,7 +584,7 @@
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
         dp.addEventAdmin(ea);
         
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             ServerFactoryBean createServerFactoryBean() {
                 return sfb;
@@ -638,7 +638,7 @@
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
         dp.addEventAdmin(ea);
         
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             ServerFactoryBean createServerFactoryBean() {
                 return sfb;

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java?rev=736345&r1=736344&r2=736345&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java Wed Jan 21 09:15:19 2009
@@ -58,7 +58,7 @@
         EasyMock.replay(sd);
         
         DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
-        WsdlConfigurationTypeHandler w = new WsdlConfigurationTypeHandler(dp, handlerProps) {
+        WsdlConfigurationTypeHandler w = new WsdlConfigurationTypeHandler(dswContext, dp, handlerProps) {
             @Override
             Service createWebService(URL wsdlAddress, QName serviceQname) {
                 Service svc = EasyMock.createMock(Service.class);



Mime
View raw message