You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2016/04/06 17:54:03 UTC
[1/2] aries-rsa git commit: ARIES-1518 - RSA exports services that
don't match the DistributionProvider
Repository: aries-rsa
Updated Branches:
refs/heads/master 19a9e0319 -> da63f3671
ARIES-1518 - RSA exports services that don't match the
DistributionProvider
adds a check if the service exports a config supported by the
DistributionProviders
Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/9af3f511
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/9af3f511
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/9af3f511
Branch: refs/heads/master
Commit: 9af3f511f92a4fbb5e86fdf85d5c897e4c6873c9
Parents: 19a9e03
Author: Johannes Utzig <j....@seeburger.de>
Authored: Wed Apr 6 15:05:03 2016 +0200
Committer: Johannes Utzig <j....@seeburger.de>
Committed: Wed Apr 6 15:07:14 2016 +0200
----------------------------------------------------------------------
.../aries/rsa/core/RemoteServiceAdminCore.java | 24 +++-
.../rsa/core/RemoteServiceAdminCoreTest.java | 124 +++++++++++++++++--
2 files changed, 140 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/9af3f511/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 60da887..d8f48da 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
@@ -104,7 +104,7 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin {
List<String> interfaceNames = getInterfaceNames(serviceProperties);
- if (isImportedService(serviceReference)) {
+ if (isImportedService(serviceReference) || !isExportConfigSupported(serviceProperties)) {
return Collections.emptyList();
}
@@ -124,6 +124,28 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin {
}
}
+ private boolean isExportConfigSupported(Map<String, Object> serviceProperties)
+ {
+ if (provider == null) {
+ return false;
+ }
+ List<String> exportedConfigs = StringPlus.normalize(serviceProperties.get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
+ if (exportedConfigs == null || exportedConfigs.isEmpty()) {
+ return true;
+ }
+ String[] supportedTypes = provider.getSupportedTypes();
+ if (supportedTypes == null || supportedTypes.length == 0) {
+ //if not set, all services should be accepted
+ return true;
+ }
+ for (String supportedType : supportedTypes)
+ {
+ if (exportedConfigs.contains(supportedType))
+ return true;
+ }
+ return false;
+ }
+
private void store(Map<String, Object> key, List<ExportRegistration> exportRegs) {
if (!exportRegs.isEmpty()) {
// enlist initial export registrations in global list of exportRegistrations
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/9af3f511/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 8836b38..0669918 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
@@ -18,13 +18,8 @@
*/
package org.apache.aries.rsa.core;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.isA;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -280,6 +275,121 @@ public class RemoteServiceAdminCoreTest {
assertEquals("No more exported services", 0, exportedServices.size());
}
+ @Test
+ public void testExportWrongConfig() throws Exception {
+ BundleContext bc = EasyMock.createMock(BundleContext.class);
+ EasyMock.expect(bc.getProperty(Constants.FRAMEWORK_VERSION)).andReturn(null).anyTimes();
+ bc.addServiceListener(EasyMock.<ServiceListener>anyObject(), EasyMock.<String>anyObject());
+ EasyMock.expectLastCall().anyTimes();
+ bc.removeServiceListener(EasyMock.<ServiceListener>anyObject());
+ EasyMock.expectLastCall().anyTimes();
+ EasyMock.expect(bc.getServiceReferences(EasyMock.<String>anyObject(),
+ EasyMock.<String>anyObject())).andReturn(null).anyTimes();
+ EasyMock.expect(bc.getAllServiceReferences(EasyMock.<String>anyObject(),
+ EasyMock.<String>anyObject())).andReturn(null).anyTimes();
+
+ Bundle b = createDummyRsaBundle(bc);
+
+ final Map<String, Object> sProps = new HashMap<String, Object>();
+ sProps.put("objectClass", new String[] {"java.lang.Runnable"});
+ sProps.put("service.id", 51L);
+ sProps.put("myProp", "myVal");
+ sProps.put("service.exported.interfaces", "*");
+ ServiceReference sref = mockServiceReference(sProps);
+
+ Runnable svcObject = EasyMock.createNiceMock(Runnable.class);
+ EasyMock.replay(svcObject);
+
+ EasyMock.expect((Runnable)bc.getService(sref)).andReturn(svcObject).anyTimes();
+ EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
+ EasyMock.expect(bc.createFilter("(service.id=51)"))
+ .andReturn(FrameworkUtil.createFilter("(service.id=51)")).anyTimes();
+ EasyMock.expect(bc.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID)).andReturn("1111");
+ EasyMock.expect(bc.getServiceReference(PackageAdmin.class)).andReturn(null);
+ EasyMock.replay(bc);
+
+ Map<String, Object> eProps = new HashMap<String, Object>(sProps);
+ eProps.put("endpoint.id", "http://something");
+ eProps.put("service.imported.configs", new String[] {"org.apache.cxf.ws"});
+
+ DistributionProvider handler = EasyMock.createStrictMock(DistributionProvider.class);
+ EasyMock.expect(handler.getSupportedTypes()).andReturn(new String[]{"something"});
+ //export service should never be called since the exported confgi does not match
+ EasyMock.replay(handler);
+
+ RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, bc, handler);
+ Map<String, String> extraProperties = new HashMap<>();
+ extraProperties.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, "org.apache.cxf.ws");
+ // Export the service for the first time
+ List<ExportRegistration> ereg = rsaCore.exportService(sref, extraProperties);
+ assertEquals(0, ereg.size());
+ }
+
+ @Test
+ public void testExportOneConfigSupported() throws Exception {
+ BundleContext bc = EasyMock.createMock(BundleContext.class);
+ EasyMock.expect(bc.getProperty(Constants.FRAMEWORK_VERSION)).andReturn(null).anyTimes();
+ bc.addServiceListener(EasyMock.<ServiceListener>anyObject(), EasyMock.<String>anyObject());
+ EasyMock.expectLastCall().anyTimes();
+ bc.removeServiceListener(EasyMock.<ServiceListener>anyObject());
+ EasyMock.expectLastCall().anyTimes();
+ EasyMock.expect(bc.getServiceReferences(EasyMock.<String>anyObject(),
+ EasyMock.<String>anyObject())).andReturn(null).anyTimes();
+ EasyMock.expect(bc.getAllServiceReferences(EasyMock.<String>anyObject(),
+ EasyMock.<String>anyObject())).andReturn(null).anyTimes();
+
+ Bundle b = createDummyRsaBundle(bc);
+
+ final Map<String, Object> sProps = new HashMap<String, Object>();
+ sProps.put("objectClass", new String[] {"java.lang.Runnable"});
+ sProps.put("service.id", 51L);
+ sProps.put("myProp", "myVal");
+ sProps.put("service.exported.interfaces", "*");
+ ServiceReference sref = mockServiceReference(sProps);
+
+ Runnable svcObject = EasyMock.createNiceMock(Runnable.class);
+ EasyMock.replay(svcObject);
+
+ EasyMock.expect((Runnable)bc.getService(sref)).andReturn(svcObject).anyTimes();
+ EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
+ EasyMock.expect(bc.createFilter("(service.id=51)"))
+ .andReturn(FrameworkUtil.createFilter("(service.id=51)")).anyTimes();
+ EasyMock.expect(bc.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID)).andReturn("1111");
+ EasyMock.expect(bc.getServiceReference(PackageAdmin.class)).andReturn(null);
+ EasyMock.replay(bc);
+
+ Map<String, Object> eProps = new HashMap<String, Object>(sProps);
+ eProps.put("endpoint.id", "http://something");
+ eProps.put("service.imported.configs", new String[] {"org.apache.cxf.ws","aconfig"});
+ final EndpointDescription epd = new EndpointDescription(eProps);
+ Endpoint er = new Endpoint() {
+
+ @Override
+ public void close() throws IOException {
+ }
+
+ @Override
+ public EndpointDescription description() {
+ return epd;
+ }
+ };
+
+ DistributionProvider handler = EasyMock.createStrictMock(DistributionProvider.class);
+ EasyMock.expect(handler.getSupportedTypes()).andReturn(new String[]{"something","aconfig"});
+ EasyMock.expect(handler.exportService(anyObject(),
+ anyObject(BundleContext.class),
+ anyObject(Map.class), isA(Class[].class))).andReturn(er);
+ //export service should never be called since the exported confgi does not match
+ EasyMock.replay(handler);
+
+ RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, bc, handler);
+ Map<String, Object> extraProperties = new HashMap<>();
+ extraProperties.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, new String[]{"org.apache.cxf.ws","aconfig"});
+ // Export the service for the first time
+ List<ExportRegistration> ereg = rsaCore.exportService(sref, extraProperties);
+ assertEquals(1, ereg.size());
+ }
+
private Bundle createDummyRsaBundle(BundleContext bc) {
Bundle b = EasyMock.createNiceMock(Bundle.class);
EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
[2/2] aries-rsa git commit: [ARIES-1518] Fix code style. Closes #1
Posted by cs...@apache.org.
[ARIES-1518] Fix code style. Closes #1
Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/da63f367
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/da63f367
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/da63f367
Branch: refs/heads/master
Commit: da63f3671760bf514aea6480b27d1f0c025479c1
Parents: 9af3f51
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Wed Apr 6 17:53:46 2016 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Wed Apr 6 17:53:46 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/da63f367/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 d8f48da..b7a93f1 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
@@ -138,10 +138,10 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin {
//if not set, all services should be accepted
return true;
}
- for (String supportedType : supportedTypes)
- {
- if (exportedConfigs.contains(supportedType))
+ for (String supportedType : supportedTypes) {
+ if (exportedConfigs.contains(supportedType)) {
return true;
+ }
}
return false;
}