cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r701337 - in /cxf/sandbox/dosgi/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/handlers/ main/java/org/apache/cxf/dosgi/dsw/service/ test/java/org/apache/cxf/dosgi/dsw/handlers/ test/java/org/apache/cxf/dosgi/dsw/service/
Date Fri, 03 Oct 2008 09:33:29 GMT
Author: eglynn
Date: Fri Oct  3 02:33:28 2008
New Revision: 701337

URL: http://svn.apache.org/viewvc?rev=701337&view=rev
Log:
Applied another patch for CXF-1836 on behalf of David Bosschaert.


Modified:
    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/service/CxfDistributionProvider.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.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
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImplTest.java

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=701337&r1=701336&r2=701337&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
Fri Oct  3 02:33:28 2008
@@ -18,6 +18,7 @@
   */
 package org.apache.cxf.dosgi.dsw.handlers;
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -120,11 +121,19 @@
 
         applyIntents(dswContext, callingContext, factory.getFeatures(), factory, sd);
 
-        Server server = factory.create();        
-        getDistributionProvider().addExposedService(serviceReference);
+        Server server = factory.create();                
+        getDistributionProvider().addExposedService(serviceReference, registerPublication(server));
         return server;
     }
 
+    private Map<String, String> registerPublication(Server server) {
+        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());
+        return publicationProperties;
+    }
+
     void applyIntents(BundleContext dswContext,
                                              BundleContext callingContext,
                                      List<AbstractFeature> features,

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/CxfDistributionProvider.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/CxfDistributionProvider.java?rev=701337&r1=701336&r2=701337&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/CxfDistributionProvider.java
(original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/CxfDistributionProvider.java
Fri Oct  3 02:33:28 2008
@@ -18,10 +18,12 @@
   */
 package org.apache.cxf.dosgi.dsw.service;
 
+import java.util.Map;
+
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.dsw.DistributionProvider;
 
 public interface CxfDistributionProvider extends DistributionProvider {
-    void addExposedService(ServiceReference serviceReference);
+    void addExposedService(ServiceReference serviceReference, Map<String, String> publicationProperties);
     void addRemoteService(ServiceReference serviceReference);   
 }

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java?rev=701337&r1=701336&r2=701337&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
(original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
Fri Oct  3 02:33:28 2008
@@ -19,6 +19,7 @@
 package org.apache.cxf.dosgi.dsw.service;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -28,11 +29,15 @@
 
 
 public class DistributionProviderImpl implements DistributionProvider, CxfDistributionProvider
{
+    private Map<ServiceReference, Map<String, String>> publicationProperties
= 
+        new HashMap<ServiceReference, Map<String,String>>();
     private Set<ServiceReference> exposedServices = new HashSet<ServiceReference>();

     private Set<ServiceReference> remoteServices = new HashSet<ServiceReference>();

     
-    public Map getPublicationProperties(ServiceReference sr) {
-        return Collections.EMPTY_MAP;
+    public Map<String, String> getPublicationProperties(ServiceReference sr) {
+        synchronized (publicationProperties) {
+            return publicationProperties.get(sr);            
+        }
     }
     
     public ServiceReference[] getExposedServices() {
@@ -51,10 +56,16 @@
         }
     }
 
-    public void addExposedService(ServiceReference sr) {
+    public void addExposedService(ServiceReference sr, Map<String, String> pp) {
         synchronized (exposedServices) {
             exposedServices.add(sr);
         }
+        synchronized (publicationProperties) {
+            if (pp == null) {
+                pp = Collections.emptyMap();
+            }
+            publicationProperties.put(sr, pp);
+        }
     }
 
     public void addRemoteService(ServiceReference sr) {

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java?rev=701337&r1=701336&r2=701337&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
(original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
Fri Oct  3 02:33:28 2008
@@ -1,3 +1,21 @@
+/** 
+  * 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 junit.framework.TestCase;

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=701337&r1=701336&r2=701337&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
Fri Oct  3 02:33:28 2008
@@ -27,10 +27,15 @@
 import org.apache.cxf.dosgi.dsw.Constants;
 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.ClientProxyFactoryBean;
 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;
@@ -85,14 +90,8 @@
     }
     
     public void testCreateServerPopulatesDistributionProvider() {
-        String myService = "Hi";
-        
-        ReflectionServiceFactoryBean sf = EasyMock.createNiceMock(ReflectionServiceFactoryBean.class);
-        EasyMock.replay(sf);
-        
-        final ServerFactoryBean sfb = EasyMock.createNiceMock(ServerFactoryBean.class);
-        EasyMock.expect(sfb.getServiceFactory()).andReturn(sf).anyTimes();        
-        EasyMock.replay(sfb);
+        String myService = "Hi";                
+        final ServerFactoryBean sfb = createMockServerFactoryBean();
         
         DistributionProviderImpl dp = new DistributionProviderImpl();
         PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps)
{
@@ -119,5 +118,61 @@
         p.createServer(sr, dswContext, callingContext, sd, String.class, myService);
         assertEquals(1, dp.getExposedServices().length);
         assertSame(sr, dp.getExposedServices()[0]);
+        
+        Map<String, String> expected = new HashMap<String, String>();
+        expected.put("osgi.remote.configuration.type", "pojo");
+        expected.put("osgi.remote.configuration.pojo.address", "http://somehost:54321/java/lang/String");
+        assertEquals(expected, dp.getPublicationProperties(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;
     }
 }

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=701337&r1=701336&r2=701337&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
Fri Oct  3 02:33:28 2008
@@ -1,3 +1,21 @@
+/** 
+  * 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.net.URL;

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImplTest.java?rev=701337&r1=701336&r2=701337&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImplTest.java
(original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImplTest.java
Fri Oct  3 02:33:28 2008
@@ -18,6 +18,9 @@
   */
 package org.apache.cxf.dosgi.dsw.service;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import junit.framework.TestCase;
 
 import org.osgi.framework.Bundle;
@@ -33,19 +36,19 @@
         ServiceReference sr = new TestServiceReference();
         ServiceReference sr2 = new TestServiceReference();
         
-        dp.addExposedService(sr);
+        dp.addExposedService(sr, null);
         assertEquals(1, dp.getExposedServices().length);
         assertEquals(0, dp.getPublishedServices().length);
         assertEquals(0, dp.getRemoteServices().length);
         assertSame(sr, dp.getExposedServices()[0]);
 
-        dp.addExposedService(sr);
+        dp.addExposedService(sr, null);
         assertEquals(1, dp.getExposedServices().length);
         assertEquals(0, dp.getPublishedServices().length);
         assertEquals(0, dp.getRemoteServices().length);
         assertSame(sr, dp.getExposedServices()[0]);
 
-        dp.addExposedService(sr2);
+        dp.addExposedService(sr2, null);
         assertEquals(2, dp.getExposedServices().length);        
         assertEquals(0, dp.getPublishedServices().length);
         assertEquals(0, dp.getRemoteServices().length);
@@ -78,6 +81,22 @@
         assertEquals(2, dp.getRemoteServices().length);
     }
     
+    public void testPublicationProperties() {
+        DistributionProviderImpl dp = new DistributionProviderImpl();
+        ServiceReference sr = new TestServiceReference();
+        ServiceReference sr2 = new TestServiceReference();
+        
+        assertNull(dp.getPublicationProperties(sr));
+        
+        dp.addExposedService(sr, null);
+        Map<String, String> pp = new HashMap<String, String>();
+        pp.put("a", "b");
+        dp.addExposedService(sr2, pp);
+
+        assertEquals(0, dp.getPublicationProperties(sr).size());
+        assertEquals(pp, dp.getPublicationProperties(sr2));
+    }
+    
     private static class TestServiceReference implements ServiceReference {
         public Bundle getBundle() {
             return null;



Mime
View raw message