You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2009/02/04 15:45:43 UTC

svn commit: r740760 - in /cxf/dosgi/trunk: distribution/single-bundle/ distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/ distribution/single-bundle/src/test/java/org/apache/cxf/dosgi/singlebundle/ dsw/cxf-dsw/src/main/java/org...

Author: davidb
Date: Wed Feb  4 14:45:41 2009
New Revision: 740760

URL: http://svn.apache.org/viewvc?rev=740760&view=rev
Log:
Fixes broken HttpServiceConfigurationTypeHandler, added extra test for the thing that was broken before.
Additionally, sets the org.osgi.service.http.port for the single-bundle distribution (this can't be done automatically for the multibundle distribution as it needs to happen before the pax-web component is started). 

The for org.osgi.service.http.port property, the following algorithm is used:
1. if its already set, don't change it
2. if not set, see if port 8080 is available and set it to that
3. if port 8080 is not available, ask the system for another free port

Modified:
    cxf/dosgi/trunk/distribution/single-bundle/pom.xml
    cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java
    cxf/dosgi/trunk/distribution/single-bundle/src/test/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivatorTest.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
    cxf/dosgi/trunk/parent/pom.xml

Modified: cxf/dosgi/trunk/distribution/single-bundle/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/distribution/single-bundle/pom.xml?rev=740760&r1=740759&r2=740760&view=diff
==============================================================================
--- cxf/dosgi/trunk/distribution/single-bundle/pom.xml (original)
+++ cxf/dosgi/trunk/distribution/single-bundle/pom.xml Wed Feb  4 14:45:41 2009
@@ -202,6 +202,11 @@
       <artifactId>cxf-dosgi-ri-dsw-cxf</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>        
 
   <build>

Modified: cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java?rev=740760&r1=740759&r2=740760&view=diff
==============================================================================
--- cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java (original)
+++ cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java Wed Feb  4 14:45:41 2009
@@ -21,6 +21,7 @@
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.net.ServerSocket;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -31,11 +32,76 @@
 import org.osgi.framework.BundleContext;
 
 public class AggregatedActivator implements BundleActivator {
-    private static final String ACTIVATOR_RESOURCE = "activators.list";
+    static final String HTTP_PORT_PROPERTY = "org.osgi.service.http.port";
+    static final String HTTPS_PORT_PROPERTY = "org.osgi.service.http.port.secure";
+    static final String HTTPS_ENABLED_PROPERTY = "org.osgi.service.http.secure.enabled";
+    static final String ACTIVATOR_RESOURCE = "activators.list";
+
+    static String DEFAULT_HTTP_PORT = "8080";
     
     private List<BundleActivator> activators = new ArrayList<BundleActivator>(); 
 
     public void start(BundleContext ctx) throws Exception {
+        setHttpServicePort(ctx);
+        startEmbeddedActivators(ctx);
+    }
+
+    public void stop(BundleContext ctx) throws Exception {
+        stopEmbeddedActivators(ctx);
+    }
+
+    void setHttpServicePort(BundleContext ctx) {
+        boolean https = false;
+        String port;
+        if ("true".equalsIgnoreCase(ctx.getProperty(HTTPS_ENABLED_PROPERTY))) {
+            https = true;
+            port = ctx.getProperty(HTTPS_PORT_PROPERTY);            
+        } else {
+            port = ctx.getProperty(HTTP_PORT_PROPERTY);            
+        }
+        
+        if (port == null || port.length() == 0) {
+            port = tryPortFree(DEFAULT_HTTP_PORT);
+            if (port == null) {
+                System.out.print("Port " + DEFAULT_HTTP_PORT + " is not available. ");
+                port = tryPortFree("0");
+            }
+            System.out.println("Setting HttpService port to: " + port);
+            
+            String prop = https ? HTTPS_PORT_PROPERTY : HTTP_PORT_PROPERTY;
+            System.setProperty(prop, port);
+        } else {
+            if (tryPortFree(port) == null) {
+                System.out.println("The system is configured to use HttpService port " 
+                    + port + ". However this port is already in use.");
+            } else {
+                System.out.println("HttpService using port: " + port);
+            }
+        }
+    }
+    
+    private String tryPortFree(String port) {
+        int p = Integer.parseInt(port);
+        
+        ServerSocket s = null;
+        try {
+             s = new ServerSocket(p);
+             return "" + s.getLocalPort(); 
+        } catch (IOException e) {
+            return null;
+        } finally {
+            if (s != null) {
+                try {
+                    s.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+        }
+        
+    }
+
+    void startEmbeddedActivators(BundleContext ctx) throws Exception {
         SPIActivator sba = new SPIActivator();
         sba.start(ctx);
         activators.add(sba);
@@ -55,11 +121,11 @@
         }
     }
 
-    public void stop(BundleContext ctx) throws Exception {
+    void stopEmbeddedActivators(BundleContext ctx) throws Exception {
         for (BundleActivator ba : activators) {
             ba.stop(ctx);
         }
-   }
+    }
     
     Collection<String> getActivators() throws IOException {
         List<String> bundleActivators = new ArrayList<String>();

Modified: cxf/dosgi/trunk/distribution/single-bundle/src/test/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivatorTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/distribution/single-bundle/src/test/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivatorTest.java?rev=740760&r1=740759&r2=740760&view=diff
==============================================================================
--- cxf/dosgi/trunk/distribution/single-bundle/src/test/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivatorTest.java (original)
+++ cxf/dosgi/trunk/distribution/single-bundle/src/test/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivatorTest.java Wed Feb  4 14:45:41 2009
@@ -1,11 +1,45 @@
 package org.apache.cxf.dosgi.singlebundle;
 
+import java.net.ServerSocket;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
 
 import junit.framework.TestCase;
 
+import org.easymock.EasyMock;
+import org.osgi.framework.BundleContext;
+
 public class AggregatedActivatorTest extends TestCase {
-    public void testReadResourcesFile() throws Exception {
+    private HashMap<Object, Object> savedProps;
+    private String oldDefaultPort;
+
+    @Override
+    protected void setUp() throws Exception {
+        oldDefaultPort = AggregatedActivator.DEFAULT_HTTP_PORT;
+        // Change the default port to one that we know is available
+        ServerSocket s = new ServerSocket(0);
+        int availablePort = s.getLocalPort();
+        s.close();
+        AggregatedActivator.DEFAULT_HTTP_PORT = "" + availablePort;        
+        
+        savedProps = new HashMap<Object, Object>(System.getProperties());
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        Properties props = new Properties();
+        props.putAll(savedProps);
+        System.setProperties(props);
+        
+        AggregatedActivator.DEFAULT_HTTP_PORT = oldDefaultPort;
+    }
+
+    public void testReadResourcesFile() throws Exception {        
         String[] expected = {
             "org.ops4j.pax.web.service.internal.Activator",
             "org.apache.cxf.dosgi.discovery.local.Activator",
@@ -15,4 +49,95 @@
         AggregatedActivator aa = new AggregatedActivator();
         assertEquals(Arrays.asList(expected), aa.getActivators());
     }
+    
+    public void testDefaultHttpServicePort() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bc);
+        
+        assertNull("Precondition failed", System.getProperty(AggregatedActivator.HTTP_PORT_PROPERTY));
+        new AggregatedActivator().setHttpServicePort(bc);
+        assertEquals(AggregatedActivator.DEFAULT_HTTP_PORT, System.getProperty(AggregatedActivator.HTTP_PORT_PROPERTY));
+    }
+    
+    public void testHttpServicePortFromProperty() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bc.getProperty(AggregatedActivator.HTTP_PORT_PROPERTY)).
+            andReturn("1234").anyTimes();
+        EasyMock.replay(bc);
+
+        HashMap<Object, Object> before = new HashMap<Object, Object>(System.getProperties());
+        new AggregatedActivator().setHttpServicePort(bc);
+        assertEquals("No additional properties should have been set",
+                before, new HashMap<Object, Object>(System.getProperties()));
+    }
+    
+    public void testHttpsServicePortFromProperty() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bc.getProperty(AggregatedActivator.HTTPS_PORT_PROPERTY)).
+            andReturn("4321").anyTimes();
+        EasyMock.expect(bc.getProperty(AggregatedActivator.HTTPS_ENABLED_PROPERTY)).
+            andReturn("true").anyTimes();
+        EasyMock.replay(bc);
+
+        HashMap<Object, Object> before = new HashMap<Object, Object>(System.getProperties());
+        new AggregatedActivator().setHttpServicePort(bc);
+        assertEquals("No additional properties should have been set",
+                before, new HashMap<Object, Object>(System.getProperties()));        
+    }
+    
+    public void testHttpServicePortInUse() throws Exception {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bc);
+
+        ServerSocket s = null;
+        try {
+            try {
+                // now lets block the default port
+                s = new ServerSocket(8080);
+            } catch (Exception e) {
+                // if someone else already has it, thats fine too
+            }
+            
+            assertNull("Precondition failed", System.getProperty(AggregatedActivator.HTTP_PORT_PROPERTY));
+            new AggregatedActivator().setHttpServicePort(bc);
+            assertTrue("The " + AggregatedActivator.HTTP_PORT_PROPERTY 
+                    + " property should have been set", 
+                    System.getProperty(AggregatedActivator.HTTP_PORT_PROPERTY).length() > 0);
+        } finally {
+            if (s != null) {
+                s.close();
+            }
+        }
+    }
+    
+    public void testSetHttpPortInActivator() throws Exception {
+        final List<String> results = new ArrayList<String>();
+        AggregatedActivator aa = new AggregatedActivator() {
+            @Override
+            void setHttpServicePort(BundleContext bc) {
+                results.add("HTTPPort");
+            }
+
+            @Override
+            void startEmbeddedActivators(BundleContext ctx) throws Exception {
+                results.add("start_activators");
+            }
+
+            @Override
+            void stopEmbeddedActivators(BundleContext ctx) throws Exception {
+                results.add("stop_activators");
+            }        
+        };
+        
+        assertEquals("Precondition failed", 0, results.size());
+        aa.start(null); 
+        assertEquals(2, results.size());
+        assertTrue(results.contains("HTTPPort"));
+        assertTrue(results.contains("start_activators"));
+        
+        results.clear();
+        aa.stop(null);
+        assertEquals(1, results.size());
+        assertEquals("stop_activators", results.iterator().next());        
+    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java?rev=740760&r1=740759&r2=740760&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java Wed Feb  4 14:45:41 2009
@@ -96,11 +96,11 @@
         }        
         Bus bus = cxf.getBus();
         
