Author: davidb
Date: Sun Jan 10 17:30:43 2010
New Revision: 897664
URL: http://svn.apache.org/viewvc?rev=897664&view=rev
Log:
Support for 'legacy' remote-service.xml files.
Additional tests.
Added:
cxf/dosgi/trunk/discovery/local/src/test/resources/sd.xml (with props)
cxf/dosgi/trunk/discovery/local/src/test/resources/sd2.xml (with props)
Removed:
cxf/dosgi/trunk/discovery/local/src/test/resources/rs1.xml
cxf/dosgi/trunk/discovery/local/src/test/resources/rs2.xml
cxf/dosgi/trunk/discovery/local/src/test/resources/rs_a.xml
cxf/dosgi/trunk/discovery/local/src/test/resources/rs_b.xml
cxf/dosgi/trunk/discovery/local/src/test/resources/rs_c.xml
cxf/dosgi/trunk/discovery/local/src/test/resources/rs_d.xml
cxf/dosgi/trunk/discovery/local/src/test/resources/rs_e.xml
cxf/dosgi/trunk/discovery/local/src/test/resources/rs_f.xml
Modified:
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtilsTest.java
Modified:
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java?rev=897664&r1=897663&r2=897664&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
(original)
+++
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
Sun Jan 10 17:30:43 2010
@@ -41,8 +41,10 @@
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
public final class LocalDiscoveryUtils {
@@ -76,7 +78,6 @@
private LocalDiscoveryUtils() {}
- @SuppressWarnings("unchecked")
public static List<EndpointDescription> getAllEndpointDescriptions(Bundle
b) {
List<Element> elements = getAllDescriptionElements(b);
@@ -85,23 +86,11 @@
if (ENDPOINT_DESCRIPTION_ELEMENT.equals(el.getName())) {
eds.add(getEndpointDescription(el));
} else if (SERVICE_DESCRIPTION_ELEMENT.equals(el.getName())) {
- Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
-
- List<String> iNames =
getProvidedInterfaces(el.getChildren(PROVIDE_INTERFACE_ELEMENT, ns));
- Map<String, Object> remoteProps =
getProperties(el.getChildren(PROPERTY_ELEMENT, ns));
-
- // this property is used by discovery for matching
-// remoteProps.put(ServicePublication.SERVICE_INTERFACE_NAME,
iNames);
-//
-// if (addEndpointID) {
-// remoteProps.put(ServicePublication.ENDPOINT_SERVICE_ID,
UUID.randomUUID().toString());
-// }
- // @@@@ TODO
- // srefs.add(new ServiceEndpointDescriptionImpl(iNames,
remoteProps));
+ eds.add(getLegacyEndpointDescription(el));
}
}
return eds;
- }
+ }
@SuppressWarnings("unchecked")
private static EndpointDescription getEndpointDescription(Element
endpointDescriptionElement) {
@@ -133,6 +122,42 @@
return new EndpointDescription(map);
}
+ @SuppressWarnings("unchecked")
+ private static EndpointDescription getLegacyEndpointDescription(Element
el) {
+ Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
+
+ List<String> iNames =
getProvidedInterfaces(el.getChildren(PROVIDE_INTERFACE_ELEMENT, ns));
+ Map<String, Object> remoteProps =
getProperties(el.getChildren(PROPERTY_ELEMENT, ns));
+
+ if (remoteProps.get(Constants.OBJECTCLASS) == null) {
+ remoteProps.put(Constants.OBJECTCLASS, iNames.toArray(new String[]
{}));
+ }
+
+ Object uri = remoteProps.get("org.apache.cxf.ws.address");
+ if (uri == null) {
+ uri = remoteProps.get("osgi.remote.configuration.pojo.address");
+ }
+ if (uri == null) {
+ String firstIntf = iNames.get(0);
+ uri = "http://localhost:9000/" + firstIntf.replace('.', '/');
+ }
+ remoteProps.put(RemoteConstants.ENDPOINT_ID, uri.toString());
+
+ Object exportedConfigs =
remoteProps.get(RemoteConstants.SERVICE_EXPORTED_CONFIGS);
+ if (exportedConfigs == null) {
+ exportedConfigs = "org.apache.cxf.ws";
+ }
+ remoteProps.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS,
exportedConfigs);
+
+ for(Iterator<String> it = remoteProps.keySet().iterator();
it.hasNext(); ) {
+ if (it.next().startsWith("service.exported.")) {
+ it.remove();
+ }
+ }
+
+ return new EndpointDescription(remoteProps);
+ }
+
private static String getTypeName(Element prop) {
String type = prop.getAttributeValue("value-type");
if (type == null) {
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=897664&r1=897663&r2=897664&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
Sun Jan 10 17:30:43 2010
@@ -23,9 +23,7 @@
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Dictionary;
import java.util.HashSet;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -35,12 +33,12 @@
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
-import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.osgi.framework.Bundle;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
public class LocalDiscoveryUtilsTest extends TestCase {
public void testNoRemoteServicesXMLFiles() {
@@ -51,108 +49,6 @@
assertEquals(0, rsElements.size());
}
- public void testRemoteServicesXMLFiles() {
- URL rs1URL = getClass().getResource("/rs1.xml");
-
- Bundle b = EasyMock.createNiceMock(Bundle.class);
- EasyMock.expect(b.findEntries(
- EasyMock.eq("OSGI-INF/remote-service"),
- EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
- Collections.enumeration(Arrays.asList(rs1URL))).anyTimes();
- EasyMock.replay(b);
-
- List<Element> rsElements =
LocalDiscoveryUtils.getAllDescriptionElements(b);
- assertEquals(2, rsElements.size());
- Namespace ns =
Namespace.getNamespace("http://www.osgi.org/xmlns/sd/v1.0.0");
- assertEquals("SomeService", rsElements.get(0).getChild("provide",
ns).getAttributeValue("interface"));
- assertEquals("SomeOtherService", rsElements.get(1).getChild("provide",
ns).getAttributeValue("interface"));
- }
-
- public void testMultiRemoteServicesXMLFiles() {
- URL rs1URL = getClass().getResource("/rs1.xml");
- URL rs2URL = getClass().getResource("/rs2.xml");
-
- Bundle b = EasyMock.createNiceMock(Bundle.class);
- EasyMock.expect(b.findEntries(
- EasyMock.eq("OSGI-INF/remote-service"),
- EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
- Collections.enumeration(Arrays.asList(rs1URL,
rs2URL))).anyTimes();
- EasyMock.replay(b);
-
- List<Element> rsElements =
LocalDiscoveryUtils.getAllDescriptionElements(b);
- assertEquals(3, rsElements.size());
- Namespace ns =
Namespace.getNamespace("http://www.osgi.org/xmlns/sd/v1.0.0");
- assertEquals("SomeService", rsElements.get(0).getChild("provide",
ns).getAttributeValue("interface"));
- assertEquals("SomeOtherService", rsElements.get(1).getChild("provide",
ns).getAttributeValue("interface"));
- assertEquals("org.example.Service",
rsElements.get(2).getChild("provide", ns).getAttributeValue("interface"));
- }
-
- @SuppressWarnings("unchecked")
- public void testRemoteServicesXMLFileAlternateLocation() {
- URL rs1URL = getClass().getResource("/rs1.xml");
- Dictionary headers = new Hashtable();
- headers.put("Remote-Service", "META-INF/osgi/");
- headers.put("Bundle-Name", "testing bundle");
-
- Bundle b = EasyMock.createNiceMock(Bundle.class);
- EasyMock.expect(b.getHeaders()).andReturn(headers).anyTimes();
- EasyMock.expect(b.findEntries(
- EasyMock.eq("META-INF/osgi"),
- EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
- Collections.enumeration(Arrays.asList(rs1URL))).anyTimes();
- EasyMock.replay(b);
-
- List<Element> rsElements =
LocalDiscoveryUtils.getAllDescriptionElements(b);
- assertEquals(2, rsElements.size());
- Namespace ns =
Namespace.getNamespace("http://www.osgi.org/xmlns/sd/v1.0.0");
- assertEquals("SomeService", rsElements.get(0).getChild("provide",
ns).getAttributeValue("interface"));
- assertEquals("SomeOtherService", rsElements.get(1).getChild("provide",
ns).getAttributeValue("interface"));
- }
-
- /* public void testAllRemoteReferences() {
- URL rs1URL = getClass().getResource("/rs1.xml");
-
- Bundle b = EasyMock.createNiceMock(Bundle.class);
- EasyMock.expect(b.findEntries("OSGI-INF/remote-service", "*.xml",
false)).
- andReturn(Collections.enumeration(Arrays.asList(rs1URL)));
- EasyMock.replay(b);
-
- List<ServiceEndpointDescription> seds =
LocalDiscoveryUtils.getAllRemoteReferences(b);
- assertEquals(2, seds.size());
- Map<Collection<String>, String> eids = getEndpointIDs(seds);
-
- List<String> interfaces = Arrays.asList("SomeService");
- Map<String, Object> sed1Props = new HashMap<String, Object>();
- sed1Props.put("osgi.remote.requires.intents", "confidentiality");
- sed1Props.put(ServicePublication.ENDPOINT_SERVICE_ID, eids.get(
- Collections.singleton("SomeService")));
- sed1Props.put(ServicePublication.SERVICE_INTERFACE_NAME, interfaces);
- ServiceEndpointDescription sed1 =
- new ServiceEndpointDescriptionImpl(interfaces, sed1Props);
-
- List<String> interfaces2 = Arrays.asList("SomeOtherService",
"WithSomeSecondInterface");
- Map<String, Object> sed2Props = new HashMap<String, Object>();
- sed2Props.put(ServicePublication.ENDPOINT_SERVICE_ID, eids.get(
- new HashSet<String>(interfaces2)));
- sed2Props.put(ServicePublication.SERVICE_INTERFACE_NAME, interfaces2);
- ServiceEndpointDescription sed2 =
- new ServiceEndpointDescriptionImpl(interfaces2, sed2Props);
- assertTrue(seds.contains(sed1));
- assertTrue(seds.contains(sed2));
- }
-
- @SuppressWarnings("unchecked")
- private Map<Collection<String>, String> getEndpointIDs(
- List<ServiceEndpointDescription> seds) {
- Map<Collection<String>, String> map = new HashMap<Collection<String>,
String>();
-
- for (ServiceEndpointDescription sed : seds) {
- map.put((Collection<String>) sed.getProvidedInterfaces(),
sed.getEndpointID());
- }
-
- return map;
- } */
-
public void testEndpointDescriptionXMLFiles() {
URL ed1URL = getClass().getResource("/ed1.xml");
@@ -201,13 +97,13 @@
@SuppressWarnings("unchecked")
public void testAllEndpoints2() throws Exception {
- URL ed1URL = getClass().getResource("/ed2.xml");
+ URL ed2URL = getClass().getResource("/ed2.xml");
Bundle b = EasyMock.createNiceMock(Bundle.class);
EasyMock.expect(b.findEntries(
EasyMock.eq("OSGI-INF/remote-service"),
EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
- Collections.enumeration(Arrays.asList(ed1URL))).anyTimes();
+ Collections.enumeration(Arrays.asList(ed2URL))).anyTimes();
EasyMock.replay(b);
List<EndpointDescription> eds =
LocalDiscoveryUtils.getAllEndpointDescriptions(b);
@@ -259,6 +155,52 @@
normXML((String) l.get(0)));
}
+ public void testLegacyServiceDescriptionFormat() {
+ URL sdURL = getClass().getResource("/sd.xml");
+
+ Bundle b = EasyMock.createNiceMock(Bundle.class);
+ EasyMock.expect(b.findEntries(
+ EasyMock.eq("OSGI-INF/remote-service"),
+ EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
+ Collections.enumeration(Arrays.asList(sdURL))).anyTimes();
+ EasyMock.replay(b);
+
+ List<EndpointDescription> eds =
LocalDiscoveryUtils.getAllEndpointDescriptions(b);
+ assertEquals(1, eds.size());
+ EndpointDescription ed = eds.get(0);
+ assertEquals("http://localhost:9090/greeter", ed.getRemoteID());
+ 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.*",
+
ed.getProperties().get(RemoteConstants.SERVICE_EXPORTED_INTERFACES));
+ assertNull("Should not contain service.exported.*",
+
ed.getProperties().get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
+ }
+
+ public void testLegacyServiceDescriptionFormat2() {
+ URL sdURL = getClass().getResource("/sd2.xml");
+
+ Bundle b = EasyMock.createNiceMock(Bundle.class);
+ EasyMock.expect(b.findEntries(
+ EasyMock.eq("OSGI-INF/remote-service"),
+ EasyMock.eq("*.xml"), EasyMock.anyBoolean())).andReturn(
+ Collections.enumeration(Arrays.asList(sdURL))).anyTimes();
+ EasyMock.replay(b);
+
+ List<EndpointDescription> eds =
LocalDiscoveryUtils.getAllEndpointDescriptions(b);
+ assertEquals(2, eds.size());
+
+ EndpointDescription ed0 = eds.get(0);
+ assertEquals("http://localhost:9000/org/example/SomeService",
ed0.getRemoteID());
+ assertEquals(Arrays.asList("org.apache.cxf.ws"),
ed0.getConfigurationTypes());
+ assertEquals(Arrays.asList("org.example.SomeService"),
ed0.getInterfaces());
+ assertEquals(Arrays.asList("confidentiality"), ed0.getIntents());
+
+ EndpointDescription ed1 = eds.get(1);
+ assertEquals(Arrays.asList("SomeOtherService",
"WithSomeSecondInterface"), ed1.getInterfaces());
+ assertEquals("5", ed1.getProperties().get("blah"));
+ }
+
private static String normXML(String s) throws JDOMException, IOException {
String s2 = stripComment(s);
String s3 = stripProlog(s2);
Added: cxf/dosgi/trunk/discovery/local/src/test/resources/sd.xml
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/resources/sd.xml?rev=897664&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/resources/sd.xml (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/resources/sd.xml Sun Jan 10
17:30:43 2010
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you under the Apache License, Version
+ 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed under
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0">
+ <service-description>
+ <provide interface="org.apache.cxf.dosgi.samples.greeter.GreeterService" />
+ <property name="service.exported.interfaces">*</property>
+ <property name="service.exported.configs">org.apache.cxf.ws</property>
+ <property
name="org.apache.cxf.ws.address">http://localhost:9090/greeter</property>
+ </service-description>
+</service-descriptions>
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/sd.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/sd.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/sd.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: cxf/dosgi/trunk/discovery/local/src/test/resources/sd2.xml
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/resources/sd2.xml?rev=897664&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/resources/sd2.xml (added)
+++ cxf/dosgi/trunk/discovery/local/src/test/resources/sd2.xml Sun Jan 10
17:30:43 2010
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0">
+ <service-description>
+ <provide interface="org.example.SomeService" />
+ <property name="service.intents">confidentiality</property>
+ </service-description>
+ <service-description>
+ <provide interface="SomeOtherService" />
+ <provide interface="WithSomeSecondInterface" />
+ <property name="blah">5</property>
+ </service-description>
+</service-descriptions>
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/sd2.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/sd2.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/dosgi/trunk/discovery/local/src/test/resources/sd2.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml