You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/04/06 16:47:08 UTC
svn commit: r1310362 - in /cxf/trunk/rt/ws/policy/src:
main/java/org/apache/cxf/ws/policy/ test/java/org/apache/cxf/ws/policy/
Author: dkulp
Date: Fri Apr 6 14:47:07 2012
New Revision: 1310362
URL: http://svn.apache.org/viewvc?rev=1310362&view=rev
Log:
[CXF-4223] Extend fault policy interceptors with POLICY_OVERRIDE
Patch from Andrei Shakirin applied
Modified:
cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.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/PolicyInInterceptor.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/ServerPolicyOutFaultInterceptor.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/PolicyInterceptorsTest.java
Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java?rev=1310362&r1=1310361&r2=1310362&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java (original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java Fri Apr 6 14:47:07 2012
@@ -19,6 +19,7 @@
package org.apache.cxf.ws.policy;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
@@ -35,6 +36,7 @@ import org.apache.cxf.phase.Phase;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.Conduit;
import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
/**
*
@@ -72,27 +74,44 @@ public class ClientPolicyInFaultIntercep
Conduit conduit = exchange.getConduit(msg);
LOG.fine("conduit: " + conduit);
-
- // We do not know the underlying message type yet - so we pre-emptively add interceptors
- // that can deal with all faults returned to this client endpoint.
-
- EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit);
- LOG.fine("ep: " + ep);
-
- List<Interceptor<? extends Message>> faultInterceptors = ep.getFaultInterceptors();
-
- LOG.fine("faultInterceptors: " + faultInterceptors);
- if (null != faultInterceptors) {
- for (Interceptor<? extends Message> i : faultInterceptors) {
- msg.getInterceptorChain().add(i);
- LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
+
+ List<Interceptor<? extends Message>> faultInterceptors =
+ new ArrayList<Interceptor<? extends Message>>();
+ Collection<Assertion> assertions = new ArrayList<Assertion>();
+
+ // 1. Check overridden policy
+ Policy p = (Policy)msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
+ if (p != null) {
+ EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
+ EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
+ effectivePolicy.initialise(endpi, (PolicyEngineImpl)pe, true, true);
+ PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ",
+ effectivePolicy.getPolicy());
+
+ faultInterceptors.addAll(effectivePolicy.getInterceptors());
+ assertions.addAll(effectivePolicy.getChosenAlternative());
+ } else {
+ // 2. Process endpoint policy
+ // We do not know the underlying message type yet - so we pre-emptively add interceptors
+ // that can deal with all faults returned to this client endpoint.
+
+ EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit);
+ LOG.fine("ep: " + ep);
+ if (ep != null) {
+ faultInterceptors.addAll(ep.getFaultInterceptors());
+ assertions.addAll(ep.getFaultVocabulary());
}
}
- // insert assertions of endpoint's fault vocabulary into message
+ // add interceptors into message chain
+ LOG.fine("faultInterceptors: " + faultInterceptors);
+ for (Interceptor<? extends Message> i : faultInterceptors) {
+ msg.getInterceptorChain().add(i);
+ LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
+ }
- Collection<Assertion> assertions = ep.getFaultVocabulary();
- if (null != assertions && !assertions.isEmpty()) {
+ // insert assertions of endpoint's fault vocabulary into message
+ if (!assertions.isEmpty()) {
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
}
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=1310362&r1=1310361&r2=1310362&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 Fri Apr 6 14:47:07 2012
@@ -70,12 +70,16 @@ public class EffectivePolicyImpl impleme
}
public void initialise(EndpointPolicyImpl epi, PolicyEngineImpl engine, boolean inbound) {
+ initialise(epi, engine, inbound, false);
+ }
+
+ public void initialise(EndpointPolicyImpl epi, PolicyEngineImpl engine, boolean inbound, boolean fault) {
policy = epi.getPolicy();
chosenAlternative = epi.getChosenAlternative();
if (chosenAlternative == null) {
chooseAlternative(engine, null);
}
- initialiseInterceptors(engine, inbound);
+ initialiseInterceptors(engine, inbound, fault);
}
public void initialise(EndpointInfo ei,
@@ -188,14 +192,19 @@ public class EffectivePolicyImpl impleme
void initialiseInterceptors(PolicyEngineImpl engine) {
initialiseInterceptors(engine, false);
}
+
void initialiseInterceptors(PolicyEngineImpl engine, boolean useIn) {
+ initialiseInterceptors(engine, useIn, false);
+ }
+
+ void initialiseInterceptors(PolicyEngineImpl engine, boolean useIn, boolean fault) {
if (engine.getBus() != null) {
PolicyInterceptorProviderRegistry reg
= engine.getBus().getExtension(PolicyInterceptorProviderRegistry.class);
Set<Interceptor<? extends org.apache.cxf.message.Message>> out
= new LinkedHashSet<Interceptor<? extends org.apache.cxf.message.Message>>();
for (Assertion a : getChosenAlternative()) {
- initialiseInterceptors(reg, engine, out, a, useIn);
+ initialiseInterceptors(reg, engine, out, a, useIn, fault);
}
setInterceptors(new ArrayList<Interceptor<? extends org.apache.cxf.message.Message>>(out));
}
@@ -217,18 +226,26 @@ public class EffectivePolicyImpl impleme
void initialiseInterceptors(PolicyInterceptorProviderRegistry reg, PolicyEngineImpl engine,
Set<Interceptor<? extends org.apache.cxf.message.Message>> out, Assertion a,
- boolean usIn) {
+ boolean useIn, boolean fault) {
QName qn = a.getName();
- List<Interceptor<? extends org.apache.cxf.message.Message>> i =
- usIn ? reg.getInInterceptorsForAssertion(qn)
- : reg.getOutInterceptorsForAssertion(qn);
+
+ List<Interceptor<? extends org.apache.cxf.message.Message>> i = null;
+ if (useIn & !fault) {
+ i = reg.getInInterceptorsForAssertion(qn);
+ } else if (!useIn && !fault) {
+ i = reg.getOutInterceptorsForAssertion(qn);
+ } else if (useIn && fault) {
+ i = reg.getInFaultInterceptorsForAssertion(qn);
+ } else if (!useIn && fault) {
+ i = reg.getOutFaultInterceptorsForAssertion(qn);
+ }
out.addAll(i);
if (a instanceof PolicyContainingAssertion) {
Policy p = ((PolicyContainingAssertion)a).getPolicy();
if (p != null) {
for (Assertion a2 : getSupportedAlternatives(engine, p)) {
- initialiseInterceptors(reg, engine, out, a2, usIn);
+ initialiseInterceptors(reg, engine, out, a2, useIn, fault);
}
}
}
Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyInInterceptor.java?rev=1310362&r1=1310361&r2=1310362&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyInInterceptor.java (original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyInInterceptor.java Fri Apr 6 14:47:07 2012
@@ -19,6 +19,7 @@
package org.apache.cxf.ws.policy;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
@@ -66,6 +67,9 @@ public class PolicyInInterceptor extends
return;
}
+ List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
+ Collection<Assertion> assertions = new ArrayList<Assertion>();
+
// 1. Check overridden policy
Policy p = (Policy)msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
if (p != null) {
@@ -76,57 +80,32 @@ public class PolicyInInterceptor extends
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ",
effectivePolicy.getPolicy());
- List<Interceptor<? extends Message>> interceptors = effectivePolicy.getInterceptors();
- for (Interceptor<? extends Message> i : interceptors) {
- msg.getInterceptorChain().add(i);
- LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
- }
- Collection<Assertion> assertions = effectivePolicy.getChosenAlternative();
- if (null != assertions && !assertions.isEmpty()) {
- msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
- msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
- }
- }
-
- // 2. Process client policy
- if (MessageUtils.isRequestor(msg)) {
+ interceptors.addAll(effectivePolicy.getInterceptors());
+ assertions.addAll(effectivePolicy.getChosenAlternative());
+ } else if (MessageUtils.isRequestor(msg)) {
+ // 2. Process client policy
BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
if (boi == null) {
Conduit conduit = exchange.getConduit(msg);
-
EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit);
-
- List<Interceptor<? extends Message>> interceptors = ep.getInterceptors();
- if (null != interceptors) {
- for (Interceptor<? extends Message> i : interceptors) {
- msg.getInterceptorChain().add(i);
- }
- }
-
- // Insert assertions of endpoint's vocabulary into message
- Collection<Assertion> assertions = ep.getVocabulary();
- if (null != assertions && !assertions.isEmpty()) {
- msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
- msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
+ if (ep != null) {
+ interceptors.addAll(ep.getInterceptors());
+ assertions.addAll(ep.getVocabulary());
}
} else {
// We do not know the underlying message type yet - so we pre-emptively add interceptors
// that can deal with any resposes or faults returned to this client endpoint.
EffectivePolicy ep = pe.getEffectiveClientResponsePolicy(ei, boi);
-
- List<Interceptor<? extends Message>> interceptors = ep.getInterceptors();
- if (null != interceptors) {
- for (Interceptor<? extends Message> i : interceptors) {
- msg.getInterceptorChain().add(i);
+ if (ep != null) {
+ interceptors.addAll(ep.getInterceptors());
+ // insert assertions of endpoint's vocabulary into message
+ if (ep.getPolicy() != null) {
+ msg.put(AssertionInfoMap.class, new AssertionInfoMap(ep.getPolicy()));
+ msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
}
}
- // insert assertions of endpoint's vocabulary into message
- if (ep.getPolicy() != null) {
- msg.put(AssertionInfoMap.class, new AssertionInfoMap(ep.getPolicy()));
- msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
- }
}
} else {
// 3. Process server policy
@@ -136,22 +115,22 @@ public class PolicyInInterceptor extends
// that can deal with any messages to this endpoint
EndpointPolicy ep = pe.getServerEndpointPolicy(ei, destination);
-
- List<Interceptor<? extends Message>> interceptors = ep.getInterceptors();
- if (null != interceptors) {
- for (Interceptor<? extends Message> i : interceptors) {
- msg.getInterceptorChain().add(i);
- LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
- }
- }
-
- // insert assertions of endpoint's vocabulary into message
-
- Collection<Assertion> assertions = ep.getVocabulary();
- if (null != assertions && !assertions.isEmpty()) {
- msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
- msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
+ if (ep != null) {
+ interceptors.addAll(ep.getInterceptors());
+ assertions.addAll(ep.getVocabulary());
}
}
+
+ // add interceptors into message chain
+ for (Interceptor<? extends Message> i : interceptors) {
+ msg.getInterceptorChain().add(i);
+ }
+
+ // Insert assertions of endpoint's vocabulary into message
+ if (!assertions.isEmpty()) {
+ msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
+ msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
+ }
+
}
}
\ No newline at end of file
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=1310362&r1=1310361&r2=1310362&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 Fri Apr 6 14:47:07 2012
@@ -19,6 +19,7 @@
package org.apache.cxf.ws.policy;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
@@ -74,6 +75,11 @@ public class PolicyOutInterceptor extend
if (null == pe) {
return;
}
+
+ List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
+ Collection<Assertion> assertions = new ArrayList<Assertion>();
+
+ // 1. Check overridden policy
Policy p = (Policy)msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
if (p != null) {
EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
@@ -83,82 +89,56 @@ public class PolicyOutInterceptor extend
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ",
effectivePolicy.getPolicy());
- List<Interceptor<? extends Message>> interceptors = effectivePolicy.getInterceptors();
- for (Interceptor<? extends Message> i : interceptors) {
- msg.getInterceptorChain().add(i);
- LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
- }
-
- // insert assertions of the chosen alternative into the message
-
- Collection<Assertion> assertions = effectivePolicy.getChosenAlternative();
- if (null != assertions && !assertions.isEmpty()) {
- if (LOG.isLoggable(Level.FINEST)) {
- StringBuilder buf = new StringBuilder();
- buf.append("Chosen alternative: ");
- String nl = SystemPropertyAction.getProperty("line.separator");
- buf.append(nl);
- for (Assertion a : assertions) {
- PolicyUtils.printPolicyComponent(a, buf, 1);
- }
- LOG.finest(buf.toString());
- }
- msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
- msg.getInterceptorChain().add(PolicyVerificationOutInterceptor.INSTANCE);
- }
+ interceptors.addAll(effectivePolicy.getInterceptors());
+ assertions.addAll(effectivePolicy.getChosenAlternative());
} else if (MessageUtils.isRequestor(msg)) {
+ // 2. Process client policy
Conduit conduit = exchange.getConduit(msg);
// add the required interceptors
EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(ei, boi, conduit);
msg.put(EffectivePolicy.class, effectivePolicy);
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
-
- List<Interceptor<? extends Message>> interceptors = effectivePolicy.getInterceptors();
- for (Interceptor<? extends Message> i : interceptors) {
- msg.getInterceptorChain().add(i);
- LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
- }
-
- // insert assertions of the chosen alternative into the message
-
- Collection<Assertion> assertions = effectivePolicy.getChosenAlternative();
- if (null != assertions && !assertions.isEmpty()) {
- if (LOG.isLoggable(Level.FINEST)) {
- StringBuilder buf = new StringBuilder();
- buf.append("Chosen alternative: ");
- String nl = SystemPropertyAction.getProperty("line.separator");
- buf.append(nl);
- for (Assertion a : assertions) {
- PolicyUtils.printPolicyComponent(a, buf, 1);
- }
- LOG.finest(buf.toString());
- }
- msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
- msg.getInterceptorChain().add(PolicyVerificationOutInterceptor.INSTANCE);
+ if (effectivePolicy != null) {
+ interceptors.addAll(effectivePolicy.getInterceptors());
+ assertions.addAll(effectivePolicy.getChosenAlternative());
}
} else {
+ // 3. Process server policy
Destination destination = exchange.getDestination();
List<List<Assertion>> incoming
= CastUtils.cast((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();
- for (Interceptor<? extends Message> oi : interceptors) {
- msg.getInterceptorChain().add(oi);
- LOG.log(Level.FINE, "Added interceptor of type {0}",
- oi.getClass().getSimpleName());
+ PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
+ if (effectivePolicy != null) {
+ interceptors.addAll(effectivePolicy.getInterceptors());
+ assertions.addAll(effectivePolicy.getChosenAlternative());
}
-
- // insert assertions of the chosen alternative into the message
-
- Collection<Assertion> assertions = effectivePolicy.getChosenAlternative();
- if (null != assertions && !assertions.isEmpty()) {
- msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
- msg.getInterceptorChain().add(PolicyVerificationOutInterceptor.INSTANCE);
+ }
+
+ // add interceptors into message chain
+ for (Interceptor<? extends Message> oi : interceptors) {
+ msg.getInterceptorChain().add(oi);
+ LOG.log(Level.FINE, "Added interceptor of type {0}",
+ oi.getClass().getSimpleName());
+ }
+
+ // insert assertions of endpoint's fault vocabulary into message
+ if (null != assertions && !assertions.isEmpty()) {
+ if (LOG.isLoggable(Level.FINEST)) {
+ StringBuilder buf = new StringBuilder();
+ buf.append("Chosen alternative: ");
+ String nl = SystemPropertyAction.getProperty("line.separator");
+ buf.append(nl);
+ for (Assertion a : assertions) {
+ PolicyUtils.printPolicyComponent(a, buf, 1);
+ }
+ LOG.finest(buf.toString());
}
+ msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
+ msg.getInterceptorChain().add(PolicyVerificationOutInterceptor.INSTANCE);
}
}
}
Modified: cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java?rev=1310362&r1=1310361&r2=1310362&view=diff
==============================================================================
--- cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java (original)
+++ cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutFaultInterceptor.java Fri Apr 6 14:47:07 2012
@@ -19,6 +19,7 @@
package org.apache.cxf.ws.policy;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
@@ -38,6 +39,7 @@ import org.apache.cxf.service.model.Bind
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.Destination;
import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
/**
*
@@ -81,31 +83,46 @@ public class ServerPolicyOutFaultInterce
Destination destination = exchange.getDestination();
Exception ex = exchange.get(Exception.class);
- assert null != ex;
- BindingFaultInfo bfi = getBindingFaultInfo(msg, ex, boi);
-
- if (bfi == null
- && msg.get(FaultMode.class) != FaultMode.UNCHECKED_APPLICATION_FAULT
- && msg.get(FaultMode.class) != FaultMode.CHECKED_APPLICATION_FAULT) {
- return;
+ List<Interceptor<? extends Message>> faultInterceptors =
+ new ArrayList<Interceptor<? extends Message>>();
+ Collection<Assertion> assertions = new ArrayList<Assertion>();
+
+ // 1. Check overridden policy
+ Policy p = (Policy)msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
+ if (p != null) {
+ EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
+ EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
+ effectivePolicy.initialise(endpi, (PolicyEngineImpl)pe, false, true);
+ PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ",
+ effectivePolicy.getPolicy());
+
+ faultInterceptors.addAll(effectivePolicy.getInterceptors());
+ assertions.addAll(effectivePolicy.getChosenAlternative());
+ } else {
+ // 2. Process effective server policy
+ BindingFaultInfo bfi = getBindingFaultInfo(msg, ex, boi);
+
+ if (bfi == null
+ && msg.get(FaultMode.class) != FaultMode.UNCHECKED_APPLICATION_FAULT
+ && msg.get(FaultMode.class) != FaultMode.CHECKED_APPLICATION_FAULT) {
+ return;
+ }
+
+ EffectivePolicy effectivePolicy = pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination);
+ if (effectivePolicy != null) {
+ faultInterceptors.addAll(effectivePolicy.getInterceptors());
+ assertions.addAll(effectivePolicy.getChosenAlternative());
+ }
}
-
- EffectivePolicy effectivePolicy = pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination);
- if (effectivePolicy == null) {
- return;
- }
-
- List<Interceptor<? extends Message>> interceptors = effectivePolicy.getInterceptors();
- for (Interceptor<? extends Message> oi : interceptors) {
+ // add interceptors into message chain
+ for (Interceptor<? extends Message> oi : faultInterceptors) {
msg.getInterceptorChain().add(oi);
LOG.log(Level.FINE, "Added interceptor of type {0}", oi.getClass().getSimpleName());
}
// insert assertions of the chosen alternative into the message
-
- Collection<Assertion> assertions = effectivePolicy.getChosenAlternative();
if (null != assertions && !assertions.isEmpty()) {
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
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=1310362&r1=1310361&r2=1310362&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 Fri Apr 6 14:47:07 2012
@@ -271,9 +271,28 @@ public class EffectivePolicyImplTest ext
control.verify();
}
- @SuppressWarnings("unchecked")
@Test
public void testInitialiseOutInterceptors() {
+ testInitialiseInterceptors(false, false);
+ }
+
+ @Test
+ public void testInitialiseInInterceptors() {
+ testInitialiseInterceptors(true, false);
+ }
+
+ @Test
+ public void testInitialiseOutFaultInterceptors() {
+ testInitialiseInterceptors(false, true);
+ }
+
+ @Test
+ public void testInitialiseInFaultInterceptors() {
+ testInitialiseInterceptors(true, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void testInitialiseInterceptors(boolean useIn, boolean fault) {
EffectivePolicyImpl epi = new EffectivePolicyImpl();
List<Assertion> alternative = new ArrayList<Assertion>();
epi.setChosenAlternative(alternative);
@@ -283,18 +302,18 @@ public class EffectivePolicyImplTest ext
setupPolicyInterceptorProviderRegistry(engine, reg);
control.replay();
- epi.initialiseInterceptors(engine);
+ epi.initialiseInterceptors(engine, useIn, fault);
assertEquals(0, epi.getInterceptors().size());
control.verify();
control.reset();
setupPolicyInterceptorProviderRegistry(engine, reg);
- EasyMock.expect(reg.getOutInterceptorsForAssertion(null))
- .andReturn(new ArrayList<Interceptor<? extends Message>>());
+ List<Interceptor<? extends Message>> m = new ArrayList<Interceptor<? extends Message>>();
+ setupRegistryInterceptors(useIn, fault, reg, null, m);
PolicyAssertion a = control.createMock(PolicyAssertion.class);
alternative.add(a);
control.replay();
- epi.initialiseInterceptors(engine);
+ epi.initialiseInterceptors(engine, useIn, fault);
assertEquals(0, epi.getInterceptors().size());
control.verify();
@@ -302,10 +321,10 @@ public class EffectivePolicyImplTest ext
setupPolicyInterceptorProviderRegistry(engine, reg);
QName qn = new QName("http://x.y.z", "a");
EasyMock.expect(a.getName()).andReturn(qn);
- EasyMock.expect(reg.getOutInterceptorsForAssertion(qn))
- .andReturn(new ArrayList<Interceptor<? extends Message>>());
+ m = new ArrayList<Interceptor<? extends Message>>();
+ setupRegistryInterceptors(useIn, fault, reg, qn, m);
control.replay();
- epi.initialiseInterceptors(engine);
+ epi.initialiseInterceptors(engine, useIn, fault);
assertEquals(0, epi.getInterceptors().size());
control.verify();
@@ -313,14 +332,32 @@ public class EffectivePolicyImplTest ext
setupPolicyInterceptorProviderRegistry(engine, reg);
EasyMock.expect(a.getName()).andReturn(qn);
Interceptor<Message> pi = control.createMock(Interceptor.class);
- List<Interceptor<? extends Message>> m = new ArrayList<Interceptor<? extends Message>>();
+ m = new ArrayList<Interceptor<? extends Message>>();
m.add(pi);
- EasyMock.expect(reg.getOutInterceptorsForAssertion(qn)).andReturn(m);
+ setupRegistryInterceptors(useIn, fault, reg, qn, m);
control.replay();
- epi.initialiseInterceptors(engine);
+ epi.initialiseInterceptors(engine, useIn, fault);
assertEquals(1, epi.getInterceptors().size());
assertSame(pi, epi.getInterceptors().get(0));
- control.verify();
+ control.verify();
+ }
+
+ private void setupRegistryInterceptors(boolean useIn, boolean fault,
+ PolicyInterceptorProviderRegistry reg, QName qn,
+ List<Interceptor<? extends Message>> m) {
+ if (useIn && !fault) {
+ EasyMock.expect(reg.getInInterceptorsForAssertion(qn))
+ .andReturn(m);
+ } else if (!useIn && !fault) {
+ EasyMock.expect(reg.getOutInterceptorsForAssertion(qn))
+ .andReturn(m);
+ } else if (useIn && fault) {
+ EasyMock.expect(reg.getInFaultInterceptorsForAssertion(qn))
+ .andReturn(m);
+ } else if (!useIn && fault) {
+ EasyMock.expect(reg.getOutFaultInterceptorsForAssertion(qn))
+ .andReturn(m);
+ }
}
private void setupPolicyInterceptorProviderRegistry(PolicyEngineImpl engine,
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=1310362&r1=1310361&r2=1310362&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 Fri Apr 6 14:47:07 2012
@@ -25,6 +25,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import javax.xml.namespace.QName;
+
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.helpers.CastUtils;
@@ -50,6 +52,7 @@ import org.junit.Test;
*
*/
public class PolicyInterceptorsTest extends Assert {
+ private static final QName ASSERTION_QNAME = new QName("http://apache.cxf", "test");
private IMocksControl control;
private Message message;
@@ -58,7 +61,7 @@ public class PolicyInterceptorsTest exte
private Endpoint endpoint;
private EndpointInfo ei;
private Bus bus;
- private PolicyEngine pe;
+ private PolicyEngineImpl pe;
private Conduit conduit;
private Destination destination;
@@ -277,6 +280,96 @@ public class PolicyInterceptorsTest exte
control.verify();
}
+ @Test
+ public void testClientPolicyInInterceptorPolicyOverride() {
+ PolicyInInterceptor interceptor = new PolicyInInterceptor();
+
+ doTestBasics(interceptor, true, false);
+
+ control.reset();
+ setupMessage(true, true, true, true, true, true);
+ coachPolicyOverride(true, false);
+
+ control.replay();
+ interceptor.handleMessage(message);
+ control.verify();
+ }
+
+ @Test
+ public void testClientPolicyOutInterceptorPolicyOverride() {
+ PolicyOutInterceptor interceptor = new PolicyOutInterceptor();
+
+ doTestBasics(interceptor, true, true);
+
+ control.reset();
+ setupMessage(true, true, true, true, true, true);
+ coachPolicyOverride(false, false);
+
+ control.replay();
+ interceptor.handleMessage(message);
+ control.verify();
+ }
+
+ @Test
+ public void testServerPolicyInInterceptorPolicyOverride() {
+ PolicyInInterceptor interceptor = new PolicyInInterceptor();
+
+ doTestBasics(interceptor, false, false);
+
+ control.reset();
+ setupMessage(false, false, false, false, true, true);
+ coachPolicyOverride(true, false);
+
+ control.replay();
+ interceptor.handleMessage(message);
+ control.verify();
+ }
+
+ @Test
+ public void testServerPolicyOutInterceptorPolicyOverride() {
+ PolicyOutInterceptor interceptor = new PolicyOutInterceptor();
+
+ doTestBasics(interceptor, false, true);
+
+ control.reset();
+ setupMessage(false, false, true, true, true, true);
+ coachPolicyOverride(false, false);
+
+ control.replay();
+ interceptor.handleMessage(message);
+ control.verify();
+ }
+
+
+ @Test
+ public void testClientPolicyInFaultInterceptorPolicyOverride() {
+ ClientPolicyInFaultInterceptor interceptor = new ClientPolicyInFaultInterceptor();
+
+ doTestBasics(interceptor, true, false);
+
+ control.reset();
+ setupMessage(true, true, false, false, true, true);
+ coachPolicyOverride(true, true);
+
+ control.replay();
+ interceptor.handleMessage(message);
+ control.verify();
+ }
+
+ @Test
+ public void testServerPolicyOutFaultInterceptorPolicyOverride() {
+ ServerPolicyOutFaultInterceptor interceptor = new ServerPolicyOutFaultInterceptor();
+ doTestBasics(interceptor, false, true);
+
+ control.reset();
+ setupMessage(false, false, true, true, true, true);
+ coachPolicyOverride(false, true);
+ control.replay();
+
+ interceptor.handleMessage(message);
+ control.verify();
+ }
+
private void doTestBasics(Interceptor<Message> interceptor, boolean isClient, boolean usesOperationInfo) {
setupMessage(!isClient, isClient, usesOperationInfo, !usesOperationInfo, false, false);
control.replay();
@@ -322,7 +415,8 @@ public class PolicyInterceptorsTest exte
if (null == boi && setupOperation) {
boi = control.createMock(BindingOperationInfo.class);
}
- EasyMock.expect(exchange.get(BindingOperationInfo.class)).andReturn(setupOperation ? boi : null);
+ EasyMock.expect(exchange.get(BindingOperationInfo.class)).andReturn(setupOperation ? boi : null)
+ .anyTimes();
if (!setupOperation) {
return;
}
@@ -341,7 +435,7 @@ public class PolicyInterceptorsTest exte
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
if (null == pe && setupEngine) {
- pe = control.createMock(PolicyEngine.class);
+ pe = control.createMock(PolicyEngineImpl.class);
}
EasyMock.expect(bus.getExtension(PolicyEngine.class)).andReturn(setupEngine ? pe : null);
if (!setupEngine) {
@@ -354,8 +448,42 @@ public class PolicyInterceptorsTest exte
EasyMock.expect(exchange.getConduit(message)).andReturn(conduit).anyTimes();
} else {
destination = control.createMock(Destination.class);
- EasyMock.expect(exchange.getDestination()).andReturn(destination);
+ EasyMock.expect(exchange.getDestination()).andReturn(destination).anyTimes();
+ }
+ }
+
+ private void coachPolicyOverride(boolean in, boolean fault) {
+ Assertion assertion = control.createMock(Assertion.class);
+ EasyMock.expect(assertion.getName()).andReturn(ASSERTION_QNAME);
+ Collection<Assertion> assertions =
+ new ArrayList<Assertion>();
+ assertions.add(assertion);
+
+ Policy policyOverride = control.createMock(Policy.class);
+ EasyMock.expect(message.getContextualProperty(PolicyConstants.POLICY_OVERRIDE))
+ .andReturn(policyOverride);
+ AlternativeSelector selector = control.createMock(AlternativeSelector.class);
+ EasyMock.expect(selector.selectAlternative(policyOverride, pe, null, null)).andReturn(assertions);
+ EasyMock.expect(pe.getAlternativeSelector()).andReturn(selector);
+ EasyMock.expect(pe.getBus()).andReturn(bus).anyTimes();
+ PolicyInterceptorProviderRegistry reg = control
+ .createMock(PolicyInterceptorProviderRegistry.class);
+ EasyMock.expect(bus.getExtension(PolicyInterceptorProviderRegistry.class)).andReturn(reg);
+
+ List<Interceptor<? extends Message>> li = createMockInterceptorList();
+ if (in && fault) {
+ EasyMock.expect(reg.getInFaultInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li);
+ } else if (!in && fault) {
+ EasyMock.expect(reg.getOutFaultInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li);
+ } else if (in && !fault) {
+ EasyMock.expect(reg.getInInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li);
+ } else if (!in && !fault) {
+ EasyMock.expect(reg.getOutInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li);
}
-
+ InterceptorChain ic = control.createMock(InterceptorChain.class);
+ EasyMock.expect(message.getInterceptorChain()).andReturn(ic).anyTimes();
+ ic.add(li.get(0));
+ EasyMock.expectLastCall();
}
+
}