You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ju...@apache.org on 2017/01/31 10:47:30 UTC

[1/2] aries-rsa git commit: RSA does not export all interfaces

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 <ju...@apache.org>
Authored: Mon Jan 30 18:00:16 2017 +0100
Committer: Johannes Utzig <ju...@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");


[2/2] aries-rsa git commit: use own classloader as fallback if class not found

Posted by ju...@apache.org.
use own classloader as fallback if class not found

e.g. if the consuming bundle does not import service exception we can
look the class up from our own classloader

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

Branch: refs/heads/master
Commit: 09771c940422a3f83d3779d6d8b482959605f95a
Parents: 2331e82
Author: Johannes Utzig <ju...@apache.org>
Authored: Mon Jan 30 17:13:59 2017 +0100
Committer: Johannes Utzig <ju...@apache.org>
Committed: Tue Jan 31 11:45:14 2017 +0100

----------------------------------------------------------------------
 .../provider/fastbin/util/ClassLoaderObjectInputStream.java    | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/09771c94/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java
----------------------------------------------------------------------
diff --git a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java
index e9f1d9c..6740938 100644
--- a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java
+++ b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/util/ClassLoaderObjectInputStream.java
@@ -70,6 +70,12 @@ public class ClassLoaderObjectInputStream extends ObjectInputStream {
             if (clazz != null) {
                 return clazz;
             } else {
+                try{
+                    //try to load it with our own classloader (could be e.g. a service exception)
+                    return Class.forName(className, false, this.getClassLoader());
+                } catch(ClassNotFoundException e2) {
+                    //ignore
+                }
                 throw e;
             }
         }