cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject cxf-dosgi git commit: [DOSGI-229] Allow to use more than one interface for import
Date Mon, 07 Mar 2016 09:14:04 GMT
Repository: cxf-dosgi
Updated Branches:
  refs/heads/master 3d3ebed88 -> a50db4a1a


[DOSGI-229] Allow to use more than one interface for import


Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/a50db4a1
Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/a50db4a1
Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/a50db4a1

Branch: refs/heads/master
Commit: a50db4a1aaac6f8388ada84bb266964963a983f1
Parents: 3d3ebed
Author: Christian Schneider <chris@die-schneider.net>
Authored: Mon Mar 7 10:13:50 2016 +0100
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Mon Mar 7 10:13:50 2016 +0100

----------------------------------------------------------------------
 .../cxf/dosgi/dsw/api/DistributionProvider.java |  6 +--
 .../dsw/handlers/CXFDistributionProvider.java   |  2 +-
 .../JaxRSPojoConfigurationTypeHandler.java      |  3 +-
 .../handlers/PojoConfigurationTypeHandler.java  |  3 +-
 .../handlers/WsdlConfigurationTypeHandler.java  |  3 +-
 .../dosgi/dsw/service/ClientServiceFactory.java | 18 ++++---
 .../dsw/handlers/ClientServiceFactoryTest.java  | 56 +++++++++++++++-----
 .../PojoConfigurationTypeHandlerTest.java       |  2 +-
 8 files changed, 66 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a50db4a1/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java