-        String address = constructAddress(contextRoot);
+        String address = constructAddress(dswContext, contextRoot);
         ServerFactoryBean factory = createServerFactoryBean();
         factory.setBus(bus);
         factory.setServiceClass(iClass);
-        factory.setAddress(address);
+        factory.setAddress("/");
         factory.getServiceFactory().setDataBinding(new AegisDatabinding());
         factory.setServiceBean(serviceBean);
 
@@ -127,17 +127,17 @@
         return publicationProperties;
     }    
 
-    private String constructAddress(String contextRoot) {
+    private String constructAddress(BundleContext ctx, String contextRoot) {
         String port = null;
         boolean https = false;
-        if ("true".equalsIgnoreCase(System.getProperty("org.osgi.service.http.secure.enabled"))) {
+        if ("true".equalsIgnoreCase(ctx.getProperty("org.osgi.service.http.secure.enabled"))) {
             https = true;
-            port = System.getProperty("org.osgi.service.http.port.secure");            
+            port = ctx.getProperty("org.osgi.service.http.port.secure");            
         } else {
-            port = System.getProperty("org.osgi.service.http.port");            
+            port = ctx.getProperty("org.osgi.service.http.port");            
         }
         if (port == null) {
-            port = "80";
+            port = "8080";
         }
         
         String hostName = null;

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java?rev=740760&r1=740759&r2=740760&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java Wed Feb  4 14:45:41 2009
@@ -1,11 +1,9 @@
 package org.apache.cxf.dosgi.dsw.handlers;
 
 import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 
 import junit.framework.TestCase;
 
@@ -29,70 +27,66 @@
 
 public class HttpServiceConfigurationTypeHandlerTest extends TestCase {
     public void testServer() throws Exception {
-        Properties savedProps = new Properties();
-        savedProps.putAll(System.getProperties());
-        try {
-            System.setProperty("org.osgi.service.http.port", "327");
-            
-            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");
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port")).
+            andReturn("1327").anyTimes();
+        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"};
                 }            
-            };
-                    
-            ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
-            BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
-            EasyMock.replay(sr);
-            EasyMock.replay(callingContext);
-    
-            Map<String, Object> props = new HashMap<String, Object>();
-            props.put(Constants.POJO_HTTP_SERVICE_CONTEXT, "/myRunnable");
-            ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
-            
-            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());
-            
-            String hostName = InetAddress.getLocalHost().getHostName();
-            Map<String, String> expected = new HashMap<String, String>();
-            expected.put("osgi.remote.configuration.type", "pojo");
-            expected.put("osgi.remote.configuration.pojo.address", "http://" + hostName + ":327/myRunnable");
-            expected.put("osgi.intents", "a.b.c");
-            assertEquals(expected, dp.getExposedProperties(sr));
-        } finally {
-            System.setProperties(savedProps);
-        }
+        };
+        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);
+        EasyMock.replay(sr);
+        EasyMock.replay(callingContext);
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.POJO_HTTP_SERVICE_CONTEXT, "/myRunnable");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
+        
+        assertEquals("Precondition failed", 0, dp.getExposedServices().size());
+        assertEquals("Precondition failed", "", sfb.getAddress());
+        h.createServer(sr, dswContext, callingContext, sd, Runnable.class, myService);
+        assertEquals("The address should be set to '/'. The Servlet context dictates the actual location.", "/", sfb.getAddress());
+        assertEquals(1, dp.getExposedServices().size());
+        assertSame(sr, dp.getExposedServices().iterator().next());
+        
+        String hostName = InetAddress.getLocalHost().getHostName();
+        Map<String, String> expected = new HashMap<String, String>();
+        expected.put("osgi.remote.configuration.type", "pojo");
+        expected.put("osgi.remote.configuration.pojo.address", "http://" + hostName + ":1327/myRunnable");
+        expected.put("osgi.intents", "a.b.c");
+        assertEquals(expected, dp.getExposedProperties(sr));
     } 
     
     public void testServerUsingDefaultAddress() throws Exception {
@@ -148,76 +142,72 @@
         String hostname = InetAddress.getLocalHost().getHostName();
         Map<String, String> expected = new HashMap<String, String>();
         expected.put("osgi.remote.configuration.type", "pojo");
-        expected.put("osgi.remote.configuration.pojo.address", "http://" + hostname + ":80/java/lang/Runnable");
+        expected.put("osgi.remote.configuration.pojo.address", "http://" + hostname + ":8080/java/lang/Runnable");
         assertEquals(expected, dp.getExposedProperties(sr));
     }
 
     public void testServerConfiguredUsingHttps() throws Exception {
-        Properties savedProps = new Properties();
-        savedProps.putAll(System.getProperties());
-        try {
-            System.setProperty("org.osgi.service.http.secure.enabled", "true");
-            System.setProperty("org.osgi.service.http.port.secure", "8443");
-            
-            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 [] {};
-                    }            
-            };
-            h.httpServiceReferences.add(httpSvcSR);
-            
-            Runnable myService = new Runnable() {
-                public void run() {
-                    System.out.println("blah");
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.secure.enabled")).
+            andReturn("true").anyTimes();
+        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port.secure")).
+            andReturn("8432").anyTimes();
+        
+        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 [] {};
                 }            
-            };
-                    
-            ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
-            BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
-            EasyMock.replay(sr);
-            EasyMock.replay(callingContext);
-    
-            Map<String, Object> props = new HashMap<String, Object>();
-            props.put(Constants.CONFIG_TYPE_PROPERTY, Constants.POJO_CONFIG_TYPE);
-            props.put(Constants.POJO_HTTP_SERVICE_CONTEXT, "/myRunnable");
-            ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
-            
-            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());
-            
-            String hostName = InetAddress.getLocalHost().getHostName();
-            Map<String, String> expected = new HashMap<String, String>();
-            expected.put("osgi.remote.configuration.type", "pojo");
-            expected.put("osgi.remote.configuration.pojo.address", "https://" + hostName + ":8443/myRunnable");
-            assertEquals(expected, dp.getExposedProperties(sr));
-        } finally {
-            System.setProperties(savedProps);
-        }
+        };
+        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);
+        EasyMock.replay(sr);
+        EasyMock.replay(callingContext);
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.CONFIG_TYPE_PROPERTY, Constants.POJO_CONFIG_TYPE);
+        props.put(Constants.POJO_HTTP_SERVICE_CONTEXT, "/myRunnable");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
+        
+        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());
+        
+        String hostName = InetAddress.getLocalHost().getHostName();
+        Map<String, String> expected = new HashMap<String, String>();
+        expected.put("osgi.remote.configuration.type", "pojo");
+        expected.put("osgi.remote.configuration.pojo.address", "https://" + hostName + ":8432/myRunnable");
+        assertEquals(expected, dp.getExposedProperties(sr));
     } 
 
     private ServerFactoryBean createMockServerFactoryBean() {
@@ -238,12 +228,12 @@
                 serverURI.append(EasyMock.getCurrentArguments()[0]);
                 return null;
             }            
-        });
+        }).anyTimes();
         EasyMock.expect(sfb.getAddress()).andAnswer(new IAnswer<String>() {
             public String answer() throws Throwable {
                 return serverURI.toString();
             }            
-        });
+        }).anyTimes();
         EasyMock.replay(sfb);
         return sfb;
     }

Modified: cxf/dosgi/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/parent/pom.xml?rev=740760&r1=740759&r2=740760&view=diff
==============================================================================
--- cxf/dosgi/trunk/parent/pom.xml (original)
+++ cxf/dosgi/trunk/parent/pom.xml Wed Feb  4 14:45:41 2009
@@ -46,6 +46,12 @@
             </dependency>
             <dependency>
                 <groupId>org.easymock</groupId>
+                <artifactId>easymock</artifactId>
+                <version>2.2</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.easymock</groupId>
                 <artifactId>easymockclassextension</artifactId>
                 <version>2.2</version>
                 <scope>test</scope>