Author: davidb
Date: Fri Dec 12 07:36:47 2008
New Revision: 726051
URL: http://svn.apache.org/viewvc?rev=726051&view=rev
Log:
Fix for CXF-1942.
New unit tests included.
Removed:
cxf/sandbox/dosgi/samples/greeter/impl/src/main/resources/
Modified:
cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
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=726051&r1=726050&r2=726051&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
Fri Dec 12 07:36:47 2008
@@ -18,10 +18,16 @@
*/
package org.apache.cxf.dosgi.dsw.handlers;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -123,7 +129,7 @@
String [] intents = applyIntents(
dswContext, callingContext, factory.getFeatures(), factory,
sd);
- Server server = factory.create();
+ Server server = factory.create();
getDistributionProvider().addExposedService(serviceReference,
registerPublication(server, intents));
return server;
} catch (IntentUnsatifiedException iue) {
@@ -152,36 +158,91 @@
AbstractEndpointFactory factory,
ServiceEndpointDescription sd) throws
IntentUnsatifiedException {
String[] requestedIntents = getRequestedIntents(sd);
+ Set<String> appliedIntents = new
HashSet<String>(Arrays.asList(requestedIntents));
- IntentMap intentMap = getIntentMap(callingContext);
-
+ IntentMap intentMap = getIntentMap(callingContext);
if (useMasterMap()) {
intentMap = mergeWithMaster(dswContext, intentMap);
}
+ appliedIntents.addAll(reverseLookup(intentMap, PROVIDED_INTENT_VALUE));
- for (int i = 0; i < requestedIntents.length; i++) {
- Object intent = intentMap.get(requestedIntents[i]);
- 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);
- features.add(feature);
- } else if (intent instanceof BindingConfiguration) {
- BindingConfiguration bindingCfg =
- (BindingConfiguration)intent;
- LOG.info("Applying intent: " + requestedIntents[i]
- + " via binding config: " + bindingCfg);
- factory.setBindingConfig(bindingCfg);
- } else {
- LOG.info("No mapping for intent: " + requestedIntents[i]);
- throw new IntentUnsatifiedException(requestedIntents[i]);
+ boolean bindingConfigAdded = false;
+ for (String requestedName : requestedIntents) {
+ bindingConfigAdded
+ |= processIntent(appliedIntents, features, factory,
requestedName, intentMap);
+ }
+
+ if (!bindingConfigAdded && getDefaultBindingIntent() != null) {
+ // If no binding config was specified, add SOAP
+ processIntent(appliedIntents, features, factory,
getDefaultBindingIntent(), intentMap);
+ }
+
+ appliedIntents.addAll(addSynonymIntents(appliedIntents, intentMap));
+ return appliedIntents.toArray(new String[0]);
+ }
+
+ private boolean processIntent(Set<String> appliedIntents,
+ List<AbstractFeature> features,
+ AbstractEndpointFactory factory, String
intentName,
+ IntentMap intentMap) throws
IntentUnsatifiedException {
+ boolean rc = processIntent(features, factory, intentName, intentMap);
+ appliedIntents.add(intentName);
+ return rc;
+ }
+
+ private boolean processIntent(List<AbstractFeature> features,
+ AbstractEndpointFactory factory, String
intentName,
+ IntentMap intentMap) throws
IntentUnsatifiedException {
+ Object intent = intentMap.get(intentName);
+ if (intent instanceof String) {
+ if (PROVIDED_INTENT_VALUE.equalsIgnoreCase((String) intent)) {
+ return false;
+ }
+ } else if (intent instanceof AbstractFeature) {
+ AbstractFeature feature = (AbstractFeature)intent;
+ LOG.info("Applying intent: " + intentName
+ + " via feature: " + feature);
+ features.add(feature);
+ return false;
+ } else if (intent instanceof BindingConfiguration) {
+ BindingConfiguration bindingCfg = (BindingConfiguration)intent;
+ LOG.info("Applying intent: " + intentName
+ + " via binding config: " + bindingCfg);
+ factory.setBindingConfig(bindingCfg);
+ return true;
+ } else {
+ LOG.info("No mapping for intent: " + intentName);
+ throw new IntentUnsatifiedException(intentName);
+ }
+ return false;
+ }
+
+
+ private Collection<String> addSynonymIntents(Collection<String>
appliedIntents, IntentMap intentMap) {
+ // E.g. SOAP and SOAP.1_1 are synonyms
+ List<Object> values = new ArrayList<Object>();
+ for (String key : appliedIntents) {
+ values.add(intentMap.get(key));
+ }
+ return reverseLookup(intentMap, values);
+ }
+
+ private Collection<String> reverseLookup(IntentMap intentMap, Object obj) {
+ return reverseLookup(intentMap, Collections.singleton(obj));
+ }
+
+ private Collection<String> reverseLookup(IntentMap intentMap, Collection<?
extends Object> objs) {
+ Set<String> intentsFound = new HashSet<String>();
+ for (Map.Entry<String, Object> entry :
intentMap.getIntents().entrySet()) {
+ if (objs.contains(entry.getValue())) {
+ intentsFound.add(entry.getKey());
}
}
- return requestedIntents;
+ return intentsFound;
+ }
+
+ String getDefaultBindingIntent() {
+ return "SOAP";
}
IntentMap getIntentMap(BundleContext callingContext) {
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=726051&r1=726050&r2=726051&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
Fri Dec 12 07:36:47 2008
@@ -28,6 +28,7 @@
import junit.framework.TestCase;
+import org.apache.cxf.binding.BindingConfiguration;
import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.dosgi.dsw.TestUtils;
import org.apache.cxf.dosgi.dsw.qos.IntentMap;
@@ -198,6 +199,7 @@
public void testIntents() throws Exception {
Map<String, Object> intents = new HashMap<String, Object>();
intents.put("A", new AbstractFeature() {});
+ intents.put("SOAP", new AbstractFeature() {});
final IntentMap intentMap = new IntentMap();
intentMap.setIntents(intents);
@@ -213,7 +215,12 @@
@Override
IntentMap getIntentMap(BundleContext callingContext) {
return intentMap;
- }
+ }
+
+ @Override
+ String getDefaultBindingIntent() {
+ return null;
+ }
};
Map<String, Object> props = new HashMap<String, Object>();
@@ -245,6 +252,11 @@
IntentMap getIntentMap(BundleContext callingContext) {
return intentMap;
}
+
+ @Override
+ String getDefaultBindingIntent() {
+ return null;
+ }
};
Map<String, Object> props = new HashMap<String, Object>();
@@ -280,7 +292,8 @@
Map<String, Object> props = new HashMap<String, Object>();
props.put(Constants.REQUIRES_INTENTS_PROPERTY, "A B");
- ServiceEndpointDescription sd = new
ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props);
+ ServiceEndpointDescription sd =
+ new
ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props);
try {
p.applyIntents(dswContext, callingContext, features, factory, sd);
@@ -289,6 +302,126 @@
assertEquals("B", iue.getIntent());
}
}
+
+ public void testInferIntents() {
+ Map<String, Object> intents = new HashMap<String, Object>();
+ intents.put("Prov", "PROVIDED");
+ AbstractFeature feat1 = new AbstractFeature() {};
+ intents.put("A", feat1);
+ intents.put("A_alt", feat1);
+ intents.put("B", new AbstractFeature() {});
+ final IntentMap intentMap = new IntentMap();
+ intentMap.setIntents(intents);
+
+ IMocksControl control = EasyMock.createNiceControl();
+ BundleContext dswContext = control.createMock(BundleContext.class);
+ BundleContext callingContext = control.createMock(BundleContext.class);
+ List<AbstractFeature> features = new ArrayList<AbstractFeature>();
+ AbstractEndpointFactory factory =
control.createMock(AbstractEndpointFactory.class);
+ control.replay();
+
+ DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
+ PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp,
handlerProps) {
+ @Override
+ IntentMap getIntentMap(BundleContext callingContext) {
+ return intentMap;
+ }
+
+ @Override
+ String getDefaultBindingIntent() {
+ return null;
+ }
+ };
+
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Constants.REQUIRES_INTENTS_PROPERTY, "A");
+ ServiceEndpointDescription sd =
+ new
ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props);
+
+ List<String> effectiveIntents =
+ Arrays.asList(p.applyIntents(dswContext, callingContext, features,
factory, sd));
+ assertEquals(3, effectiveIntents.size());
+ assertTrue(effectiveIntents.contains("Prov"));
+ assertTrue(effectiveIntents.contains("A"));
+ assertTrue(effectiveIntents.contains("A_alt"));
+ }
+
+ public void testDefaultBindingIntent() {
+ IMocksControl control = EasyMock.createNiceControl();
+
+ Map<String, Object> intents = new HashMap<String, Object>();
+ BindingConfiguration feat1 =
control.createMock(BindingConfiguration.class);
+ intents.put("A", new AbstractFeature() {});
+ intents.put("SOAP", feat1);
+ intents.put("SOAP.1_1", feat1);
+ intents.put("SOAP.1_2",
control.createMock(BindingConfiguration.class));
+ final IntentMap intentMap = new IntentMap();
+ intentMap.setIntents(intents);
+
+ BundleContext dswContext = control.createMock(BundleContext.class);
+ BundleContext callingContext = control.createMock(BundleContext.class);
+ List<AbstractFeature> features = new ArrayList<AbstractFeature>();
+ AbstractEndpointFactory factory =
control.createMock(AbstractEndpointFactory.class);
+ control.replay();
+
+ DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
+ PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp,
handlerProps) {
+ @Override
+ IntentMap getIntentMap(BundleContext callingContext) {
+ return intentMap;
+ }
+ };
+
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Constants.REQUIRES_INTENTS_PROPERTY, "A");
+ ServiceEndpointDescription sd =
+ new
ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props);
+
+ List<String> effectiveIntents =
+ Arrays.asList(p.applyIntents(dswContext, callingContext, features,
factory, sd));
+ assertEquals(3, effectiveIntents.size());
+ assertTrue(effectiveIntents.contains("A"));
+ assertTrue(effectiveIntents.contains("SOAP"));
+ assertTrue(effectiveIntents.contains("SOAP.1_1"));
+ }
+
+ public void testExplicitBindingIntent() {
+ IMocksControl control = EasyMock.createNiceControl();
+
+ Map<String, Object> intents = new HashMap<String, Object>();
+ BindingConfiguration feat1 =
control.createMock(BindingConfiguration.class);
+ intents.put("A", new AbstractFeature() {});
+ intents.put("SOAP", feat1);
+ intents.put("SOAP.1_1", feat1);
+ intents.put("SOAP.1_2",
control.createMock(BindingConfiguration.class));
+ final IntentMap intentMap = new IntentMap();
+ intentMap.setIntents(intents);
+
+ BundleContext dswContext = control.createMock(BundleContext.class);
+ BundleContext callingContext = control.createMock(BundleContext.class);
+ List<AbstractFeature> features = new ArrayList<AbstractFeature>();
+ AbstractEndpointFactory factory =
control.createMock(AbstractEndpointFactory.class);
+ control.replay();
+
+ DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
+ PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp,
handlerProps) {
+ @Override
+ IntentMap getIntentMap(BundleContext callingContext) {
+ return intentMap;
+ }
+ };
+
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Constants.REQUIRES_INTENTS_PROPERTY, "A SOAP.1_2");
+ ServiceEndpointDescription sd =
+ new
ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props);
+
+ List<String> effectiveIntents =
+ Arrays.asList(p.applyIntents(dswContext, callingContext, features,
factory, sd));
+ assertEquals(2, effectiveIntents.size());
+ assertTrue(effectiveIntents.contains("A"));
+ assertTrue(effectiveIntents.contains("SOAP.1_2"));
+ }
public void testInheritMasterIntentMapDefault() {
List<String> features = runTestInheritMasterIntentMap("A B");
@@ -361,6 +494,11 @@
return null;
}
}
+
+ @Override
+ String getDefaultBindingIntent() {
+ return null;
+ }
};
p.applyIntents(dswContext, callingContext, features, factory, sd);
@@ -404,7 +542,12 @@
} else {
return null;
}
- }
+ }
+
+ @Override
+ String getDefaultBindingIntent() {
+ return null;
+ }
};
Set<String> effectiveIntents = new HashSet<String>(Arrays.asList(