You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2010/01/13 14:28:39 UTC
svn commit: r898744 [1/3] - in /cxf/dosgi/trunk:
discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/
discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/
dsw/cxf-dsw/ dsw/cxf-dsw/src/main/java/org/...
Author: davidb
Date: Wed Jan 13 13:28:38 2010
New Revision: 898744
URL: http://svn.apache.org/viewvc?rev=898744&view=rev
Log:
Committing new_interfaces__more_tests__clean_shutdown__smaller_issues_for_tck.patch from DOSGI-13 on behalf of Marc Schaaf
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportReferenceImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRuleTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHookTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtilsTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImplTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/src/main/java/org/osgi/service/remoteserviceadmin/EndpointDescription.java
cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/src/main/java/org/osgi/service/remoteserviceadmin/EndpointPermission.java
cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/src/main/java/org/osgi/service/remoteserviceadmin/RemoteServiceAdmin.java
cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/src/main/java/org/osgi/service/remoteserviceadmin/RemoteServiceAdminListener.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManagerImport.java
Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java Wed Jan 13 13:28:38 2010
@@ -51,8 +51,6 @@
private Logger LOG = Logger.getLogger(EndpointListenerImpl.class.getName());
- private static final Pattern LOCALHOST_MATCH = Pattern.compile("(.*://)(localhost|127.0.0.1)(:.*)");
-
private ZooKeeperDiscovery discovery;
private BundleContext bctx;
@@ -85,7 +83,7 @@
try {
Collection<String> interfaces = endpoint.getInterfaces();
- String endpointKey = getKey(endpoint.getRemoteID());
+ String endpointKey = getKey(endpoint.getId());
ZooKeeper zk = getZooKeeper();
for (String name : interfaces) {
@@ -130,7 +128,7 @@
private void removeEndpoint(EndpointDescription endpoint) throws UnknownHostException,
URISyntaxException, InterruptedException, KeeperException {
Collection<String> interfaces = endpoint.getInterfaces();
- String endpointKey = getKey(endpoint.getRemoteID());
+ String endpointKey = getKey(endpoint.getId());
ZooKeeper zk = getZooKeeper();
for (String name : interfaces) {
@@ -162,7 +160,6 @@
static byte[] getData(EndpointDescription sr) throws IOException {
Properties p = new Properties();
- String host = InetAddress.getLocalHost().getHostAddress();
Map<String, Object> serviceProps = (Map<String, Object>)sr.getProperties();
if (serviceProps != null) {
@@ -172,7 +169,7 @@
// null values are not allowed
continue;
}
- p.setProperty(prop.getKey(), filterLocalHost(val.toString(), host));
+ p.setProperty(prop.getKey(), val.toString());
}
}
@@ -191,24 +188,8 @@
return baos.toByteArray();
}
- static String filterLocalHost(String value, String replacement) {
- Matcher m = LOCALHOST_MATCH.matcher(value);
- return m.replaceAll("$1" + replacement + "$3");
- }
-
- // private static void copyProperty(String key, ServiceReference sr, Properties p, String localhost) {
- // Object eID = sr.getProperty(key);
- // if (eID != null) {
- // p.setProperty(key, filterLocalHost(eID.toString(), localhost));
- // }
- // }
-
static String getKey(String endpoint) throws UnknownHostException, URISyntaxException {
URI uri = new URI(endpoint);
- if ("localhost".equals(uri.getHost()) || "127.0.0.1".equals(uri.getHost())) {
- uri = new URI(uri.getScheme(), uri.getUserInfo(), InetAddress.getLocalHost().getHostAddress(),
- uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
- }
StringBuilder sb = new StringBuilder();
sb.append(uri.getHost());
Modified: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryTest.java Wed Jan 13 13:28:38 2010
@@ -125,7 +125,7 @@
Set<String> actual = new HashSet<String>();
for (Map.Entry<EndpointDescription, Bundle> entry : ld.endpointDescriptions.entrySet()) {
assertSame(b2, entry.getValue());
- actual.add(entry.getKey().getRemoteID());
+ actual.add(entry.getKey().getId());
}
assertEquals(expected, actual);
}
@@ -170,7 +170,7 @@
ld.bundleChanged(be);
assertEquals(1, ld.endpointDescriptions.size());
EndpointDescription ed = ld.endpointDescriptions.keySet().iterator().next();
- assertEquals("http://somewhere:12345", ed.getRemoteID());
+ assertEquals("http://somewhere:12345", ed.getId());
assertSame(bundle, ld.endpointDescriptions.get(ed));
EasyMock.verify(el);
Modified: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java Wed Jan 13 13:28:38 2010
@@ -76,22 +76,22 @@
List<EndpointDescription> eds = LocalDiscoveryUtils.getAllEndpointDescriptions(b);
assertEquals(4, eds.size());
EndpointDescription ed0 = eds.get(0);
- assertEquals("http://somewhere:12345", ed0.getRemoteID());
+ assertEquals("http://somewhere:12345", ed0.getId());
assertEquals(Arrays.asList("SomeService"), ed0.getInterfaces());
assertEquals(Arrays.asList("confidentiality"),
ed0.getProperties().get("osgi.remote.requires.intents"));
assertEquals("testValue", ed0.getProperties().get("testKey"));
EndpointDescription ed1 = eds.get(1);
- assertEquals("myScheme://somewhere:12345", ed1.getRemoteID());
+ assertEquals("myScheme://somewhere:12345", ed1.getId());
assertEquals(Arrays.asList("SomeOtherService", "WithSomeSecondInterface"), ed1.getInterfaces());
EndpointDescription ed2 = eds.get(2);
- assertEquals("http://somewhere", ed2.getRemoteID());
+ assertEquals("http://somewhere", ed2.getId());
assertEquals(Arrays.asList("SomeOtherService", "WithSomeSecondInterface"), ed2.getInterfaces());
EndpointDescription ed3 = eds.get(3);
- assertEquals("http://somewhere:1/2/3/4?5", ed3.getRemoteID());
+ assertEquals("http://somewhere:1/2/3/4?5", ed3.getId());
assertEquals(Arrays.asList("SomeOtherService", "WithSomeSecondInterface"), ed3.getInterfaces());
}
@@ -109,7 +109,7 @@
List<EndpointDescription> eds = LocalDiscoveryUtils.getAllEndpointDescriptions(b);
assertEquals(2, eds.size());
EndpointDescription ed0 = eds.get(0);
- assertEquals("foo:bar", ed0.getRemoteID());
+ assertEquals("foo:bar", ed0.getId());
assertEquals(Arrays.asList("com.acme.HelloService"), ed0.getInterfaces());
assertEquals(Arrays.asList("SOAP"), ed0.getIntents());
// changed from exported to imported
@@ -168,7 +168,7 @@
List<EndpointDescription> eds = LocalDiscoveryUtils.getAllEndpointDescriptions(b);
assertEquals(1, eds.size());
EndpointDescription ed = eds.get(0);
- assertEquals("http://localhost:9090/greeter", ed.getRemoteID());
+ assertEquals("http://localhost:9090/greeter", ed.getId());
assertEquals(Arrays.asList("org.apache.cxf.ws"), ed.getConfigurationTypes());
assertEquals(Arrays.asList("org.apache.cxf.dosgi.samples.greeter.GreeterService"), ed.getInterfaces());
assertNull("Should not contain service.exported.*",
@@ -191,7 +191,7 @@
assertEquals(2, eds.size());
EndpointDescription ed0 = eds.get(0);
- assertEquals("http://localhost:9000/org/example/SomeService", ed0.getRemoteID());
+ assertEquals("http://localhost:9000/org/example/SomeService", ed0.getId());
assertEquals(Arrays.asList("org.apache.cxf.ws"), ed0.getConfigurationTypes());
assertEquals(Arrays.asList("org.example.SomeService"), ed0.getInterfaces());
assertEquals(Arrays.asList("confidentiality"), ed0.getIntents());
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml Wed Jan 13 13:28:38 2010
@@ -34,7 +34,11 @@
<properties>
<topDirectoryLocation>../..</topDirectoryLocation>
- <bundle.import.package>*</bundle.import.package>
+ <bundle.import.package>
+ org.apache.cxf.ws.security.*,
+ org.apache.cxf.ws.policy.*,
+ *
+ </bundle.import.package>
<bundle.export.package>
org.apache.cxf.dosgi.*;version="${pom.version}",
org.osgi.service.remoteserviceadmin;version="${remote.service.admin.interfaces.version}"
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java Wed Jan 13 13:28:38 2010
@@ -20,10 +20,15 @@
import java.util.Dictionary;
import java.util.Hashtable;
+import java.util.logging.Logger;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
import org.apache.cxf.dosgi.dsw.decorator.ServiceDecorator;
import org.apache.cxf.dosgi.dsw.decorator.ServiceDecoratorImpl;
import org.apache.cxf.dosgi.dsw.qos.IntentMap;
+import org.apache.cxf.dosgi.dsw.service.ExportRegistrationImpl;
+import org.apache.cxf.dosgi.dsw.service.ImportRegistrationImpl;
import org.apache.cxf.dosgi.dsw.service.RemoteServiceadminFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -31,17 +36,18 @@
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
-import org.osgi.service.distribution.DistributionProvider;
import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
public class Activator implements BundleActivator, ManagedService {
+ private final static Logger LOG = Logger.getLogger(Activator.class.getName());
+
private static final String CONFIG_SERVICE_PID = "cxf-dsw";
private BundleContext bc;
+ private RemoteServiceadminFactory rsaFactory;
+ private ServiceRegistration rsaFactoryReg;
- private RemoteServiceadminFactory dpService;
-
private ServiceRegistration decoratorReg;
public synchronized void start(BundleContext context) throws Exception {
@@ -50,46 +56,41 @@
bc = context;
// should we have a seperate PID for a find and publish hook ?
- //context.registerService(ManagedService.class.getName(), this, getDefaults());
-
- dpService = registerRemoteServiceAdminService();
+ // context.registerService(ManagedService.class.getName(), this, getDefaults());
+ rsaFactory = registerRemoteServiceAdminService();
/**
* What is this decorator doing ?!?!?! Why as a service ?
*/
decoratorReg = bc.registerService(ServiceDecorator.class.getName(), new ServiceDecoratorImpl(bc),
- null);
-
-
-
+ null);
}
private RemoteServiceadminFactory registerRemoteServiceAdminService() {
- RemoteServiceadminFactory dpService = new RemoteServiceadminFactory(bc);
+ RemoteServiceadminFactory rsaf = new RemoteServiceadminFactory(bc);
Hashtable<String, Object> props = new Hashtable<String, Object>();
// TODO .... RemoteAdminService.XXX
- props.put(DistributionProvider.PRODUCT_NAME, getHeader("Bundle-Name"));
- props.put(DistributionProvider.PRODUCT_VERSION, getHeader("Bundle-Version"));
- props.put(DistributionProvider.VENDOR_NAME, getHeader("Bundle-Vendor"));
+ // props.put(DistributionProvider.PRODUCT_NAME, getHeader("Bundle-Name"));
+ // props.put(DistributionProvider.PRODUCT_VERSION, getHeader("Bundle-Version"));
+ // props.put(DistributionProvider.VENDOR_NAME, getHeader("Bundle-Vendor"));
String[] supportedIntents = getIntentMap().getIntents().keySet().toArray(new String[] {});
String siString = OsgiUtils.formatIntents(supportedIntents);
- props.put(DistributionProvider.SUPPORTED_INTENTS, siString);
- props.put("remote.intents.supported", supportedIntents);
+ props.put("remote.intents.supported", siString);
- // TODO make this a little smarter
+ // // TODO make this a little smarter
String[] supportedConfigs = {
- org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE,
- org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE_OLD,
- org.apache.cxf.dosgi.dsw.Constants.RS_CONFIG_TYPE
+ org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE,
+ org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE_OLD,
+ org.apache.cxf.dosgi.dsw.Constants.RS_CONFIG_TYPE
};
props.put("remote.configs.supported", supportedConfigs);
- bc.registerService(RemoteServiceAdmin.class.getName(), dpService, props);
- return dpService;
+ rsaFactoryReg = bc.registerService(RemoteServiceAdmin.class.getName(), rsaf, props);
+ return rsaf;
}
IntentMap getIntentMap() {
@@ -106,12 +107,33 @@
}
public void stop(BundleContext context) {
- // dpService.shutdown();
-
-
-
+ LOG.fine("RemoteServiceAdmin Implementation is shutting down now");
+ rsaFactoryReg.unregister();
decoratorReg.unregister();
+
+ for (Object o : rsaFactory.getRsaCore().getExportedServices()) {
+ if (o instanceof ExportRegistrationImpl) {
+ LOG.fine("closing Export");
+ ExportRegistrationImpl er = (ExportRegistrationImpl)o;
+ er.close();
+ }
+ }
+
+ for (Object o : rsaFactory.getRsaCore().getImportedEndpoints()) {
+ if (o instanceof ImportRegistrationImpl) {
+ LOG.fine("closing Import");
+ ImportRegistrationImpl er = (ImportRegistrationImpl)o;
+ er.close();
+ }
+ }
+ // shutdown the CXF Bus -> Causes also the shutdown of the embedded HTTP server
+ Bus b = BusFactory.getDefaultBus();
+ if (b != null) {
+ LOG.fine("Shutting down the CXF Bus");
+ b.shutdown(true);
+ }
+
// unregister other registered services (ManagedService + Hooks)
}
@@ -123,7 +145,7 @@
public synchronized void updated(Dictionary props) throws ConfigurationException {
if (props != null && CONFIG_SERVICE_PID.equals(props.get(Constants.SERVICE_PID))) {
- // topManager.updated(props);
+ // topManager.updated(props);
}
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java Wed Jan 13 13:28:38 2010
@@ -35,7 +35,8 @@
import org.apache.cxf.dosgi.dsw.decorator.ServiceDecorator;
import org.apache.cxf.dosgi.dsw.qos.IntentMap;
-import org.apache.cxf.dosgi.dsw.service.ServiceEndpointDescriptionImpl;
+import org.apache.cxf.dosgi.dsw.service.RemoteServiceAdminCore;
+import org.apache.cxf.ws.policy.spring.PolicyNamespaceHandler;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
@@ -45,10 +46,10 @@
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.discovery.ServiceEndpointDescription;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.springframework.context.ApplicationContext;
import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
public final class OsgiUtils {
@@ -79,88 +80,88 @@
private OsgiUtils() {
}
- // Used by PublishHook
- public static ServiceEndpointDescription getRemoteReference(ServiceReference sref, boolean matchAllNames) {
-
- String[] names = (String[])sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
- if (names == null || names.length == 0) {
- return null;
- }
-
- Map<String, Object> userProperties = new HashMap<String, Object>();
- for (String key : sref.getPropertyKeys()) {
- userProperties.put(key, sref.getProperty(key));
- }
- List<ServiceEndpointDescription> srefs = getRemoteReferences(sref.getBundle(), names, userProperties,
- matchAllNames);
- setAdditionalProperties(sref, userProperties);
-
- if (srefs.isEmpty()) {
- return new ServiceEndpointDescriptionImpl(Arrays.asList(names), userProperties);
- }
-
- return srefs.get(0);
- }
-
- @SuppressWarnings("unchecked")
- public static List<ServiceEndpointDescription> getRemoteReferences(Bundle b, String[] names,
- Map<String, Object> userProperties,
- boolean matchAllNames) {
-
- List<Element> references = getAllDescriptionElements(b);
-
- List<ServiceEndpointDescription> srefs = new ArrayList<ServiceEndpointDescription>();
- Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
- for (Element ref : references) {
- List<String> iNames = getProvidedInterfaces(ref.getChildren(PROVIDE_INTERFACE_ELEMENT, ns));
- if (!serviceNamesMatch(names, iNames, matchAllNames)) {
- continue;
- }
-
- Map<String, Object> remoteProps = new HashMap<String, Object>(userProperties);
- addProperties(remoteProps, ref.getChildren(PROPERTY_ELEMENT, ns));
- srefs.add(new ServiceEndpointDescriptionImpl(iNames, remoteProps));
- }
- return srefs;
-
- }
-
- public static ServiceEndpointDescription[] flattenServiceDescription(ServiceEndpointDescription sd) {
- ServiceEndpointDescription[] list = null;
- int interfaceNameCount = sd.getProvidedInterfaces().size();
- if (sd.getProvidedInterfaces() == null || interfaceNameCount <= 1) {
- list = new ServiceEndpointDescription[] {
- sd
- };
- } else {
- String[] iNames = (String[])sd.getProvidedInterfaces().toArray(new String[interfaceNameCount]);
- list = new ServiceEndpointDescription[iNames.length];
- for (int i = 0; i < iNames.length; i++) {
- Map<String, Object> props = excludeProperty(sd.getProperties(),
- Constants.EXPORTED_INTERFACES,
- Constants.EXPORTED_INTERFACES_OLD,
- Constants.RS_PROVIDER_GLOBAL_PROP_KEY,
- Constants.RS_PROVIDER_EXPECTED_PROP_KEY,
- Constants.RS_PROVIDER_PROP_KEY);
-
- String keys[] = props.keySet().toArray(new String[props.size()]);
- for (int j = 0; j < keys.length; j++) {
- int sep = keys[j].indexOf(INTERFACE_SEPARATOR);
- if (sep > -1) {
- String value = (String)props.remove(keys[j]);
- String root = keys[j].substring(0, sep);
- String iface = sep + INTERFACE_SEPARATOR.length() < keys[j].length() ? keys[j]
- .substring(sep + INTERFACE_SEPARATOR.length()) : "";
- if (iNames[i].equals(iface)) {
- props.put(root, value);
- }
- }
- }
- list[i] = new ServiceEndpointDescriptionImpl(iNames[i], props);
- }
- }
- return list;
- }
+// // Used by PublishHook
+// public static ServiceEndpointDescription getRemoteReference(ServiceReference sref, boolean matchAllNames) {
+//
+// String[] names = (String[])sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
+// if (names == null || names.length == 0) {
+// return null;
+// }
+//
+// Map<String, Object> userProperties = new HashMap<String, Object>();
+// for (String key : sref.getPropertyKeys()) {
+// userProperties.put(key, sref.getProperty(key));
+// }
+// List<ServiceEndpointDescription> srefs = getRemoteReferences(sref.getBundle(), names, userProperties,
+// matchAllNames);
+// setAdditionalProperties(sref, userProperties);
+//
+// if (srefs.isEmpty()) {
+// return new ServiceEndpointDescriptionImpl(Arrays.asList(names), userProperties);
+// }
+//
+// return srefs.get(0);
+// }
+
+// @SuppressWarnings("unchecked")
+// public static List<ServiceEndpointDescription> getRemoteReferences(Bundle b, String[] names,
+// Map<String, Object> userProperties,
+// boolean matchAllNames) {
+//
+// List<Element> references = getAllDescriptionElements(b);
+//
+// List<ServiceEndpointDescription> srefs = new ArrayList<ServiceEndpointDescription>();
+// Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
+// for (Element ref : references) {
+// List<String> iNames = getProvidedInterfaces(ref.getChildren(PROVIDE_INTERFACE_ELEMENT, ns));
+// if (!serviceNamesMatch(names, iNames, matchAllNames)) {
+// continue;
+// }
+//
+// Map<String, Object> remoteProps = new HashMap<String, Object>(userProperties);
+// addProperties(remoteProps, ref.getChildren(PROPERTY_ELEMENT, ns));
+// srefs.add(new ServiceEndpointDescriptionImpl(iNames, remoteProps));
+// }
+// return srefs;
+//
+// }
+
+// public static ServiceEndpointDescription[] flattenServiceDescription(ServiceEndpointDescription sd) {
+// ServiceEndpointDescription[] list = null;
+// int interfaceNameCount = sd.getProvidedInterfaces().size();
+// if (sd.getProvidedInterfaces() == null || interfaceNameCount <= 1) {
+// list = new ServiceEndpointDescription[] {
+// sd
+// };
+// } else {
+// String[] iNames = (String[])sd.getProvidedInterfaces().toArray(new String[interfaceNameCount]);
+// list = new ServiceEndpointDescription[iNames.length];
+// for (int i = 0; i < iNames.length; i++) {
+// Map<String, Object> props = excludeProperty(sd.getProperties(),
+// Constants.EXPORTED_INTERFACES,
+// Constants.EXPORTED_INTERFACES_OLD,
+// Constants.RS_PROVIDER_GLOBAL_PROP_KEY,
+// Constants.RS_PROVIDER_EXPECTED_PROP_KEY,
+// Constants.RS_PROVIDER_PROP_KEY);
+//
+// String keys[] = props.keySet().toArray(new String[props.size()]);
+// for (int j = 0; j < keys.length; j++) {
+// int sep = keys[j].indexOf(INTERFACE_SEPARATOR);
+// if (sep > -1) {
+// String value = (String)props.remove(keys[j]);
+// String root = keys[j].substring(0, sep);
+// String iface = sep + INTERFACE_SEPARATOR.length() < keys[j].length() ? keys[j]
+// .substring(sep + INTERFACE_SEPARATOR.length()) : "";
+// if (iNames[i].equals(iface)) {
+// props.put(root, value);
+// }
+// }
+// }
+// list[i] = new ServiceEndpointDescriptionImpl(iNames[i], props);
+// }
+// }
+// return list;
+// }
private static Map<String, Object> excludeProperty(Map properties, String... excludes) {
Collection<String> exList = Arrays.asList(excludes);
@@ -265,24 +266,24 @@
* interfaceNames); } return filter.match(props); }
*/
- public static String[] getProvidedInterfaces(ServiceEndpointDescription sd, String interfaceName) {
-
- int interfaceNameCount = sd.getProvidedInterfaces().size();
- String[] interfaceNames = (String[])sd.getProvidedInterfaces()
- .toArray(new String[interfaceNameCount]);
- if (interfaceName == null) {
- return interfaceNames;
- }
-
- for (String s : interfaceNames) {
- if (s.equals(interfaceName)) {
- return new String[] {
- s
- };
- }
- }
- return null;
- }
+// public static String[] getProvidedInterfaces(ServiceEndpointDescription sd, String interfaceName) {
+//
+// int interfaceNameCount = sd.getProvidedInterfaces().size();
+// String[] interfaceNames = (String[])sd.getProvidedInterfaces()
+// .toArray(new String[interfaceNameCount]);
+// if (interfaceName == null) {
+// return interfaceNames;
+// }
+//
+// for (String s : interfaceNames) {
+// if (s.equals(interfaceName)) {
+// return new String[] {
+// s
+// };
+// }
+// }
+// return null;
+// }
public static Filter createFilter(BundleContext bc, String filterValue) {
@@ -395,15 +396,25 @@
}
try {
+
+ // switch to cxf bundle classloader for spring
+ Thread.currentThread().setContextClassLoader(PolicyNamespaceHandler.class.getClassLoader());
+
LOG.fine("Loading Intent map from "+springIntentLocations);
+ System.out.println("Loading Intent map from "+springIntentLocations);
OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext(springIntentLocations
.toArray(new String[] {}));
ctx.setPublishContextAsService(false);
ctx.setBundleContext(bundleContext);
ctx.refresh();
LOG.fine("application context: " + ctx);
+ System.out.println("application context: " + ctx);
IntentMap im = (IntentMap)ctx.getBean("intentMap");
LOG.fine("retrieved intent map: " + im);
+ System.out.println("retrieved intent map: " + im);
+ // switch back
+ Thread.currentThread().setContextClassLoader(RemoteServiceAdminCore.class.getClassLoader());
+
return im;
} catch (Throwable t) {
LOG.log(Level.WARNING, "Intent map load failed: ", t);
@@ -476,61 +487,61 @@
return null;
}
- @SuppressWarnings("unchecked")
- public static <T> T getProperty(ServiceEndpointDescription sd, String name, Class<T> type, T defaultValue) {
- Object o = sd.getProperty(name);
- if (o == null) {
- return defaultValue;
- }
- return type.isAssignableFrom(o.getClass()) ? (T)o : null;
- }
-
- public static String[] getPublishableInterfaces(ServiceEndpointDescription sd, ServiceReference sref) {
- Collection<String> publishProperty = getMultiValueProperty(sd
- .getProperty(Constants.EXPORTED_INTERFACES));
- if (publishProperty == null) {
- publishProperty = getMultiValueProperty(sd.getProperty(Constants.EXPORTED_INTERFACES_OLD));
- }
-
- String[] actualInterfaces = (String[])sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
- String[] publishableInterfaces = null;
-
- if (actualInterfaces != null && actualInterfaces.length > 0 && publishProperty != null) {
-
- if (publishProperty.size() == 1 && INTERFACE_WILDCARD.equals(publishProperty.iterator().next())) {
- // wildcard indicates all interfaces should be published
- //
- publishableInterfaces = actualInterfaces;
- } else {
- String[] requestedInterfaces;
- if (publishProperty.size() == 0) {
- requestedInterfaces = null;
- } else if (publishProperty.size() == 1) {
- requestedInterfaces = tokenize(publishProperty.iterator().next(), ",");
- } else {
- requestedInterfaces = publishProperty.toArray(new String[publishProperty.size()]);
- }
-
- ArrayList<String> publishableList = new ArrayList<String>();
- for (int i = 0; requestedInterfaces != null && i < requestedInterfaces.length; i++) {
- if (contains(actualInterfaces, requestedInterfaces[i])) {
- publishableList.add(requestedInterfaces[i]);
- } else {
- // simply ignore non-exposed interfaces
- //
- LOG.warning("ignoring publish interface, " + requestedInterfaces[i]
- + ", not exposed by service");
- }
- }
-
- if (publishableList.size() > 0) {
- publishableInterfaces = publishableList.toArray(new String[publishableList.size()]);
- }
- }
- }
-
- return publishableInterfaces;
- }
+// @SuppressWarnings("unchecked")
+// public static <T> T getProperty(ServiceEndpointDescription sd, String name, Class<T> type, T defaultValue) {
+// Object o = sd.getProperty(name);
+// if (o == null) {
+// return defaultValue;
+// }
+// return type.isAssignableFrom(o.getClass()) ? (T)o : null;
+// }
+//
+// public static String[] getPublishableInterfaces(ServiceEndpointDescription sd, ServiceReference sref) {
+// Collection<String> publishProperty = getMultiValueProperty(sd
+// .getProperty(Constants.EXPORTED_INTERFACES));
+// if (publishProperty == null) {
+// publishProperty = getMultiValueProperty(sd.getProperty(Constants.EXPORTED_INTERFACES_OLD));
+// }
+//
+// String[] actualInterfaces = (String[])sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
+// String[] publishableInterfaces = null;
+//
+// if (actualInterfaces != null && actualInterfaces.length > 0 && publishProperty != null) {
+//
+// if (publishProperty.size() == 1 && INTERFACE_WILDCARD.equals(publishProperty.iterator().next())) {
+// // wildcard indicates all interfaces should be published
+// //
+// publishableInterfaces = actualInterfaces;
+// } else {
+// String[] requestedInterfaces;
+// if (publishProperty.size() == 0) {
+// requestedInterfaces = null;
+// } else if (publishProperty.size() == 1) {
+// requestedInterfaces = tokenize(publishProperty.iterator().next(), ",");
+// } else {
+// requestedInterfaces = publishProperty.toArray(new String[publishProperty.size()]);
+// }
+//
+// ArrayList<String> publishableList = new ArrayList<String>();
+// for (int i = 0; requestedInterfaces != null && i < requestedInterfaces.length; i++) {
+// if (contains(actualInterfaces, requestedInterfaces[i])) {
+// publishableList.add(requestedInterfaces[i]);
+// } else {
+// // simply ignore non-exposed interfaces
+// //
+// LOG.warning("ignoring publish interface, " + requestedInterfaces[i]
+// + ", not exposed by service");
+// }
+// }
+//
+// if (publishableList.size() > 0) {
+// publishableInterfaces = publishableList.toArray(new String[publishableList.size()]);
+// }
+// }
+// }
+//
+// return publishableInterfaces;
+// }
private static String[] tokenize(String str, String delim) {
StringTokenizer tokenizer = new StringTokenizer(str, delim);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java Wed Jan 13 13:28:38 2010
@@ -42,8 +42,7 @@
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.osgi.framework.BundleContext;
-
-import static org.osgi.service.discovery.ServicePublication.ENDPOINT_LOCATION;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
public abstract class AbstractPojoConfigurationTypeHandler extends AbstractConfigurationHandler {
private static final Logger LOG = Logger.getLogger(AbstractPojoConfigurationTypeHandler.class.getName());
@@ -228,7 +227,7 @@
protected void addAddressProperty(Map props, String address) {
if (props != null) {
- props.put(ENDPOINT_LOCATION, address);
+ props.put(RemoteConstants.ENDPOINT_ID, address);
}
}
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java Wed Jan 13 13:28:38 2010
@@ -108,6 +108,8 @@
copyEndpointProperties(sd, endpointProps);
+
+
String[] sa = new String[1];
sa[0] = iClass.getName();
endpointProps.put(org.osgi.framework.Constants.OBJECTCLASS, sa);
@@ -122,7 +124,9 @@
endpointProps.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, Constants.WS_CONFIG_TYPE);
endpointProps.put(RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + sa[0], OsgiUtils.getVersion(iClass, dswContext));
endpointProps.put(RemoteConstants.SERVICE_INTENTS, Utils.getAllIntentsCombined(sd));
-
+ // make sure that the Endpoint contains the address that was actualy used
+ addAddressProperty(endpointProps, address);
+
DataBinding databinding;
String dataBindingImpl = (String)exportRegistration.getExportedService()
.getProperty(Constants.WS_DATABINDING_PROP_KEY);
@@ -146,7 +150,7 @@
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
Server server = factory.create();
- endpointProps.put(RemoteConstants.ENDPOINT_ID, address);
+
exportRegistration.setServer(server);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java Wed Jan 13 13:28:38 2010
@@ -19,11 +19,14 @@
package org.apache.cxf.dosgi.dsw.service;
import java.util.Arrays;
+import java.util.Dictionary;
import java.util.Properties;
+import java.util.logging.Logger;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
@@ -32,6 +35,8 @@
public class EventAdminHelper {
+ private final static Logger LOG = Logger.getLogger(EventAdminHelper.class.getName());
+
private BundleContext bctx;
public EventAdminHelper(BundleContext bc) {
@@ -41,13 +46,22 @@
private Event createEvent(Properties p, String t) {
String topic = "org/osgi/service/remoteserviceadmin/" + t;
- Properties props = new Properties(p);
+ Dictionary props = p;
props.put("bundle", bctx.getBundle());
- props.put("bundle-id", bctx.getBundle().getBundleId());
- props.put("bundle-symbolicname", bctx.getBundle().getSymbolicName());
+ props.put("bundle.id", bctx.getBundle().getBundleId());
+ props.put("bundle.symbolicname", bctx.getBundle().getSymbolicName());
// FIXME is this correct?
- setIfNotNull(props, "bundle-version", bctx.getBundle().getHeaders("Bundle-Version"));
+
+ String version = (String)bctx.getBundle().getHeaders().get("Bundle-Version");
+
+ Version v;
+ if(version!=null)
+ v = new Version(version);
+ else
+ v = Version.emptyVersion;
+
+ setIfNotNull(props, "bundle.version", v);
return new Event(topic, props);
}
@@ -56,26 +70,25 @@
String topic = Utils.remoteServiceAdminEventTypeToString(rsae.getType());
+ Properties props = new Properties();
+ setIfNotNull(props, "cause", rsae.getException());
+
+
EndpointDescription epd = null;
if (rsae.getImportReference()!= null) {
- epd = rsae.getImportReference().getImportedEndpoint();
+ epd = ((ImportReferenceImpl)rsae.getImportReference()).getImportedEndpointAlways();
+ setIfNotNull(props, "import.registration", epd);
} else if (rsae.getExportReference() != null) {
- epd = rsae.getExportReference().getExportedEndpoint();
+ epd = ((ExportReferenceImpl)rsae.getExportReference()).getExportedEndpointAlways();
+ setIfNotNull(props, "export.registration", epd);
}
- Properties props = new Properties();
- setIfNotNull(props, "cause", rsae.getException());
-//FIXME !!!!!!!!!!!!!
-// setIfNotNull(props, "import.registration", rsae.getImportRegistration());
-// setIfNotNull(props, "export.registration", rsae.getExportRegistration());
if (epd != null) {
- setIfNotNull(props, "service.remote.id", epd.getRemoteServiceID());
- setIfNotNull(props, "service.remote.uuid", epd.getRemoteFrameworkUUID());
- setIfNotNull(props, "service.remote.uri", epd.getRemoteID());
- // FIXME: correct ?!?
+ setIfNotNull(props, "service.remote.id", epd.getServiceId());
+ setIfNotNull(props, "service.remote.uuid", epd.getFrameworkUUID());
+ setIfNotNull(props, "service.remote.uri", epd.getId());
setIfNotNull(props, "objectClass", epd.getInterfaces().toArray());
setIfNotNull(props, "service.imported.configs", epd.getConfigurationTypes());
- setIfNotNull(props, "service.imported.configs", epd.getConfigurationTypes());
}
props.put("timestamp", System.currentTimeMillis());
props.put("event", rsae);
@@ -84,6 +97,7 @@
EventAdmin[] eas = getEventAdmins();
if (eas != null) {
+ LOG.fine("Publishing event to "+eas.length+" EventAdmins; Topic:["+topic+"]");
for (EventAdmin eventAdmin : eas) {
eventAdmin.postEvent(ev);
}
@@ -91,7 +105,7 @@
}
- private void setIfNotNull(Properties props, String key, Object o) {
+ private void setIfNotNull(Dictionary props, String key, Object o) {
if (o != null)
props.put(key, o);
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java Wed Jan 13 13:28:38 2010
@@ -38,4 +38,8 @@
return exportRegistartion.getExportedService();
}
+ protected EndpointDescription getExportedEndpointAlways() {
+ return exportRegistartion.getEndpointDescriptionAlways();
+ }
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java Wed Jan 13 13:28:38 2010
@@ -22,13 +22,21 @@
import java.util.Set;
import java.util.logging.Logger;
+import org.apache.commons.logging.Log;
import org.apache.cxf.dosgi.dsw.handlers.IntentUnsatifiedException;
import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.ServerFactoryBean;
import org.mortbay.jetty.servlet.PathMap.Entry;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.ExportReference;
import org.osgi.service.remoteserviceadmin.ExportRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -50,6 +58,8 @@
private ExportReference exportReference;
+ private ServiceTracker serviceTracker;
+
// provide a clone of the provided exp.Reg that is linked to this instance
public ExportRegistrationImpl(ExportRegistrationImpl exportRegistration) {
@@ -57,7 +67,7 @@
serviceReference = parent.getExportedService();
endpointDescription = parent.getEndpointDescription();
exception = parent.getException();
-
+ rsaCore = parent.getRsaCore();
parent.instanceAdded();
}
@@ -77,6 +87,8 @@
return;
closed = true;
+ rsaCore.removeExportRegistration(this);
+
parent.instanceClosed();
}
@@ -88,7 +100,7 @@
LOG.fine("really closing ExportRegistartion now! ");
- rsaCore.removeExportRegistration(this);
+
if (server != null) {
// FIXME: is this done like this ?
@@ -97,6 +109,15 @@
}
}
+ private void closeAll() {
+ if(parent!=this){
+ parent.closeAll();
+ return;
+ }
+ // FIXME: close all clients !!!!
+ close();
+ }
+
public EndpointDescription getEndpointDescription() {
if (!closed)
return endpointDescription;
@@ -166,4 +187,62 @@
}
return exportReference;
}
+
+ protected EndpointDescription getEndpointDescriptionAlways() {
+ return endpointDescription;
+ }
+
+ /**
+ * Start the service tracker that monitors the osgi service that
+ * is exported by this exportRegistration
+ * */
+ public void startServiceTracker(BundleContext bctx) {
+
+ // only the parent should do this
+ if(parent!=this){
+ parent.startServiceTracker(bctx);
+ return;
+ }
+
+ // do it only once
+ if(serviceTracker!=null){
+ return;
+ }
+
+ Filter f;
+ final Long sid = (Long)serviceReference.getProperty(Constants.SERVICE_ID);
+ try {
+ f = bctx.createFilter("("+Constants.SERVICE_ID+"="+sid+")");
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ LOG.warning("Service tracker could not be started. The service will not be automatically unexported.");
+ return;
+ }
+ serviceTracker = new ServiceTracker(bctx, f, new ServiceTrackerCustomizer() {
+
+ public void removedService(ServiceReference sr, Object s) {
+ LOG.info("Service ["+sid+"] has ben unregistered: Removing service export");
+ close();
+ }
+
+ public void modifiedService(ServiceReference sr, Object s) {
+ // FIXME:
+ LOG.warning("Service modifications after the service is exported are currently not supported. The export is not modified!");
+ }
+
+ public Object addingService(ServiceReference sr) {
+ return sr;
+ }
+ });
+ serviceTracker.open();
+ }
+
+ public void setRsaCore(RemoteServiceAdminCore rsaCore) {
+ this.rsaCore = rsaCore;
+ }
+
+ public RemoteServiceAdminCore getRsaCore() {
+ return rsaCore;
+ }
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportReferenceImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportReferenceImpl.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportReferenceImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportReferenceImpl.java Wed Jan 13 13:28:38 2010
@@ -38,4 +38,8 @@
return importRegistration.getImportedService();
}
+ public EndpointDescription getImportedEndpointAlways() {
+ return importRegistration.getImportedEndpointAlways();
+ }
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java Wed Jan 13 13:28:38 2010
@@ -95,7 +95,7 @@
return;
closed = true;
-
+ rsaCore.removeImportRegistration(this);
parent.instanceClosed(this);
}
@@ -110,7 +110,6 @@
LOG.fine("really closing ImportRegistartion now! ");
- rsaCore.removeImportRegistration(this);
if (clientServiceFactory != null)
clientServiceFactory.setCloseable(true);
if (importedService != null)
@@ -146,6 +145,9 @@
public EndpointDescription getImportedEndpointDescription() {
if (isFailure())
return null;
+ if(closed)
+ return null;
+
return importedEndpoint;
}
@@ -212,4 +214,8 @@
return importReference;
}
+ public EndpointDescription getImportedEndpointAlways() {
+ return importedEndpoint;
+ }
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java Wed Jan 13 13:28:38 2010
@@ -50,8 +50,9 @@
private Logger LOG = Logger.getLogger(RemoteServiceAdminCore.class.getName());
private LinkedHashMap<ServiceReference, Collection<ExportRegistrationImpl>> exportedServices = new LinkedHashMap<ServiceReference, Collection<ExportRegistrationImpl>>();
- private LinkedHashMap<EndpointDescription, ImportRegistrationImpl> importedServices = new LinkedHashMap<EndpointDescription, ImportRegistrationImpl>();
-
+ private LinkedHashMap<EndpointDescription, Collection<ImportRegistrationImpl>> importedServices = new LinkedHashMap<EndpointDescription, Collection<ImportRegistrationImpl>>();
+
+
private BundleContext bctx;
private EventProducer eventProducer;
@@ -60,8 +61,8 @@
private volatile String defaultPort;
private volatile String defaultHost;
-
- private static List<String> supportedConfigurationTypes = new ArrayList<String>();
+ // protected because of tests
+ protected static List<String> supportedConfigurationTypes = new ArrayList<String>();
static {
supportedConfigurationTypes.add(Constants.WSDL_CONFIG_TYPE);
supportedConfigurationTypes.add(Constants.RS_CONFIG_TYPE);
@@ -74,37 +75,46 @@
eventProducer = new EventProducer(bctx);
}
- public List exportService(ServiceReference sref, Map additionalProperties)
+ public List exportService(ServiceReference serviceReference, Map additionalProperties)
throws IllegalArgumentException, UnsupportedOperationException {
- LOG.fine("RemoteServiceAdmin: exportService: " + sref.getClass().getName());
+ LOG.fine("RemoteServiceAdmin: exportService: " + serviceReference.getClass().getName());
synchronized (exportedServices) {
// check if it is already exported ....
- if (exportedServices.containsKey(sref)) {
- LOG.fine("already exported ... " + sref.getClass().getName());
- Collection<ExportRegistrationImpl> regs = exportedServices.get(sref);
+ if (exportedServices.containsKey(serviceReference)) {
+ LOG.fine("already exported ... " + serviceReference.getClass().getName());
+ Collection<ExportRegistrationImpl> regs = exportedServices.get(serviceReference);
+ List<EndpointDescription> copiedEndpoints = new ArrayList<EndpointDescription>();
+
// / create a new list with copies of the exportRegistrations
List<ExportRegistrationImpl> copy = new ArrayList<ExportRegistrationImpl>(regs.size());
for (ExportRegistrationImpl exportRegistration : regs) {
- copy.add(new ExportRegistrationImpl(exportRegistration));
+ // create one copy for each distinct endpoint description
+ if(!copiedEndpoints.contains(exportRegistration.getEndpointDescription())){
+ copiedEndpoints.add(exportRegistration.getEndpointDescription());
+ copy.add(new ExportRegistrationImpl(exportRegistration));
+ }
}
+
+ regs.addAll(copy);
+
eventProducer.publishNotifcation(copy);
return copy;
}
- if (isCreatedByThisRSA(sref)) {
- LOG.fine("proxy provided by this bundle ... " + sref.getClass().getName());
+ if (isCreatedByThisRSA(serviceReference)) {
+ LOG.fine("proxy provided by this bundle ... " + serviceReference.getClass().getName());
return null;
}
Properties serviceProperties = new Properties();
{// gather EventProducerproperties from sRef
- String[] keys = sref.getPropertyKeys();
+ String[] keys = serviceReference.getPropertyKeys();
for (String k : keys) {
- serviceProperties.put(k, sref.getProperty(k));
+ serviceProperties.put(k, serviceReference.getProperty(k));
}
}
@@ -138,6 +148,8 @@
{ // TODO: Determine if the required intents can be provided by the RSA ....
// if not return null
+ if(requiredIntents!=null && requiredIntents.length>0)
+ return null;
}
@@ -178,23 +190,7 @@
return null;
}
- List<String> configurationTypes = new ArrayList<String>();
- {// determine which configuration types should be used / if the requested are supported
- String[] requestedConfigurationTypes = Utils.normalizeStringPlus(serviceProperties
- .get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
- if (requestedConfigurationTypes == null || requestedConfigurationTypes.length == 0) {
- // add all supported
- configurationTypes.addAll(supportedConfigurationTypes);
- } else {
- for (String rct : requestedConfigurationTypes) {
- if (supportedConfigurationTypes.contains(rct)) {
- // this RSA supports this requested type ...
- configurationTypes.add(rct);
- }
- }
- }
-
- }
+ List<String> configurationTypes = determineConfigurationTypes(serviceProperties);
LOG.info("configuration types selected for export: " + configurationTypes);
@@ -212,14 +208,14 @@
+ " with configuration types " + configurationTypes);
// create initial ExportRegistartion
- ExportRegistrationImpl expReg = new ExportRegistrationImpl(sref, null, this);
+ ExportRegistrationImpl expReg = new ExportRegistrationImpl(serviceReference, null, this);
exportRegs.put(iface, expReg);
}
// enlist initial export Registrations in global list of exprtRegistrations
- exportedServices.put(sref, exportRegs.values());
+ exportedServices.put(serviceReference, new ArrayList<ExportRegistrationImpl>(exportRegs.values()));
// FIXME: move out of synchronized ... -> blocks until publication is finished
for (String iface : interfaces) {
@@ -228,8 +224,8 @@
ExportRegistrationImpl exportRegistration = exportRegs.get(iface);
ConfigurationTypeHandler handler = getHandler(configurationTypes, serviceProperties,
getHandlerProperties());
- Object serviceObject = bctx.getService(sref);
- BundleContext callingContext = sref.getBundle().getBundleContext();
+ Object serviceObject = bctx.getService(serviceReference);
+ BundleContext callingContext = serviceReference.getBundle().getBundleContext();
if (handler == null) {
return null;
@@ -247,6 +243,8 @@
interfaceClass, serviceObject);
LOG.info("created server for interface " + iface);
+ exportRegistration.startServiceTracker(bctx);
+
}
}
@@ -258,6 +256,30 @@
}
}
+ protected List<String> determineConfigurationTypes(Properties serviceProperties) {
+
+ List<String> configurationTypes = new ArrayList<String>();
+
+ {// determine which configuration types should be used / if the requested are supported
+ String[] requestedConfigurationTypes = Utils.normalizeStringPlus(serviceProperties
+ .get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
+ if (requestedConfigurationTypes == null || requestedConfigurationTypes.length == 0) {
+ // add all supported
+ configurationTypes.addAll(supportedConfigurationTypes);
+ } else {
+ for (String rct : requestedConfigurationTypes) {
+ if (supportedConfigurationTypes.contains(rct)) {
+ // this RSA supports this requested type ...
+ configurationTypes.add(rct);
+ }
+ }
+ }
+
+ }
+
+ return configurationTypes;
+ }
+
private boolean isCreatedByThisRSA(ServiceReference sref) {
return sref.getBundle().equals(bctx.getBundle());
}
@@ -274,7 +296,11 @@
public Collection getImportedEndpoints() {
synchronized (importedServices) {
- return Collections.unmodifiableCollection(importedServices.values());
+ List<ImportRegistrationImpl> irs = new ArrayList<ImportRegistrationImpl>();
+ for (Collection<ImportRegistrationImpl> irl : importedServices.values()) {
+ irs.addAll(irl);
+ }
+ return Collections.unmodifiableCollection(irs);
}
}
@@ -312,8 +338,10 @@
LOG.info("importService() Endpoint: " + endpoint.getProperties());
synchronized (importedServices) {
- if (importedServices.containsKey(endpoint)) {
- ImportRegistrationImpl ir = new ImportRegistrationImpl(importedServices.get(endpoint));
+ if (importedServices.containsKey(endpoint) && importedServices.get(endpoint).size()>0) {
+ Collection<ImportRegistrationImpl> imRegs = importedServices.get(endpoint);
+ ImportRegistrationImpl irParent = imRegs.iterator().next();
+ ImportRegistrationImpl ir = new ImportRegistrationImpl(irParent);
eventProducer.publishNotifcation(ir);
return ir;
}
@@ -362,7 +390,12 @@
ImportRegistrationImpl imReg = new ImportRegistrationImpl(endpoint,this);
proxifyMatchingInterface(matchingInterfaces.get(0), imReg, handler, bctx);
- importedServices.put(endpoint, imReg);
+ Collection<ImportRegistrationImpl> imRegs = importedServices.get(endpoint);
+ if(imRegs==null){
+ imRegs = new ArrayList<ImportRegistrationImpl>();
+ importedServices.put(endpoint,imRegs);
+ }
+ imRegs.add(imReg);
eventProducer.publishNotifcation(imReg);
return imReg;
} else {
@@ -442,9 +475,21 @@
protected void removeImportRegistration(ImportRegistrationImpl iri){
synchronized (importedServices) {
LOG.finest("Removing importRegistration "+iri);
- if(importedServices.remove(iri.getImportedEndpointDescription())==null){
- LOG.severe("An importRegistartion couldn't be removed from the internal management structure -> structure is inconsistent !!");
+
+ Collection<ImportRegistrationImpl> imRegs = importedServices.get(iri.getImportedEndpointAlways());
+ if (imRegs.contains(iri)) {
+ imRegs.remove(iri);
+ } else {
+ LOG.severe("An importRegistartion was intended to be removed form internal management structure but couldn't be found in it !! ");
}
+ if (imRegs.size() == 0) {
+ importedServices.remove(iri.getImportedEndpointAlways());
+ }
+
+// if(importedServices.remove(iri.getImportedEndpointDescription())==null){
+// LOG.severe("An importRegistartion couldn't be removed from the internal management structure -> structure is inconsistent !!");
+// }
+
eventProducer.notifyRemoval(iri);
}
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceadminFactory.java Wed Jan 13 13:28:38 2010
@@ -57,4 +57,12 @@
}
}
+ public void setRsaCore(RemoteServiceAdminCore rsaCore) {
+ this.rsaCore = rsaCore;
+ }
+
+ public RemoteServiceAdminCore getRsaCore() {
+ return rsaCore;
+ }
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java?rev=898744&r1=898743&r2=898744&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java Wed Jan 13 13:28:38 2010
@@ -30,9 +30,7 @@
import junit.framework.TestCase;
-import org.apache.cxf.dosgi.dsw.decorator.ServiceDecorator;
import org.easymock.EasyMock;
-import org.easymock.IAnswer;
import org.easymock.IMocksControl;
import org.jdom.Element;
import org.jdom.Namespace;
@@ -40,7 +38,6 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
-import org.osgi.service.discovery.ServiceEndpointDescription;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
@@ -48,192 +45,192 @@
public class OsgiUtilsTest extends TestCase {
- public void testGetPublishableInterfacesAll() throws Exception {
- doTestGetPublishableInterfaces("foo,bar,snafu",
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "bar", "snafu"});
- }
-
- public void testGetPublishableInterfacesAllStringArray() throws Exception {
- doTestGetPublishableInterfaces(new String[] {"foo", "bar", "snafu"},
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "bar", "snafu"});
- }
-
- public void testGetPublishableInterfacesAllCollection() throws Exception {
- doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "snafu"),
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "bar", "snafu"});
- }
-
- public void testGetPublishableInterfacesSubset() throws Exception {
- doTestGetPublishableInterfaces("foo,snafu",
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "snafu"});
- }
-
- public void testGetPublishableInterfacesSubsetStringArray() throws Exception {
- doTestGetPublishableInterfaces(new String[] {"foo", "snafu"},
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "snafu"});
- }
-
- public void testGetPublishableInterfacesSubsetCollection() throws Exception {
- doTestGetPublishableInterfaces(Arrays.asList("foo", "snafu"),
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "snafu"});
- }
-
- public void testGetPublishableInterfacesSuperset() throws Exception {
- doTestGetPublishableInterfaces("foo,bar,snafu",
- new String[] {"snafu", "bar"},
- new String[] {"bar", "snafu"});
- }
-
- public void testGetPublishableInterfacesSupersetStringArray() throws Exception {
- doTestGetPublishableInterfaces(new String[] {"foo", "bar", "snafu"},
- new String[] {"snafu", "bar"},
- new String[] {"bar", "snafu"});
- }
-
- public void testGetPublishableInterfacesSupersetCollection() throws Exception {
- doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "snafu"),
- new String[] {"snafu", "bar"},
- new String[] {"bar", "snafu"});
- }
-
- public void testGetPublishableInterfacesNonexistant() throws Exception {
- doTestGetPublishableInterfaces("foo,bar,tofu",
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "bar"});
- }
-
- public void testGetPublishableInterfacesNonexistantStringArray() throws Exception {
- doTestGetPublishableInterfaces(new String[] {"foo", "bar", "tofu"},
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "bar"});
- }
-
- public void testGetPublishableInterfacesNonexistantCollection() throws Exception {
- doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "tofu"),
- new String[] {"snafu", "foo", "bar"},
- new String[] {"foo", "bar"});
- }
-
- public void testGetPublishableInterfacesWildcarded() throws Exception {
- doTestGetPublishableInterfaces("*",
- new String[] {"snafu", "foo", "bar"},
- new String[] {"snafu", "foo", "bar"});
- }
-
- public void testGetPublishableInterfacesWildcardedInArray() throws Exception {
- doTestGetPublishableInterfaces(Arrays.asList("*"),
- new String[] {"snafu", "foo", "bar"},
- new String[] {"snafu", "foo", "bar"});
- }
-
- public void doTestGetPublishableInterfaces(Object requested,
- String[] actual,
- String[] expected)
- throws Exception {
- ServiceEndpointDescription sd =
- EasyMock.createMock(ServiceEndpointDescription.class);
- ServiceReference sref = EasyMock.createMock(ServiceReference.class);
- EasyMock.expect(sd.getProperty("service.exported.interfaces")).andReturn(requested);
- EasyMock.expect(sd.getProperty("osgi.remote.interfaces")).andReturn(null);
- EasyMock.expect(sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS)).andReturn(actual);
- EasyMock.replay(sd);
- EasyMock.replay(sref);
-
- String[] ret = OsgiUtils.getPublishableInterfaces(sd, sref);
-
- assertNotNull(ret);
- assertEquals(expected.length, ret.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(expected[i], ret[i]);
- }
-
- EasyMock.verify();
- }
-
- public void testGetRemoteReferencesFromRegistrationProperties() throws Exception {
- final Map<String, Object> props = new HashMap<String, Object>();
- props.put(org.osgi.framework.Constants.OBJECTCLASS, new String [] {"myClass"});
- props.put("osgi.remote.interfaces", "*");
- props.put(Constants.WS_DATABINDING_PROP_KEY, "jaxb");
-
- BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.expect(bc.getServiceReferences(ServiceDecorator.class.getName(), null)).
- andReturn(null).anyTimes();
- EasyMock.replay(bc);
-
- Bundle b = EasyMock.createNiceMock(Bundle.class);
- EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
- EasyMock.replay(b);
-
- ServiceReference sr = EasyMock.createMock(ServiceReference.class);
- // set behaviour for getPropertyKeys() and getProperty() based on the map above.
- EasyMock.expect(sr.getPropertyKeys()).
- andReturn(props.keySet().toArray(new String [] {})).anyTimes();
- EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).
- andAnswer(new IAnswer<Object>() {
- public Object answer() throws Throwable {
- return props.get(EasyMock.getCurrentArguments()[0]);
- }
- }).anyTimes();
- EasyMock.expect(sr.getBundle()).andReturn(b).anyTimes();
- EasyMock.replay(sr);
-
- // Actual test starts here
- ServiceEndpointDescription sd = OsgiUtils.getRemoteReference(sr, true);
- assertEquals("*", sd.getProperties().get("osgi.remote.interfaces"));
- assertEquals("jaxb", sd.getProperties().get(Constants.WS_DATABINDING_PROP_KEY));
-
- EasyMock.verify(sr);
- }
-
- public void testSetAdditionalDecoratorProperties() throws Exception {
- final Map<String, Object> props = new HashMap<String, Object>();
- props.put(org.osgi.framework.Constants.OBJECTCLASS, new String [] {"myClass"});
-
- ServiceDecorator decorator = new ServiceDecorator() {
- public void decorate(ServiceReference sref, Map<String, Object> properties) {
- properties.put("osgi.remote.interfaces", "*");
- }
- };
-
- ServiceReference decoratorRef = EasyMock.createMock(ServiceReference.class);
- EasyMock.replay(decoratorRef);
-
- BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.expect(bc.getServiceReferences(ServiceDecorator.class.getName(), null)).
- andReturn(new ServiceReference [] {decoratorRef}).anyTimes();
- EasyMock.expect(bc.getService(decoratorRef)).andReturn(decorator).anyTimes();
- EasyMock.replay(bc);
-
- Bundle b = EasyMock.createNiceMock(Bundle.class);
- EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
- EasyMock.replay(b);
-
- ServiceReference sr = EasyMock.createMock(ServiceReference.class);
- // set behaviour for getPropertyKeys() and getProperty() based on the map above.
- EasyMock.expect(sr.getPropertyKeys()).
- andReturn(props.keySet().toArray(new String [] {})).anyTimes();
- EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).
- andAnswer(new IAnswer<Object>() {
- public Object answer() throws Throwable {
- return props.get(EasyMock.getCurrentArguments()[0]);
- }
- }).anyTimes();
- EasyMock.expect(sr.getBundle()).andReturn(b).anyTimes();
- EasyMock.replay(sr);
-
- // Actual test starts here
- ServiceEndpointDescription sd = OsgiUtils.getRemoteReference(sr, true);
- assertEquals("*", sd.getProperties().get("osgi.remote.interfaces"));
-
- EasyMock.verify(sr);
- }
+// public void testGetPublishableInterfacesAll() throws Exception {
+// doTestGetPublishableInterfaces("foo,bar,snafu",
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "bar", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesAllStringArray() throws Exception {
+// doTestGetPublishableInterfaces(new String[] {"foo", "bar", "snafu"},
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "bar", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesAllCollection() throws Exception {
+// doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "snafu"),
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "bar", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesSubset() throws Exception {
+// doTestGetPublishableInterfaces("foo,snafu",
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesSubsetStringArray() throws Exception {
+// doTestGetPublishableInterfaces(new String[] {"foo", "snafu"},
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesSubsetCollection() throws Exception {
+// doTestGetPublishableInterfaces(Arrays.asList("foo", "snafu"),
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesSuperset() throws Exception {
+// doTestGetPublishableInterfaces("foo,bar,snafu",
+// new String[] {"snafu", "bar"},
+// new String[] {"bar", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesSupersetStringArray() throws Exception {
+// doTestGetPublishableInterfaces(new String[] {"foo", "bar", "snafu"},
+// new String[] {"snafu", "bar"},
+// new String[] {"bar", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesSupersetCollection() throws Exception {
+// doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "snafu"),
+// new String[] {"snafu", "bar"},
+// new String[] {"bar", "snafu"});
+// }
+//
+// public void testGetPublishableInterfacesNonexistant() throws Exception {
+// doTestGetPublishableInterfaces("foo,bar,tofu",
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "bar"});
+// }
+//
+// public void testGetPublishableInterfacesNonexistantStringArray() throws Exception {
+// doTestGetPublishableInterfaces(new String[] {"foo", "bar", "tofu"},
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "bar"});
+// }
+//
+// public void testGetPublishableInterfacesNonexistantCollection() throws Exception {
+// doTestGetPublishableInterfaces(Arrays.asList("foo", "bar", "tofu"),
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"foo", "bar"});
+// }
+//
+// public void testGetPublishableInterfacesWildcarded() throws Exception {
+// doTestGetPublishableInterfaces("*",
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"snafu", "foo", "bar"});
+// }
+//
+// public void testGetPublishableInterfacesWildcardedInArray() throws Exception {
+// doTestGetPublishableInterfaces(Arrays.asList("*"),
+// new String[] {"snafu", "foo", "bar"},
+// new String[] {"snafu", "foo", "bar"});
+// }
+
+// public void doTestGetPublishableInterfaces(Object requested,
+// String[] actual,
+// String[] expected)
+// throws Exception {
+// ServiceEndpointDescription sd =
+// EasyMock.createMock(ServiceEndpointDescription.class);
+// ServiceReference sref = EasyMock.createMock(ServiceReference.class);
+// EasyMock.expect(sd.getProperty("service.exported.interfaces")).andReturn(requested);
+// EasyMock.expect(sd.getProperty("osgi.remote.interfaces")).andReturn(null);
+// EasyMock.expect(sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS)).andReturn(actual);
+// EasyMock.replay(sd);
+// EasyMock.replay(sref);
+//
+// String[] ret = OsgiUtils.getPublishableInterfaces(sd, sref);
+//
+// assertNotNull(ret);
+// assertEquals(expected.length, ret.length);
+// for (int i = 0; i < expected.length; i++) {
+// assertEquals(expected[i], ret[i]);
+// }
+//
+// EasyMock.verify();
+// }
+
+// public void testGetRemoteReferencesFromRegistrationProperties() throws Exception {
+// final Map<String, Object> props = new HashMap<String, Object>();
+// props.put(org.osgi.framework.Constants.OBJECTCLASS, new String [] {"myClass"});
+// props.put("osgi.remote.interfaces", "*");
+// props.put(Constants.WS_DATABINDING_PROP_KEY, "jaxb");
+//
+// BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+// EasyMock.expect(bc.getServiceReferences(ServiceDecorator.class.getName(), null)).
+// andReturn(null).anyTimes();
+// EasyMock.replay(bc);
+//
+// Bundle b = EasyMock.createNiceMock(Bundle.class);
+// EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
+// EasyMock.replay(b);
+//
+// ServiceReference sr = EasyMock.createMock(ServiceReference.class);
+// // set behaviour for getPropertyKeys() and getProperty() based on the map above.
+// EasyMock.expect(sr.getPropertyKeys()).
+// andReturn(props.keySet().toArray(new String [] {})).anyTimes();
+// EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).
+// andAnswer(new IAnswer<Object>() {
+// public Object answer() throws Throwable {
+// return props.get(EasyMock.getCurrentArguments()[0]);
+// }
+// }).anyTimes();
+// EasyMock.expect(sr.getBundle()).andReturn(b).anyTimes();
+// EasyMock.replay(sr);
+//
+// // Actual test starts here
+// ServiceEndpointDescription sd = OsgiUtils.getRemoteReference(sr, true);
+// assertEquals("*", sd.getProperties().get("osgi.remote.interfaces"));
+// assertEquals("jaxb", sd.getProperties().get(Constants.WS_DATABINDING_PROP_KEY));
+//
+// EasyMock.verify(sr);
+// }
+
+// public void testSetAdditionalDecoratorProperties() throws Exception {
+// final Map<String, Object> props = new HashMap<String, Object>();
+// props.put(org.osgi.framework.Constants.OBJECTCLASS, new String [] {"myClass"});
+//
+// ServiceDecorator decorator = new ServiceDecorator() {
+// public void decorate(ServiceReference sref, Map<String, Object> properties) {
+// properties.put("osgi.remote.interfaces", "*");
+// }
+// };
+//
+// ServiceReference decoratorRef = EasyMock.createMock(ServiceReference.class);
+// EasyMock.replay(decoratorRef);
+//
+// BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+// EasyMock.expect(bc.getServiceReferences(ServiceDecorator.class.getName(), null)).
+// andReturn(new ServiceReference [] {decoratorRef}).anyTimes();
+// EasyMock.expect(bc.getService(decoratorRef)).andReturn(decorator).anyTimes();
+// EasyMock.replay(bc);
+//
+// Bundle b = EasyMock.createNiceMock(Bundle.class);
+// EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
+// EasyMock.replay(b);
+//
+// ServiceReference sr = EasyMock.createMock(ServiceReference.class);
+// // set behaviour for getPropertyKeys() and getProperty() based on the map above.
+// EasyMock.expect(sr.getPropertyKeys()).
+// andReturn(props.keySet().toArray(new String [] {})).anyTimes();
+// EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).
+// andAnswer(new IAnswer<Object>() {
+// public Object answer() throws Throwable {
+// return props.get(EasyMock.getCurrentArguments()[0]);
+// }
+// }).anyTimes();
+// EasyMock.expect(sr.getBundle()).andReturn(b).anyTimes();
+// EasyMock.replay(sr);
+//
+// // Actual test starts here
+// ServiceEndpointDescription sd = OsgiUtils.getRemoteReference(sr, true);
+// assertEquals("*", sd.getProperties().get("osgi.remote.interfaces"));
+//
+// EasyMock.verify(sr);
+// }
public void testNoIntentMap() {
Bundle b = EasyMock.createNiceMock(Bundle.class);