Author: dkulp
Date: Wed Oct 5 19:44:12 2011
New Revision: 1179397
URL: http://svn.apache.org/viewvc?rev=1179397&view=rev
Log:
[CXF-3365] Updates to allow considering the incoming policy alternative
when selecting the outgoing alternative.
Added:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/BaseAlternativeSelector.java
- copied, changed from r1179159,
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java
cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java
cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java
(original)
+++
cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java
Wed Oct 5 19:44:12 2011
@@ -20,15 +20,35 @@
package org.apache.cxf.ws.policy;
import java.util.Collection;
+import java.util.List;
import org.apache.neethi.Assertion;
import org.apache.neethi.Policy;
/**
+ * Used by the Policy engine to select the Policy alternative to use.
*
+ * By default, the Policy engine uses a "Minimal" policy alternative selector
+ * that finds the alternative with the smallest Collection of Assertions to
+ * assert.
*/
public interface AlternativeSelector {
- Collection<Assertion> selectAlternative(Policy policy, PolicyEngine
engine, Assertor assertor);
+ /**
+ *
+ * @param policy The full policy to consider
+ * @param engine The policy engine calling the selector
+ * @param assertor Additional asserter (such as the transport) that may be
+ * able to handle some of the assertions
+ * @param request On the server out bound side, this will contain the
alternatives
+ * from the request that were successfully met by the
request. The
+ * selector should use these to help narrow down the
alternative to
+ * use.
+ * @return
+ */
+ Collection<Assertion> selectAlternative(Policy policy,
+ PolicyEngine engine,
+ Assertor assertor,
+ List<List<Assertion>> request);
}
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java
Wed Oct 5 19:44:12 2011
@@ -130,15 +130,19 @@ public class AssertionInfoMap extends Ha
return pass;
}
- public void checkEffectivePolicy(Policy policy) {
+ public List<List<Assertion>> checkEffectivePolicy(Policy policy) {
+ List<List<Assertion>> validated = new ArrayList<List<Assertion>>(4);
List<QName> errors = new ArrayList<QName>();
Iterator<List<Assertion>> alternatives = policy.getAlternatives();
while (alternatives.hasNext()) {
List<Assertion> pc = alternatives.next();
if (supportsAlternative(pc, errors)) {
- return;
+ validated.add(pc);
}
}
+ if (!validated.isEmpty()) {
+ return validated;
+ }
Set<String> msgs = new LinkedHashSet<String>();
Modified: cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java Wed
Oct 5 19:44:12 2011
@@ -20,12 +20,14 @@
package org.apache.cxf.ws.policy;
import java.util.Collection;
+import java.util.List;
import org.apache.cxf.service.model.BindingFaultInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.Conduit;
import org.apache.cxf.transport.Destination;
+import org.apache.neethi.Assertion;
import org.apache.neethi.PolicyComponent;
import org.apache.neethi.PolicyRegistry;
@@ -59,7 +61,7 @@ public interface PolicyEngine {
void setEffectiveClientRequestPolicy(EndpointInfo ei, BindingOperationInfo
boi, EffectivePolicy ep);
EffectivePolicy getEffectiveServerResponsePolicy(EndpointInfo ei,
BindingOperationInfo boi,
- Destination d);
+ Destination d,
List<List<Assertion>> incoming);
void setEffectiveServerResponsePolicy(EndpointInfo ei,
BindingOperationInfo boi, EffectivePolicy ep);
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java
Wed Oct 5 19:44:12 2011
@@ -83,7 +83,8 @@ public class EffectivePolicyImpl impleme
BindingOperationInfo boi,
PolicyEngineImpl engine,
Assertor assertor,
- boolean requestor, boolean request) {
+ boolean requestor,
+ boolean request) {
initialisePolicy(ei, boi, engine, requestor, request, assertor);
chooseAlternative(engine, assertor);
initialiseInterceptors(engine, false);
@@ -91,6 +92,17 @@ public class EffectivePolicyImpl impleme
void initialise(EndpointInfo ei,
BindingOperationInfo boi,
PolicyEngineImpl engine,
+ Assertor assertor,
+ boolean requestor,
+ boolean request,
+ List<List<Assertion>> incoming) {
+ initialisePolicy(ei, boi, engine, requestor, request, assertor);
+ chooseAlternative(engine, assertor, incoming);
+ initialiseInterceptors(engine, false);
+ }
+ void initialise(EndpointInfo ei,
+ BindingOperationInfo boi,
+ PolicyEngineImpl engine,
boolean requestor, boolean request) {
Assertor assertor = initialisePolicy(ei, boi, engine, requestor,
request, null);
chooseAlternative(engine, assertor);
@@ -148,8 +160,11 @@ public class EffectivePolicyImpl impleme
}
void chooseAlternative(PolicyEngineImpl engine, Assertor assertor) {
+ chooseAlternative(engine, assertor, null);
+ }
+ void chooseAlternative(PolicyEngineImpl engine, Assertor assertor,
List<List<Assertion>> incoming) {
Collection<Assertion> alternative = engine.getAlternativeSelector()
- .selectAlternative(policy, engine, assertor);
+ .selectAlternative(policy, engine, assertor, incoming);
if (null == alternative) {
PolicyUtils.logPolicy(LOG, Level.FINE, "No alternative
supported.", getPolicy());
throw new PolicyException(new Message("NO_ALTERNATIVE_EXC",
BUNDLE));
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
Wed Oct 5 19:44:12 2011
@@ -157,7 +157,7 @@ public class EndpointPolicyImpl implemen
void chooseAlternative() {
Collection<Assertion> alternative = null;
if (requestor) {
- alternative =
engine.getAlternativeSelector().selectAlternative(policy, engine, assertor);
+ alternative =
engine.getAlternativeSelector().selectAlternative(policy, engine, assertor,
null);
} else {
alternative = getSupportedAlternatives();
}
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
Wed Oct 5 19:44:12 2011
@@ -213,19 +213,29 @@ public class PolicyEngineImpl implements
public EffectivePolicy getEffectiveServerResponsePolicy(EndpointInfo ei,
BindingOperationInfo boi,
- Destination d) {
- EffectivePolicy effectivePolicy =
(EffectivePolicy)boi.getProperty(POLICY_INFO_RESPONSE_SERVER);
- if (null == effectivePolicy) {
- EffectivePolicyImpl epi = createOutPolicyInfo();
- Assertor assertor = null;
- if (d instanceof Assertor) {
- assertor = (Assertor)d;
- }
- epi.initialise(ei, boi, this, assertor, false, false);
- boi.setProperty(POLICY_INFO_RESPONSE_SERVER, epi);
- effectivePolicy = epi;
+ Destination d,
+
List<List<Assertion>> incoming) {
+ if (incoming == null) {
+ EffectivePolicy effectivePolicy =
(EffectivePolicy)boi.getProperty(POLICY_INFO_RESPONSE_SERVER);
+ if (null == effectivePolicy) {
+ EffectivePolicyImpl epi = createOutPolicyInfo();
+ Assertor assertor = null;
+ if (d instanceof Assertor) {
+ assertor = (Assertor)d;
+ }
+ epi.initialise(ei, boi, this, assertor, false, false,
incoming);
+ boi.setProperty(POLICY_INFO_RESPONSE_SERVER, epi);
+ effectivePolicy = epi;
+ }
+ return effectivePolicy;
+ }
+ EffectivePolicyImpl epi = createOutPolicyInfo();
+ Assertor assertor = null;
+ if (d instanceof Assertor) {
+ assertor = (Assertor)d;
}
- return effectivePolicy;
+ epi.initialise(ei, boi, this, assertor, false, false, incoming);
+ return epi;
}
public void setEffectiveServerResponsePolicy(EndpointInfo ei,
BindingOperationInfo boi,
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyOutInterceptor.java
Wed Oct 5 19:44:12 2011
@@ -138,7 +138,10 @@ public class PolicyOutInterceptor extend
}
} else {
Destination destination = exchange.getDestination();
- EffectivePolicy effectivePolicy =
pe.getEffectiveServerResponsePolicy(ei, boi, destination);
+ @SuppressWarnings("unchecked")
+ List<List<Assertion>> incoming =
(List)exchange.get("ws-policy.validated.alternatives");
+ EffectivePolicy effectivePolicy
+ = pe.getEffectiveServerResponsePolicy(ei, boi, destination,
incoming);
msg.put(EffectivePolicy.class, effectivePolicy);
List<Interceptor<? extends Message>> interceptors =
effectivePolicy.getInterceptors();
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java
Wed Oct 5 19:44:12 2011
@@ -19,6 +19,7 @@
package org.apache.cxf.ws.policy;
+import java.util.List;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
@@ -33,6 +34,7 @@ import org.apache.cxf.message.MessageUti
import org.apache.cxf.phase.Phase;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.neethi.Assertion;
/**
*
@@ -96,7 +98,10 @@ public class PolicyVerificationInInterce
}
}
try {
- aim.checkEffectivePolicy(effectivePolicy.getPolicy());
+ List<List<Assertion>> usedAlternatives =
aim.checkEffectivePolicy(effectivePolicy.getPolicy());
+ if (usedAlternatives != null && !usedAlternatives.isEmpty() &&
message.getExchange() != null) {
+ message.getExchange().put("ws-policy.validated.alternatives",
usedAlternatives);
+ }
} catch (PolicyException ex) {
//To check if there is ws addressing policy violation and throw
WSA specific
//exception to pass jaxws2.2 tests
Copied:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/BaseAlternativeSelector.java
(from r1179159,
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java)
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/BaseAlternativeSelector.java?p2=cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/BaseAlternativeSelector.java&p1=cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java&r1=1179159&r2=1179397&rev=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/BaseAlternativeSelector.java
Wed Oct 5 19:44:12 2011
@@ -19,30 +19,39 @@
package org.apache.cxf.ws.policy.selector;
-import java.util.Collection;
-import java.util.Iterator;
+
+import java.util.ArrayList;
import java.util.List;
import org.apache.cxf.ws.policy.AlternativeSelector;
-import org.apache.cxf.ws.policy.Assertor;
-import org.apache.cxf.ws.policy.PolicyEngine;
import org.apache.neethi.Assertion;
-import org.apache.neethi.Policy;
+
/**
*
*/
-public class FirstAlternativeSelector implements AlternativeSelector {
-
- public Collection<Assertion> selectAlternative(
- Policy policy, PolicyEngine engine, Assertor assertor) {
- Iterator<List<Assertion>> alternatives = policy.getAlternatives();
- while (alternatives.hasNext()) {
- List<Assertion> alternative = alternatives.next();
- if (engine.supportsAlternative(alternative, assertor)) {
- return alternative;
+public abstract class BaseAlternativeSelector implements AlternativeSelector {
+
+ protected boolean isCompatibleWithRequest(List<Assertion> alternative,
+ List<List<Assertion>> request) {
+ if (request == null) {
+ return true;
+ }
+ for (List<Assertion> r : request) {
+ if (isCompatible(alternative, r)) {
+ return true;
}
- }
- return null;
+ }
+ return false;
}
+
+ protected boolean isCompatible(List<Assertion> alternative,
List<Assertion> r) {
+ List<Assertion> r2 = new ArrayList<Assertion>(r);
+ for (Assertion a : alternative) {
+ r2.remove(a);
+ }
+ return r2.isEmpty();
+ }
+
+
}
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java
Wed Oct 5 19:44:12 2011
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import org.apache.cxf.ws.policy.AlternativeSelector;
import org.apache.cxf.ws.policy.Assertor;
import org.apache.cxf.ws.policy.PolicyEngine;
import org.apache.neethi.Assertion;
@@ -32,17 +31,27 @@ import org.apache.neethi.Policy;
/**
*
*/
-public class FirstAlternativeSelector implements AlternativeSelector {
+public class FirstAlternativeSelector extends BaseAlternativeSelector {
- public Collection<Assertion> selectAlternative(
- Policy policy, PolicyEngine engine, Assertor assertor) {
+ public Collection<Assertion> selectAlternative(Policy policy, PolicyEngine
engine, Assertor assertor,
+ List<List<Assertion>>
request) {
+
Iterator<List<Assertion>> alternatives = policy.getAlternatives();
while (alternatives.hasNext()) {
List<Assertion> alternative = alternatives.next();
+ if (engine.supportsAlternative(alternative, assertor)
+ && this.isCompatibleWithRequest(alternative, request)) {
+ return alternative;
+ }
+ }
+ alternatives = policy.getAlternatives();
+ while (alternatives.hasNext()) {
+ List<Assertion> alternative = alternatives.next();
if (engine.supportsAlternative(alternative, assertor)) {
return alternative;
}
}
return null;
}
+
}
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java
Wed Oct 5 19:44:12 2011
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import org.apache.cxf.ws.policy.AlternativeSelector;
import org.apache.cxf.ws.policy.Assertor;
import org.apache.cxf.ws.policy.PolicyEngine;
import org.apache.neethi.Assertion;
@@ -32,19 +31,32 @@ import org.apache.neethi.Policy;
/**
*
*/
-public class MaximalAlternativeSelector implements AlternativeSelector {
+public class MaximalAlternativeSelector extends BaseAlternativeSelector {
public Collection<Assertion> selectAlternative(
- Policy policy, PolicyEngine engine, Assertor assertor) {
+ Policy policy, PolicyEngine engine,
+ Assertor assertor,
+ List<List<Assertion>> request) {
Collection<Assertion> choice = null;
Iterator<List<Assertion>> alternatives = policy.getAlternatives();
while (alternatives.hasNext()) {
List<Assertion> alternative = alternatives.next();
if (engine.supportsAlternative(alternative, assertor)
+ && isCompatibleWithRequest(alternative, request)
&& (null == choice || alternative.size() > choice.size())) {
choice = alternative;
}
}
+ if (choice == null) {
+ alternatives = policy.getAlternatives();
+ while (alternatives.hasNext()) {
+ List<Assertion> alternative = alternatives.next();
+ if (engine.supportsAlternative(alternative, assertor)
+ && (null == choice || alternative.size() > choice.size()))
{
+ choice = alternative;
+ }
+ }
+ }
return choice;
}
}
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java
(original)
+++
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java
Wed Oct 5 19:44:12 2011
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import org.apache.cxf.ws.policy.AlternativeSelector;
import org.apache.cxf.ws.policy.Assertor;
import org.apache.cxf.ws.policy.PolicyEngine;
import org.apache.neethi.Assertion;
@@ -32,20 +31,36 @@ import org.apache.neethi.Policy;
/**
*
*/
-public class MinimalAlternativeSelector implements AlternativeSelector {
+public class MinimalAlternativeSelector extends BaseAlternativeSelector {
public Collection<Assertion> selectAlternative(
- Policy policy, PolicyEngine engine, Assertor assertor) {
+ Policy policy, PolicyEngine engine,
+ Assertor assertor,
+ List<List<Assertion>> request) {
+
Collection<Assertion> choice = null;
Iterator<List<Assertion>> alternatives = policy.getAlternatives();
while (alternatives.hasNext()) {
List<Assertion> alternative = alternatives.next();
- if (engine.supportsAlternative(alternative, assertor)
+ if (engine.supportsAlternative(alternative, assertor)
+ && isCompatibleWithRequest(alternative, request)
&& (null == choice || alternative.size() < choice.size())) {
choice = alternative;
}
}
+ if (choice == null) {
+ // didn't find one completely compatible with the incoming, just
get the minimal
+ alternatives = policy.getAlternatives();
+ while (alternatives.hasNext()) {
+ List<Assertion> alternative = alternatives.next();
+
+ if (engine.supportsAlternative(alternative, assertor)
+ && (null == choice || alternative.size() < choice.size()))
{
+ choice = alternative;
+ }
+ }
+ }
return choice;
}
}
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java
Wed Oct 5 19:44:12 2011
@@ -248,7 +248,7 @@ public class EffectivePolicyImplTest ext
Assertor assertor = control.createMock(Assertor.class);
AlternativeSelector selector =
control.createMock(AlternativeSelector.class);
EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
- EasyMock.expect(selector.selectAlternative(policy, engine,
assertor)).andReturn(null);
+ EasyMock.expect(selector.selectAlternative(policy, engine, assertor,
null)).andReturn(null);
control.replay();
try {
@@ -262,7 +262,7 @@ public class EffectivePolicyImplTest ext
control.reset();
EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
Collection<Assertion> alternative = new ArrayList<Assertion>();
- EasyMock.expect(selector.selectAlternative(policy, engine,
assertor)).andReturn(alternative);
+ EasyMock.expect(selector.selectAlternative(policy, engine, assertor,
null)).andReturn(alternative);
control.replay();
epi.chooseAlternative(engine, assertor);
Collection<Assertion> choice = epi.getChosenAlternative();
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
Wed Oct 5 19:44:12 2011
@@ -164,7 +164,7 @@ public class EndpointPolicyImplTest exte
epi.setPolicy(policy);
EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
- EasyMock.expect(selector.selectAlternative(policy, engine,
assertor)).andReturn(null);
+ EasyMock.expect(selector.selectAlternative(policy, engine, assertor,
null)).andReturn(null);
control.replay();
try {
@@ -178,7 +178,7 @@ public class EndpointPolicyImplTest exte
control.reset();
EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
Collection<Assertion> alternative = new ArrayList<Assertion>();
- EasyMock.expect(selector.selectAlternative(policy, engine,
assertor)).andReturn(alternative);
+ EasyMock.expect(selector.selectAlternative(policy, engine, assertor,
null)).andReturn(alternative);
control.replay();
epi.chooseAlternative();
Collection<Assertion> choice = epi.getChosenAlternative();
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
Wed Oct 5 19:44:12 2011
@@ -151,11 +151,11 @@ public class PolicyEngineTest extends As
AssertingDestination destination =
control.createMock(AssertingDestination.class);
EffectivePolicyImpl epi =
control.createMock(EffectivePolicyImpl.class);
EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi);
- epi.initialise(ei, boi, engine, destination, false, false);
+ epi.initialise(ei, boi, engine, destination, false, false, null);
EasyMock.expectLastCall();
control.replay();
- assertSame(epi, engine.getEffectiveServerResponsePolicy(ei, boi,
destination));
- assertSame(epi, engine.getEffectiveServerResponsePolicy(ei, boi,
destination));
+ assertSame(epi, engine.getEffectiveServerResponsePolicy(ei, boi,
destination, null));
+ assertSame(epi, engine.getEffectiveServerResponsePolicy(ei, boi,
destination, null));
control.verify();
}
@@ -168,7 +168,7 @@ public class PolicyEngineTest extends As
control.replay();
engine.setEffectiveServerResponsePolicy(ei, boi, effectivePolicy);
assertSame(effectivePolicy,
- engine.getEffectiveServerResponsePolicy(ei, boi,
(Destination)null));
+ engine.getEffectiveServerResponsePolicy(ei, boi,
(Destination)null, null));
control.verify();
}
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java
Wed Oct 5 19:44:12 2011
@@ -190,7 +190,7 @@ public class PolicyInterceptorsTest exte
control.reset();
setupMessage(false, false, true, true, true, true);
EffectivePolicy effectivePolicy =
control.createMock(EffectivePolicy.class);
- EasyMock.expect(pe.getEffectiveServerResponsePolicy(ei, boi,
destination))
+ EasyMock.expect(pe.getEffectiveServerResponsePolicy(ei, boi,
destination, null))
.andReturn(effectivePolicy);
List<Interceptor<? extends Message>> li = createMockInterceptorList();
EasyMock.expect(effectivePolicy.getInterceptors())
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
Wed Oct 5 19:44:12 2011
@@ -110,7 +110,7 @@ public class PolicyVerificationInFaultIn
Policy policy = control.createMock(Policy.class);
EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
aim.checkEffectivePolicy(policy);
- EasyMock.expectLastCall();
+ EasyMock.expectLastCall().andReturn(null);
control.replay();
interceptor.handleMessage(message);
control.verify();
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
Wed Oct 5 19:44:12 2011
@@ -102,7 +102,7 @@ public class PolicyVerificationInInterce
Policy policy = control.createMock(Policy.class);
EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
aim.checkEffectivePolicy(policy);
- EasyMock.expectLastCall();
+ EasyMock.expectLastCall().andReturn(null);
control.replay();
interceptor.handleMessage(message);
control.verify();
@@ -118,7 +118,7 @@ public class PolicyVerificationInInterce
policy = control.createMock(Policy.class);
EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
aim.checkEffectivePolicy(policy);
- EasyMock.expectLastCall();
+ EasyMock.expectLastCall().andReturn(null);
control.replay();
interceptor.handleMessage(message);
control.verify();
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
Wed Oct 5 19:44:12 2011
@@ -72,7 +72,7 @@ public class PolicyVerificationOutInterc
aim.checkEffectivePolicy(null);
- EasyMock.expectLastCall();
+ EasyMock.expectLastCall().andReturn(null);
control.replay();
interceptor.handleMessage(message);
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java
Wed Oct 5 19:44:12 2011
@@ -69,13 +69,13 @@ public class FirstAlternativeSelectorTes
EasyMock.expect(engine.supportsAlternative(firstAlternative,
assertor)).andReturn(false);
control.replay();
- assertNull(selector.selectAlternative(policy, engine, assertor));
+ assertNull(selector.selectAlternative(policy, engine, assertor,
null));
control.verify();
control.reset();
EasyMock.expect(engine.supportsAlternative(firstAlternative,
assertor)).andReturn(true);
control.replay();
- Collection<Assertion> chosen = selector.selectAlternative(policy,
engine, assertor);
+ Collection<Assertion> chosen = selector.selectAlternative(policy,
engine, assertor, null);
assertSame(1, chosen.size());
assertSame(chosen.size(), firstAlternative.size());
assertSame(chosen.iterator().next(),
firstAlternative.iterator().next());
@@ -91,7 +91,7 @@ public class FirstAlternativeSelectorTes
EasyMock.expect(engine.supportsAlternative(secondAlternative,
assertor)).andReturn(true);
control.replay();
- chosen = selector.selectAlternative(policy, engine, assertor);
+ chosen = selector.selectAlternative(policy, engine, assertor, null);
assertSame(1, chosen.size());
assertSame(chosen.size(), secondAlternative.size());
assertSame(chosen.iterator().next(),
secondAlternative.iterator().next());
Modified:
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java?rev=1179397&r1=1179396&r2=1179397&view=diff
==============================================================================
---
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java
(original)
+++
cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java
Wed Oct 5 19:44:12 2011
@@ -75,7 +75,7 @@ public class MinimalMaximalAlternativeSe
control.replay();
Collection<Assertion> choice =
- selector.selectAlternative(policy, engine, assertor);
+ selector.selectAlternative(policy, engine, assertor, null);
assertEquals(0, choice.size());
control.verify();
}
@@ -104,7 +104,7 @@ public class MinimalMaximalAlternativeSe
EasyMock.expect(engine.supportsAlternative(minAlternative,
assertor)).andReturn(true);
control.replay();
- Collection<Assertion> choice = selector.selectAlternative(policy,
engine, assertor);
+ Collection<Assertion> choice = selector.selectAlternative(policy,
engine, assertor, null);
assertEquals(1, choice.size());
assertSame(a1, choice.iterator().next());
control.verify();