aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jut...@apache.org
Subject [1/2] aries-rsa git commit: RSA does not export all interfaces
Date Tue, 31 Jan 2017 10:47:30 GMT
Repository: aries-rsa
Updated Branches:
  refs/heads/master a6945ded6 -> 09771c940


RSA does not export all interfaces

if a service should expose multiple interaces (e.g.
exported.interfaces=* and it implements multiple interfaces) the RSA
must register the service under all interfaces names, not just the first

Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/2331e82e
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/2331e82e
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/2331e82e

Branch: refs/heads/master
Commit: 2331e82ef2bce61798c0df26c13a1064d99eead7
Parents: a6945de
Author: Johannes Utzig <jutzig@apache.org>
Authored: Mon Jan 30 18:00:16 2017 +0100
Committer: Johannes Utzig <jutzig@apache.org>
Committed: Mon Jan 30 18:00:16 2017 +0100

----------------------------------------------------------------------
 .../aries/rsa/core/RemoteServiceAdminCore.java  |  8 +--
 .../rsa/core/RemoteServiceAdminCoreTest.java    | 54 ++++++++++++++++++++
 2 files changed, 58 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/2331e82e/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
----------------------------------------------------------------------
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
index b20e53b..5396a66 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
@@ -378,7 +378,7 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin {
             LOG.info("Importing service {} with interfaces {} using handler {}.", 
                      endpoint.getId(), endpoint.getInterfaces(), provider.getClass());
 
-            ImportRegistrationImpl imReg = exposeServiceFactory(matchingInterfaces.get(0),
endpoint, provider);
+            ImportRegistrationImpl imReg = exposeServiceFactory(matchingInterfaces.toArray(new
String[matchingInterfaces.size()]), endpoint, provider);
             if (imRegs == null) {
                 imRegs = new ArrayList<ImportRegistrationImpl>();
                 importedServices.put(endpoint, imRegs);
@@ -406,7 +406,7 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin {
         return usableConfigurationTypes;
     }
 
-    protected ImportRegistrationImpl exposeServiceFactory(String interfaceName,
+    protected ImportRegistrationImpl exposeServiceFactory(String[] interfaceNames,
                                             EndpointDescription epd,
                                             DistributionProvider handler) {
         ImportRegistrationImpl imReg = new ImportRegistrationImpl(epd, this);
@@ -424,11 +424,11 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin {
              *  If the bundle publishing the factory does not import the service interface
              *  package then the factory is visible for all consumers which we want.
              */
-            ServiceRegistration<?> csfReg = apictx.registerService(interfaceName, csf,
serviceProps);
+            ServiceRegistration<?> csfReg = apictx.registerService(interfaceNames,
csf, serviceProps);
             imReg.setImportedServiceRegistration(csfReg);
         } catch (Exception ex) {
             // Only logging at debug level as this might be written to the log at the TopologyManager
-            LOG.debug("Can not proxy service with interface " + interfaceName + ": " + ex.getMessage(),
ex);
+            LOG.debug("Can not proxy service with interfaces " + Arrays.toString(interfaceNames)
+ ": " + ex.getMessage(), ex);
             imReg.setException(ex);
         }
         return imReg;

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/2331e82e/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java
----------------------------------------------------------------------
diff --git a/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java b/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java
index 0669918..79c6c76 100644
--- a/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java
+++ b/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java
@@ -155,6 +155,60 @@ public class RemoteServiceAdminCoreTest {
         c.verify();
     }
 
+
+    @Test
+    public void testImportWithMultipleInterfaces() {
+        IMocksControl c = EasyMock.createNiceControl();
+        Bundle b = c.createMock(Bundle.class);
+        BundleContext bc = c.createMock(BundleContext.class);
+
+        Dictionary<String, String> d = new Hashtable<String, String>();
+        EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes();
+
+        EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
+
+        EasyMock.expect(bc.registerService(EasyMock.aryEq(new String[]{"es.schaaf.my.class","java.lang.Runnable"}),
anyObject(), (Dictionary<String, ? >)anyObject())).andReturn(null);
+        EasyMock.expect(b.getSymbolicName()).andReturn("BundleName").anyTimes();
+
+        DistributionProvider provider = c.createMock(DistributionProvider.class);
+        EasyMock.expect(provider.getSupportedTypes())
+            .andReturn(new String[]{MYCONFIG}).atLeastOnce();
+        c.replay();
+
+        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, bc, provider);
+
+
+        Map<String, Object> p = new HashMap<String, Object>();
+        p.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
+        p.put(Constants.OBJECTCLASS, new String[] {
+            "es.schaaf.my.class",
+            "java.lang.Runnable"
+        });
+        p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, MYCONFIG);
+        EndpointDescription endpoint = new EndpointDescription(p);
+
+        ImportRegistration ireg = rsaCore.importService(endpoint);
+
+        assertNotNull(ireg);
+
+        assertEquals(1, rsaCore.getImportedEndpoints().size());
+
+        // lets import the same endpoint once more -> should get a copy of the ImportRegistration
+        ImportRegistration ireg2 = rsaCore.importService(endpoint);
+        assertNotNull(ireg2);
+        assertEquals(2, rsaCore.getImportedEndpoints().size());
+
+        assertEquals(ireg.getImportReference(), (rsaCore.getImportedEndpoints().toArray())[0]);
+
+        assertEquals(ireg.getImportReference().getImportedEndpoint(), ireg2.getImportReference()
+            .getImportedEndpoint());
+
+        EndpointDescription importedEndpoint = ireg.getImportReference().getImportedEndpoint();
+        assertEquals(2,importedEndpoint.getInterfaces().size());
+
+        c.verify();
+    }
+
     private EndpointDescription creatEndpointDesc(String configType) {
         Map<String, Object> p = new HashMap<String, Object>();
         p.put(RemoteConstants.ENDPOINT_ID, "http://google.de");


Mime
View raw message