Author: eglynn
Date: Fri Oct 10 06:34:27 2008
New Revision: 703452
URL: http://svn.apache.org/viewvc?rev=703452&view=rev
Log:
[dOSGi] Adding support for configuration of per-interface addresses for
multi-interface OSGi services
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-services/multi-services.xml
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java?rev=703452&r1=703451&r2=703452&view=diff
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
(original)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
Fri Oct 10 06:34:27 2008
@@ -68,6 +68,10 @@
private static final String PROPERTY_ELEMENT = "property";
private static final String PROPERTY_KEY_ATTRIBUTE = "key";
+ private static final String PROPERTY_INTERFACE_ATTRIBUTE = "interface";
+
+ private static final String INTERFACE_WILDCARD = "*";
+ private static final String INTERFACE_SEPARATOR = ":";
private OsgiUtils() {
}
@@ -150,6 +154,21 @@
Map<String, Object> props =
excludeProperty(sd.getProperties(),
Constants.REMOTE_INTERFACES_PROPERTY);
+ 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);
}
}
@@ -308,8 +327,12 @@
for (Element p : elements) {
String key = p.getAttributeValue(PROPERTY_KEY_ATTRIBUTE);
+ String iface = p.getAttributeValue(PROPERTY_INTERFACE_ATTRIBUTE);
if (key != null) {
- props.put(key, p.getTextTrim());
+ props.put(iface == null || iface.length() == 0
+ ? key
+ : key + INTERFACE_SEPARATOR + iface,
+ p.getTextTrim());
}
}
@@ -444,7 +467,7 @@
&& publishProperty != null
&& publishProperty.length() > 0) {
- if ("*".equals(publishProperty)) {
+ if (INTERFACE_WILDCARD.equals(publishProperty)) {
// wildcard indicates all interfaces should be published
//
publishableInterfaces = actualInterfaces;
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java?rev=703452&r1=703451&r2=703452&view=diff
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
(original)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
Fri Oct 10 06:34:27 2008
@@ -52,19 +52,23 @@
@Test
public void testPublishSingleInterface() throws Exception {
String[] serviceNames = new String[]{TestService.class.getName()};
- doTestPublishHook("remote-services.xml", serviceNames);
+ String[] addresses = new String[]{"http://localhost:9000/hello"};
+ doTestPublishHook("remote-services.xml", serviceNames, addresses);
}
@Test
public void testPublishMultiInterface() throws Exception {
String[] serviceNames = new String[]{TestService.class.getName(),
AdditionalInterface.class.getName()};
- doTestPublishHook("multi-services.xml", serviceNames);
+ String[] addresses = new String[]{"http://localhost:9001/hello",
+ "http://localhost:9002/hello"};
+ doTestPublishHook("multi-services.xml", serviceNames, addresses);
}
@SuppressWarnings("unchecked")
private void doTestPublishHook(String remoteServices,
- String[] serviceNames) throws Exception {
+ String[] serviceNames,
+ String[] addresses) throws Exception {
Bundle bundle = control.createMock(Bundle.class);
bundle.findEntries(EasyMock.eq("OSGI-INF/remote-services"),
@@ -122,6 +126,9 @@
String excludeProp =
org.apache.cxf.dosgi.dsw.Constants.REMOTE_INTERFACES_PROPERTY;
assertNull(sd.getProperties().get(excludeProp));
+ String addrProp =
+ org.apache.cxf.dosgi.dsw.Constants.POJO_ADDRESS_PROPERTY;
+ assertEquals(addresses[i], sd.getProperties().get(addrProp));
}
}
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-services/multi-services.xml
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-services/multi-services.xml?rev=703452&r1=703451&r2=703452&view=diff
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-services/multi-services.xml
(original)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-services/multi-services.xml
Fri Oct 10 06:34:27 2008
@@ -26,6 +26,13 @@
<property
key="osgi.remote.publish.interfaces">org.apache.cxf.dosgi.dsw.hooks.TestService,org.apache.cxf.dosgi.dsw.hooks.CxfPublishHookTest$AdditionalInterface</property>
<property key="osgi.remote.requires.intents">SOAP HTTP</property>
<property key="osgi.remote.configuration.type">pojo</property>
- <property
key="osgi.remote.configuration.pojo.address">http://localhost:9001/hello</property>
+ <property key="osgi.remote.configuration.pojo.address"
+ interface="org.apache.cxf.dosgi.dsw.hooks.TestService">
+ http://localhost:9001/hello
+ </property>
+ <property key="osgi.remote.configuration.pojo.address"
+
interface="org.apache.cxf.dosgi.dsw.hooks.CxfPublishHookTest$AdditionalInterface">
+ http://localhost:9002/hello
+ </property>
</service-description>
</service-descriptions>