Author: eglynn
Date: Tue Oct 7 07:53:39 2008
New Revision: 702501
URL: http://svn.apache.org/viewvc?rev=702501&view=rev
Log:
Applying patch for CXF-1836 on behalf of David Bosschaert
Added:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
(with props)
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/pom.xml
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/resources/META-INF/osgi/intent-map.xml
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
cxf/sandbox/dosgi/felix/framework/src/main/java/org/osgi/service/dsw/DistributionProvider.java
Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/pom.xml?rev=702501&r1=702500&r2=702501&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/pom.xml (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/pom.xml Tue Oct 7 07:53:39 2008
@@ -81,6 +81,7 @@
<Bundle-Name>CXF Distributed Software
Bundle</Bundle-Name>
<Bundle-Description>This bundle contains the
implementation required by the CXF Distributed Software
Bundle</Bundle-Description>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Vendor>The Apache Software
Foundation</Bundle-Vendor>
<Bundle-Activator>org.apache.cxf.dosgi.dsw.Activator</Bundle-Activator>
<Import-Package>${bundle.import.package}</Import-Package>
<Export-Package>${bundle.export.package}</Export-Package>
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java?rev=702501&r1=702500&r2=702501&view=diff
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
(original)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
Tue Oct 7 07:53:39 2008
@@ -19,8 +19,10 @@
package org.apache.cxf.dosgi.dsw;
+import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
+import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -28,6 +30,7 @@
import org.apache.cxf.dosgi.dsw.hooks.CxfListenerHook;
import org.apache.cxf.dosgi.dsw.hooks.CxfPublishHook;
+import org.apache.cxf.dosgi.dsw.qos.IntentMap;
import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
import org.apache.cxf.dosgi.dsw.service.DistributionProviderImpl;
import org.osgi.framework.BundleActivator;
@@ -58,16 +61,42 @@
context.registerService(ManagedService.class.getName(),
this, getDefaults());
- CxfDistributionProvider dpService = new DistributionProviderImpl();
- context.registerService(DistributionProvider.class.getName(),
- dpService, new Hashtable());
+ CxfDistributionProvider dpService =
registerDistributionProviderService();
pHook = new CxfPublishHook(context, dpService);
lHook = new CxfListenerHook(context, dpService);
context.registerService(ListenerHook.class.getName(), lHook, new
Hashtable());
- context.addServiceListener(this);
-
+ context.addServiceListener(this);
+ }
+
+ private CxfDistributionProvider registerDistributionProviderService() {
+ DistributionProviderImpl dpService = new DistributionProviderImpl();
+ Hashtable<String, Object> props = new Hashtable<String, Object>();
+
+ props.put(DistributionProvider.PROP_KEY_PRODUCT_NAME,
getHeader("Bundle-Name"));
+ props.put(DistributionProvider.PROP_KEY_PRODUCT_VERSION,
getHeader("Bundle-Version"));
+ props.put(DistributionProvider.PROP_KEY_VENDOR_NAME,
getHeader("Bundle-Vendor"));
+
+ String supportedIntents = OsgiUtils.formatIntents(
+ getIntentMap().getIntents().keySet().toArray(new String [] {}));
+ props.put(DistributionProvider.PROP_KEY_SUPPORTED_INTENTS,
supportedIntents);
+
+ bc.registerService(DistributionProvider.class.getName(), dpService,
props);
+ return dpService;
+ }
+
+ IntentMap getIntentMap() {
+ return OsgiUtils.getIntentMap(bc);
+ }
+
+ private Object getHeader(String key) {
+ Object value = bc.getBundle().getHeaders().get(key);
+ if (value == null) {
+ return "";
+ } else {
+ return value;
+ }
}
public void stop(BundleContext context) {
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=702501&r1=702500&r2=702501&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
Tue Oct 7 07:53:39 2008
@@ -222,8 +222,21 @@
return intentsSequence == null ? new String[]{} :
intentsSequence.split(" ");
}
- private static Map<String, Object> getProperties(List<Element> elements) {
-
+ public static String formatIntents(String [] intents) {
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for (String intent : intents) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(' ');
+ }
+ sb.append(intent);
+ }
+ return sb.toString();
+ }
+
+ private static Map<String, Object> getProperties(List<Element> elements) {
Map<String, Object> props = new HashMap<String, Object>();
for (Element p : elements) {
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java?rev=702501&r1=702500&r2=702501&view=diff
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
(original)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
Tue Oct 7 07:53:39 2008
@@ -41,8 +41,8 @@
import org.osgi.service.discovery.ServiceDescription;
public class PojoConfigurationTypeHandler extends AbstractConfigurationHandler
{
-
private static final Logger LOG =
Logger.getLogger(PojoConfigurationTypeHandler.class.getName());
+ private static final String PROVIDED_INTENT_VALUE = "PROVIDED";
private IntentMap masterMap;
@@ -132,20 +132,10 @@
publicationProperties.put(Constants.CONFIG_TYPE_PROPERTY,
Constants.POJO_CONFIG_TYPE);
publicationProperties.put(Constants.POJO_ADDRESS_PROPERTY,
server.getDestination().getAddress().getAddress().getValue());
-
- StringBuilder intentsValue = new StringBuilder();
- boolean first = true;
- for (String intent : intents) {
- if (first) {
- first = false;
- } else {
- intentsValue.append(' ');
- }
- intentsValue.append(intent);
- }
-
+
+ String intentsValue = OsgiUtils.formatIntents(intents);
if (intentsValue.length() > 0) {
- publicationProperties.put(Constants.INTENTS_PROPERTY,
intentsValue.toString());
+ publicationProperties.put(Constants.INTENTS_PROPERTY,
intentsValue);
}
return publicationProperties;
}
@@ -164,13 +154,12 @@
}
for (int i = 0; i < requestedIntents.length; i++) {
- // This is temporary
- if ("HTTP".equals(requestedIntents[i])) {
- continue;
- }
-
Object intent = intentMap.get(requestedIntents[i]);
- if (intent instanceof AbstractFeature) {
+ if (intent instanceof String) {
+ if (PROVIDED_INTENT_VALUE.equalsIgnoreCase((String) intent)) {
+ continue;
+ }
+ } else if (intent instanceof AbstractFeature) {
AbstractFeature feature = (AbstractFeature)intent;
LOG.info("Applying intent: " + requestedIntents[i]
+ " via feature: " + feature);
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/resources/META-INF/osgi/intent-map.xml
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/resources/META-INF/osgi/intent-map.xml?rev=702501&r1=702500&r2=702501&view=diff
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/resources/META-INF/osgi/intent-map.xml
(original)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/resources/META-INF/osgi/intent-map.xml
Tue Oct 7 07:53:39 2008
@@ -40,7 +40,7 @@
<entry key="SOAP" value-ref="soap11Binding"/>
<entry key="SOAP.1_1" value-ref="soap11Binding"/>
<entry key="SOAP.1_2" value-ref="soap12Binding"/>
- <!-- <entry key="HTTP"/> -->
+ <entry key="HTTP" value="PROVIDED"/>
</map>
</property>
</bean>
Added:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java?rev=702501&view=auto
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
(added)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
Tue Oct 7 07:53:39 2008
@@ -0,0 +1,83 @@
+package org.apache.cxf.dosgi.dsw;
+
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.dosgi.dsw.qos.IntentMap;
+import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
+import org.apache.cxf.feature.AbstractFeature;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.easymock.IMocksControl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.dsw.DistributionProvider;
+
+
+public class ActivatorTest extends TestCase{
+ @SuppressWarnings("unchecked")
+ public void testCreateDistributionProviderService() {
+ IMocksControl control = EasyMock.createNiceControl();
+
+ Bundle b = control.createMock(Bundle.class);
+ Hashtable<String, String> ht = new Hashtable<String, String>();
+ EasyMock.expect(b.getHeaders()).andReturn(ht).anyTimes();
+
+ final Map<Object, Dictionary> services = new HashMap<Object,
Dictionary>();
+ BundleContext bc = control.createMock(BundleContext.class);
+ EasyMock.expect(bc.registerService(
+ (String) EasyMock.anyObject(),
+ EasyMock.anyObject(),
+ (Dictionary) EasyMock.anyObject())).andAnswer(new
IAnswer<ServiceRegistration>() {
+ public ServiceRegistration answer() throws Throwable {
+ services.put(EasyMock.getCurrentArguments()[1],
+ (Dictionary) EasyMock.getCurrentArguments()[2]);
+ return null;
+ }
+ }).anyTimes();
+
+ EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
+ EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
+ control.replay();
+
+ Activator a = new Activator() {
+ @Override
+ IntentMap getIntentMap() {
+ Map<String, Object> intents = new HashMap<String, Object>();
+ intents.put("A", new AbstractFeature() {});
+ intents.put("B", "PROVIDED");
+
+ IntentMap im = new IntentMap();
+ im.setIntents(intents);
+ return im;
+ }
+ };
+
+ assertEquals("Precondition failed", 0, services.size());
+ a.start(bc);
+
+ assertEquals(3, services.size());
+ CxfDistributionProvider dp = null;
+ for (Object o : services.keySet()) {
+ if (o instanceof CxfDistributionProvider) {
+ dp = ((CxfDistributionProvider) o);
+ }
+ }
+
+ Dictionary serviceProps = services.get(dp);
+ Set<String> expected = new HashSet<String>(Arrays.asList("A", "B"));
+ assertEquals(expected, new HashSet<String>(Arrays.asList(
+ OsgiUtils.parseIntents((String)
serviceProps.get(DistributionProvider.PROP_KEY_SUPPORTED_INTENTS)))));
+
assertNotNull(serviceProps.get(DistributionProvider.PROP_KEY_PRODUCT_NAME));
+
assertNotNull(serviceProps.get(DistributionProvider.PROP_KEY_PRODUCT_VERSION));
+
assertNotNull(serviceProps.get(DistributionProvider.PROP_KEY_VENDOR_NAME));
+ }
+}
Propchange:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java?rev=702501&r1=702500&r2=702501&view=diff
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
(original)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
Tue Oct 7 07:53:39 2008
@@ -1,5 +1,6 @@
package org.apache.cxf.dosgi.dsw;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -51,4 +52,14 @@
assertNull(OsgiUtils.readIntentMap(bc));
assertNotNull(OsgiUtils.getIntentMap(bc));
}
+
+ public void testIntentsParsingAndFormatting() {
+ String initial = "A SOAP_1.1 integrity";
+
+ String[] expected = {"A", "SOAP_1.1", "integrity"};
+ String[] actual = OsgiUtils.parseIntents(initial);
+ assertTrue(Arrays.equals(expected, actual));
+
+ assertEquals(initial, OsgiUtils.formatIntents(actual));
+ }
}
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java?rev=702501&r1=702500&r2=702501&view=diff
==============================================================================
---
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
(original)
+++
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
Tue Oct 7 07:53:39 2008
@@ -21,8 +21,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import junit.framework.TestCase;
@@ -361,6 +363,45 @@
return featureNames;
}
+ public void testProvidedIntents() {
+ Map<String, Object> masterIntents = new HashMap<String, Object>();
+ masterIntents.put("A", "Provided");
+ masterIntents.put("B", "PROVIDED");
+ final IntentMap masterIntentMap = new IntentMap();
+ masterIntentMap.setIntents(masterIntents);
+ final IntentMap appIntentMap = new IntentMap();
+ appIntentMap.setIntents(new HashMap<String, Object>());
+
+ DistributionProviderImpl dp = new DistributionProviderImpl();
+ IMocksControl control = EasyMock.createNiceControl();
+ final BundleContext dswContext =
control.createMock(BundleContext.class);
+ final BundleContext callingContext =
control.createMock(BundleContext.class);
+ List<AbstractFeature> features = new ArrayList<AbstractFeature>();
+ AbstractEndpointFactory factory =
control.createMock(AbstractEndpointFactory.class);
+ control.replay();
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Constants.REQUIRES_INTENTS_PROPERTY, "B A");
+ ServiceDescription sd = new
ServiceDescriptionImpl(Arrays.asList(String.class.getName()), props);
+
+ PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp,
handlerProps) {
+ @Override
+ IntentMap getIntentMap(BundleContext ctx) {
+ if (ctx == callingContext) {
+ return appIntentMap;
+ } else if (ctx == dswContext) {
+ return masterIntentMap;
+ } else {
+ return null;
+ }
+ }
+ };
+
+ Set<String> effectiveIntents = new HashSet<String>(Arrays.asList(
+ p.applyIntents(dswContext, callingContext, features, factory,
sd)));
+ Set<String> expectedIntents = new HashSet<String>(Arrays.asList(new
String [] {"A", "B"}));
+ assertEquals(expectedIntents, effectiveIntents);
+ }
+
private static class TestFeature extends AbstractFeature {
private final String name;
Modified:
cxf/sandbox/dosgi/felix/framework/src/main/java/org/osgi/service/dsw/DistributionProvider.java
URL:
http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/osgi/service/dsw/DistributionProvider.java?rev=702501&r1=702500&r2=702501&view=diff
==============================================================================
---
cxf/sandbox/dosgi/felix/framework/src/main/java/org/osgi/service/dsw/DistributionProvider.java
(original)
+++
cxf/sandbox/dosgi/felix/framework/src/main/java/org/osgi/service/dsw/DistributionProvider.java
Tue Oct 7 07:53:39 2008
@@ -21,10 +21,87 @@
import org.osgi.framework.ServiceReference;
+/**
+ * Every Distribution Provider registers exactly one Service in the
+ * ServiceRegistry implementing this interface. The service is registered with
+ * extra properties identified at the beginning of this interface to denote the
+ * Distribution Provider product name, version, vendor and supported intents.
+ */
public interface DistributionProvider {
- ServiceReference[] getExposedServices();
+ /**
+ * Service Registration property for the name of the Distribution Provider
+ * product.
+ */
+ static final String PROP_KEY_PRODUCT_NAME =
+ "osgi.remote.distribution.product";
+
+ /**
+ * Service Registration property for the version of the Distribution
+ * Provider product.
+ */
+ static final String PROP_KEY_PRODUCT_VERSION =
+ "osgi.remote.distribution.product.version";
+
+ /**
+ * Service Registration property for the Distribution Provider product
+ * vendor name.
+ */
+ static final String PROP_KEY_VENDOR_NAME =
+ "osgi.remote.distribution.vendor";
+
+ /**
+ * Service Registration property that lists the intents supported by this
+ * DistributionProvider.
+ */
+ static final String PROP_KEY_SUPPORTED_INTENTS =
+ "osgi.remote.distribition.supported_intents";
+
+ /**
+ * @return ServiceReferences of services registered in the local Service
+ * Registry that are proxies to remote services. If no proxies are
+ * registered, then an empty array is returned.
+ */
ServiceReference[] getRemoteServices();
+
+ /**
+ * @return ServiceReferences of local services that are exposed remotely
+ * using this DisitributionProvider. Note that certain services
may be
+ * exposed and without being published to a discovery service.
This
+ * API returns all the exposed services. If no services are
exposed an
+ * empty array is returned.
+ */
+ ServiceReference[] getExposedServices();
+
+ /**
+ * @return Local ServiceReferences of exposed services that are published
+ * remotely to a discovery mechanism using this
DisitributionProvider.
+ * Note that certain services might be exposed without being
+ * published.
+ * This API returns all the published service. If no services are
+ * published an empty array is returned.
+ */
ServiceReference[] getPublishedServices();
-
+
+ /**
+ * Provides access to extra properties set by the DistributionProvider on
+ * endpoints, as they will appear on client side proxies given an exposed
+ * ServiceReference.
+ * These properties are not always available on the server-side
+ * ServiceReference of the published
+ * service but will be on the remote client side proxy to this service.
+ * This API provides access to these extra properties from the publishing
+ * side.
+ * E.g. a service is exposed remotely, the distribution software is
configured
+ * to add transactionality to the remote service. Because of this, on the
+ * client-side proxy the property osgi.intents=transactionality is set.
+ * However, these intents are *not* always set on the original
+ * ServiceRegistration on the server-side since on the server side the
service
+ * object is a local pojo which doesnt provide transactionality by itself.
+ * This QoS is added by the distribution.
+ * This API provides access to these extra properties from the server-side.
+ *
+ * @param sr A ServiceReference of a published service.
+ * @return The map of extra properties.
+ */
Map getPublicationProperties(ServiceReference sr);
}