b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java
index fad6b03..9a8c0ca 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java
@@ -32,7 +32,7 @@ public interface DistributionProvider {
      * @param sref reference of the service to be exported
      * @param effectiveProperties combined properties of the service and additional properties
from rsa
      * @param exportedInterface name of the interface to be exported
-     * @return
+     * @return closeable Endpoint that represents the service that is exposed to the outside
world
      */
     Endpoint exportService(ServiceReference<?> sref, 
                            Map<String, Object> effectiveProperties,
@@ -40,13 +40,13 @@ public interface DistributionProvider {
 
     /**
      * @param sref reference of the service offered to the requesting bundle
-     * @param iClass interface of the service to proxy
+     * @param interfaces interfaces of the service to proxy
      * @param endpoint description of the remote endpoint
      * @return service proxy to be given to the requesting bundle
      * @throws IntentUnsatisfiedException
      */
     Object importEndpoint(BundleContext consumerContext, 
-                          Class<?> iClass, 
+                          Class<?>[] interfaces, 
                           EndpointDescription endpoint)
         throws IntentUnsatisfiedException;
     

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a50db4a1/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java
b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java
index dad4a89..0be2fbf 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java
@@ -79,7 +79,7 @@ public class CXFDistributionProvider implements DistributionProvider {
     }
 
     @Override
-    public Object importEndpoint(BundleContext consumerContext, Class<?> iClass, EndpointDescription
endpoint)
+    public Object importEndpoint(BundleContext consumerContext, Class<?>[] iClass,
EndpointDescription endpoint)
         throws IntentUnsatisfiedException {
         List<String> configurationTypes = determineConfigTypesForImport(endpoint);
         DistributionProvider handler = getHandler(configurationTypes, endpoint.getProperties());

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a50db4a1/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
index 3c95200..e67bc31 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
@@ -56,8 +56,9 @@ public class JaxRSPojoConfigurationTypeHandler extends AbstractPojoConfiguration
     }
 
     public Object importEndpoint(BundleContext consumerContext,
-                              Class<?> iClass,
+                              Class<?>[] interfaces,
                               EndpointDescription endpoint) {
+        Class<?> iClass = interfaces[0];
         String address = getPojoAddress(endpoint, iClass);
         if (address == null) {
             LOG.warn("Remote address is unavailable");

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a50db4a1/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
index fefa0ee..0451a8e 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
@@ -55,8 +55,9 @@ public class PojoConfigurationTypeHandler extends AbstractPojoConfigurationTypeH
     }
 
     public Object importEndpoint(BundleContext consumerContext,
-                              Class<?> iClass,
+                              Class<?>[] interfaces,
                               EndpointDescription endpoint) throws IntentUnsatisfiedException
{
+        Class<?> iClass = interfaces[0];
         Map<String, Object> sd = endpoint.getProperties();
         String address = getClientAddress(sd);
         if (address == null) {

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a50db4a1/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
index ec0f638..9384958 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
@@ -55,8 +55,9 @@ public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeH
     }
 
     public Object importEndpoint(BundleContext consumerContext,
-                              Class<?> iClass,
+                              Class<?>[] interfaces,
                               EndpointDescription endpoint) {
+        Class<?> iClass = interfaces[0];
         String wsdlAddressProp = getWsdlAddress(endpoint, iClass);
         if (wsdlAddressProp == null) {
             LOG.warn("WSDL address is unavailable");

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a50db4a1/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
index 343c406..b482b64 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
@@ -20,6 +20,7 @@ package org.apache.cxf.dosgi.dsw.service;
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -52,14 +53,17 @@ public class ClientServiceFactory implements ServiceFactory {
     }
 
     public Object getService(final Bundle requestingBundle, final ServiceRegistration sreg)
{
-        List<String> interfaces = endpoint.getInterfaces();
-        String interfaceName = interfaces == null || interfaces.isEmpty() ? null : interfaces.get(0);
-        LOG.debug("getService() from serviceFactory for {}", interfaceName);
+        List<String> interfaceNames = endpoint.getInterfaces();
         try {
-            final Class<?> iClass = requestingBundle.loadClass(interfaceName);
+            LOG.debug("getService() from serviceFactory for {}", interfaceNames);
+            final List<Class<?>> interfaces = new ArrayList<Class<?>>();
+            for (String ifaceName : interfaceNames) {
+                interfaces.add(requestingBundle.loadClass(ifaceName));
+            }
             Object proxy = AccessController.doPrivileged(new PrivilegedAction<Object>()
{
                 public Object run() {
-                    return handler.importEndpoint(requestingBundle.getBundleContext(), iClass,
endpoint);
+                    Class<?>[] ifAr = interfaces.toArray(new Class[]{});
+                    return handler.importEndpoint(requestingBundle.getBundleContext(), ifAr,
endpoint);
                 }
             });
 
@@ -69,9 +73,9 @@ public class ClientServiceFactory implements ServiceFactory {
             return proxy;
         } catch (IntentUnsatisfiedException iue) {
             LOG.info("Did not create proxy for {} because intent {} could not be satisfied",
-                    interfaceName, iue.getIntent());
+                    interfaceNames, iue.getIntent());
         } catch (Exception e) {
-            LOG.warn("Problem creating a remote proxy for {}", interfaceName, e);
+            LOG.warn("Problem creating a remote proxy for {}", interfaceNames, e);
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a50db4a1/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
index afc45d1..8de459d 100644
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
+++ b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
@@ -18,12 +18,15 @@
  */
 package org.apache.cxf.dosgi.dsw.handlers;
 
+
 import java.util.HashMap;
 import java.util.Map;
 
 import junit.framework.TestCase;
 
 import org.apache.cxf.dosgi.dsw.api.DistributionProvider;
+import org.apache.cxf.dosgi.dsw.api.Endpoint;
+import org.apache.cxf.dosgi.dsw.api.IntentUnsatisfiedException;
 import org.apache.cxf.dosgi.dsw.service.ClientServiceFactory;
 import org.apache.cxf.dosgi.dsw.service.ImportRegistrationImpl;
 import org.easymock.EasyMock;
@@ -31,6 +34,7 @@ import org.easymock.IMocksControl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
@@ -41,17 +45,10 @@ public class ClientServiceFactoryTest extends TestCase {
      "rawtypes", "unchecked"
     })
     public void testGetService() throws ClassNotFoundException {
-        Object myTestProxyObject = new Object();
+        final Object myTestProxyObject = new Object();
 
         IMocksControl control = EasyMock.createControl();
-        Map<String, Object> map = new HashMap<String, Object>();
-        map.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
-        map.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "myGreatConfiguration");
-        map.put(Constants.OBJECTCLASS, new String[]{String.class.getName()});
-
-        EndpointDescription endpoint = new EndpointDescription(map);
-        
-
+        EndpointDescription endpoint = createTestEndpointDesc();
         ImportRegistrationImpl iri = new ImportRegistrationImpl(endpoint, null);
 
         BundleContext requestingContext = control.createMock(BundleContext.class);
@@ -60,12 +57,47 @@ public class ClientServiceFactoryTest extends TestCase {
         EasyMock.expect(requestingBundle.getBundleContext()).andReturn(requestingContext);
         ServiceRegistration sreg = control.createMock(ServiceRegistration.class);
 
-        DistributionProvider handler = control.createMock(DistributionProvider.class);
-        handler.importEndpoint(requestingContext, String.class, endpoint);
-        EasyMock.expectLastCall().andReturn(myTestProxyObject);
+        DistributionProvider handler = mockDistributionProvider(myTestProxyObject);
         control.replay();
 
         ClientServiceFactory csf = new ClientServiceFactory(endpoint, handler, iri);
         assertSame(myTestProxyObject, csf.getService(requestingBundle, sreg));
     }
+
+    /**
+     * Creating dummy class as I was not able to really mock it
+     * @param myTestProxyObject
+     * @return
+     */
+    private DistributionProvider mockDistributionProvider(final Object myTestProxyObject)
{
+        return new DistributionProvider() {
+            
+            @Override
+            public Object importEndpoint(BundleContext consumerContext, Class<?>[]
interfaces,
+                                         EndpointDescription endpoint)
+                throws IntentUnsatisfiedException {
+                return myTestProxyObject;
+            }
+            
+            @Override
+            public String[] getSupportedTypes() {
+                return null;
+            }
+            
+            @Override
+            public Endpoint exportService(ServiceReference<?> sref, Map<String,
Object> effectiveProperties,
+                                          String exportedInterface) {
+                return null;
+            }
+        };
+    }
+
+    private EndpointDescription createTestEndpointDesc() {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
+        map.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "myGreatConfiguration");
+        map.put(Constants.OBJECTCLASS, new String[]{String.class.getName()});
+        EndpointDescription endpoint = new EndpointDescription(map);
+        return endpoint;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a50db4a1/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
index 8e9d64d..4058de4 100644
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
+++ b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
@@ -148,7 +148,7 @@ public class PojoConfigurationTypeHandlerTest extends TestCase {
         EasyMock.expectLastCall().atLeastOnce();
 
         c.replay();
-        Object proxy = p.importEndpoint(requestingContext, CharSequence.class, endpoint);
+        Object proxy = p.importEndpoint(requestingContext, new Class<?>[]{CharSequence.class},
endpoint);
         assertNotNull(proxy);
         assertTrue("Proxy is not of the requested type! ", proxy instanceof CharSequence);
         c.verify();


Mime
View raw message