You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by an...@apache.org on 2007/04/06 13:21:49 UTC
svn commit: r526120 [1/2] - in /incubator/cxf/trunk:
api/src/main/java/org/apache/cxf/message/
api/src/main/java/org/apache/cxf/ws/policy/
api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/
api/src/test/java/org/apache/cxf/ws/policy/ api/src/test...
Author: andreasmyth
Date: Fri Apr 6 04:21:45 2007
New Revision: 526120
URL: http://svn.apache.org/viewvc?view=rev&rev=526120
Log:
[JIRA CXF-473] WS-Policification of HTTPClientPolicy
* Implemented AssertionBuilders for client and server policies; compatibility and equality only implemented for client policy so far.
* System test demonstrating the use of HTTPClientPolicy assertions in wsp:Policy elements attached to different subjects (port, operation, binding,...), e.g. to implement an operation specific (receive) timeout.
* HTTPConduit initialisation to respect policies (injected value takes precedence but must be compatible with endpoint specific policy).
Added:
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/AddressingPolicyTest.java
- copied, changed from r524739, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/AddressingPolicyClientServerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/HTTPClientPolicyTest.java (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/HttpGreeterImpl.java (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/PolicyLoggingInterceptor.java (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyTest.java
- copied, changed from r524739, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyClientServerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyWsdlTest.java
- copied, changed from r524739, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMWsdlPolicyClientServerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/http.xml (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/http_client_greeter.wsdl (with props)
Removed:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/AddressingPolicyClientServerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMPolicyClientServerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/RMWsdlPolicyClientServerTest.java
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageImpl.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/APIMessages.properties
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Assertor.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Intersector.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertion.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionBuilder.java
incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java
incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java
incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java
incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AbstractPolicyInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java
incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMEndpoint.java
incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMEndpointTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr.xml
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/rm.xml
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/rmwsdl.xml
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageImpl.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageImpl.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageImpl.java Fri Apr 6 04:21:45 2007
@@ -150,4 +150,10 @@
m2.setContent(c, m1.getContent(c));
}
}
+
+ public static void copyProperties(Message m1, Message m2) {
+ for (String s : m1.keySet()) {
+ m2.put(s, m1.get(s));
+ }
+ }
}
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/APIMessages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/APIMessages.properties?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/APIMessages.properties (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/APIMessages.properties Fri Apr 6 04:21:45 2007
@@ -18,4 +18,5 @@
# under the License.
#
#
-NO_ALTERNATIVE_EXC = None of the policy alternatives can be satisfied.
\ No newline at end of file
+NO_ALTERNATIVE_EXC = None of the policy alternatives can be satisfied.
+NOT_ASSERTED_EXC = Assertion of type {0} could not be asserted.
\ No newline at end of file
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AssertionInfoMap.java Fri Apr 6 04:21:45 2007
@@ -55,8 +55,7 @@
}
public boolean supportsAlternative(Collection<Assertion> alternative) {
-
- for (Assertion a : alternative) {
+ for (Assertion a : alternative) {
boolean asserted = false;
Collection<AssertionInfo> ais = get(a.getName());
if (null != ais) {
@@ -85,5 +84,16 @@
}
}
throw new PolicyException(new Message("NO_ALTERNATIVE_EXC", BUNDLE));
+ }
+
+ public void check() {
+ for (Collection<AssertionInfo> ais : values()) {
+ for (AssertionInfo ai : ais) {
+ if (!ai.isAsserted()) {
+ throw new PolicyException(new org.apache.cxf.common.i18n.Message(
+ "NOT_ASSERTED_EXC", BUNDLE, ai.getAssertion().getName()));
+ }
+ }
+ }
}
}
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Assertor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Assertor.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Assertor.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Assertor.java Fri Apr 6 04:21:45 2007
@@ -19,13 +19,17 @@
package org.apache.cxf.ws.policy;
-import org.apache.neethi.Assertion;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.message.Message;
/**
- * API used in the WS-Policy framework to check if the condition specified by the given
- * Assertion object is met.
+ * API used in the WS-Policy framework to allow a message exchange participant to
+ * assert its capabilities for the underlying message.
*/
public interface Assertor {
- boolean asserts(Assertion a);
+ void assertMessage(Message message);
+
+ boolean canAssert(QName type);
}
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Intersector.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Intersector.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Intersector.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/Intersector.java Fri Apr 6 04:21:45 2007
@@ -95,8 +95,6 @@
return true;
}
}
- System.out.println("p1 and p2 are incompatible because p2 has no alternative compatible with "
- + alt1);
return false;
}
return true;
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java Fri Apr 6 04:21:45 2007
@@ -31,6 +31,8 @@
*/
public interface PolicyEngine {
+ boolean isEnabled();
+
// available throughout the outbound path
EffectivePolicy getEffectiveClientRequestPolicy(EndpointInfo ei, BindingOperationInfo boi, Conduit c);
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertion.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertion.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertion.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertion.java Fri Apr 6 04:21:45 2007
@@ -23,7 +23,6 @@
import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
import org.apache.neethi.Assertion;
-import org.apache.neethi.PolicyComponent;
/**
@@ -46,16 +45,6 @@
public T getData() {
return data;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public boolean equal(PolicyComponent policyComponent) {
- if (!super.equal(policyComponent)) {
- return false;
- }
- JaxbAssertion<T> other = JaxbAssertion.cast((Assertion)policyComponent);
- return data.equals(other.data);
}
protected Assertion cloneMandatory() {
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionBuilder.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionBuilder.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionBuilder.java Fri Apr 6 04:21:45 2007
@@ -82,8 +82,41 @@
supportedTypes = Collections.singletonList(qn);
}
- @SuppressWarnings("unchecked")
+
public Assertion build(Element element) {
+ QName name = new QName(element.getNamespaceURI(), element.getLocalName());
+ JaxbAssertion<T> assertion = buildAssertion();
+ assertion.setName(name);
+ assertion.setOptional(getOptionality(element));
+ assertion.setData(getData(element));
+ return assertion;
+ }
+
+ public Collection<QName> getKnownElements() {
+ return supportedTypes;
+ }
+
+ public Assertion buildCompatible(Assertion a, Assertion b) {
+ return null;
+ }
+
+ protected JaxbAssertion<T> buildAssertion() {
+ return new JaxbAssertion<T>();
+ }
+
+ protected boolean getOptionality(Element element) {
+ boolean optional = false;
+ String value = element.getAttributeNS(
+ Constants.Q_ELEM_OPTIONAL_ATTR.getNamespaceURI(),
+ Constants.Q_ELEM_OPTIONAL_ATTR.getLocalPart());
+ if (Boolean.valueOf(value)) {
+ optional = true;
+ }
+ return optional;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected T getData(Element element) {
Object obj = null;
try {
obj = unmarshaller.unmarshal(element);
@@ -94,33 +127,11 @@
JAXBElement<?> el = (JAXBElement<?>)obj;
obj = el.getValue();
}
-
- if (null != obj) {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Unmarshaled element into object of type: " + obj.getClass().getName()
- + " value: " + obj);
- }
- QName name = new QName(element.getNamespaceURI(), element.getLocalName());
- boolean optional = false;
- String value = element.getAttributeNS(
- Constants.Q_ELEM_OPTIONAL_ATTR.getNamespaceURI(),
- Constants.Q_ELEM_OPTIONAL_ATTR.getLocalPart());
- if (Boolean.valueOf(value)) {
- optional = true;
- }
- JaxbAssertion<T> a = new JaxbAssertion<T>(name, optional);
- a.setData((T)obj);
- return a;
+ if (null != obj && LOG.isLoggable(Level.FINE)) {
+ LOG.fine("Unmarshaled element into object of type: " + obj.getClass().getName()
+ + " value: " + obj);
}
- return null;
- }
-
- public Collection<QName> getKnownElements() {
- return supportedTypes;
- }
-
- public Assertion buildCompatible(Assertion a, Assertion b) {
- return null;
+ return (T)obj;
}
Modified: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java (original)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java Fri Apr 6 04:21:45 2007
@@ -134,5 +134,22 @@
ci.setAsserted(true);
aim.checkEffectivePolicy(p);
- }
+ }
+
+ @Test
+ public void testCheck() throws PolicyException {
+ QName aqn = new QName("http://x.y.z", "a");
+ Assertion a = new PrimitiveAssertion(aqn);
+ Collection<Assertion> assertions = new ArrayList<Assertion>();
+ assertions.add(a);
+ AssertionInfoMap aim = new AssertionInfoMap(assertions);
+ try {
+ aim.check();
+ fail("Expected PolicyException not thrown.");
+ } catch (PolicyException ex) {
+ assertEquals("NOT_ASSERTED_EXC", ex.getCode());
+ }
+ aim.get(aqn).iterator().next().setAsserted(true);
+ aim.check();
+ }
}
Modified: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java (original)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java Fri Apr 6 04:21:45 2007
@@ -95,11 +95,7 @@
JaxbAssertion<FooType> oassertion = new JaxbAssertion<FooType>();
oassertion.setData(odata);
oassertion.setName(qn);
- assertTrue(!assertion.equal(oassertion));
-
- oassertion.setData(data);
- assertTrue(assertion.equal(assertion));
-
+ assertTrue(assertion.equal(oassertion));
assertTrue(assertion.equal(assertion));
}
Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Fri Apr 6 04:21:45 2007
@@ -34,6 +34,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.xml.namespace.QName;
+
import org.apache.cxf.Bus;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.Base64Utility;
@@ -53,8 +55,11 @@
import org.apache.cxf.transport.DestinationFactory;
import org.apache.cxf.transport.DestinationFactoryManager;
import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.http.policy.PolicyUtils;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.cxf.ws.policy.Assertor;
+import org.apache.cxf.ws.policy.PolicyEngine;
import org.apache.cxf.wsdl.EndpointReferenceUtils;
import static org.apache.cxf.message.Message.DECOUPLED_CHANNEL_MESSAGE;
@@ -63,7 +68,7 @@
/**
* HTTP Conduit implementation.
*/
-public class HTTPConduit extends AbstractConduit implements Configurable {
+public class HTTPConduit extends AbstractConduit implements Configurable, Assertor {
public static final String HTTP_CONNECTION = "http.connection";
private static final Logger LOG = LogUtils.getL7dLogger(HTTPConduit.class);
@@ -157,13 +162,16 @@
*/
public void prepare(Message message) throws IOException {
Map<String, List<String>> headers = setHeaders(message);
- URL currentURL = setupURL(message);
+ URL currentURL = setupURL(message);
+ HTTPClientPolicy clientPolicy = getClient(message);
URLConnection connection =
- connectionFactory.createConnection(getProxy(), currentURL);
- connection.setDoOutput(true);
- //TODO using Message context to deceided HTTP send properties
- connection.setConnectTimeout((int)getClient().getConnectionTimeout());
- connection.setReadTimeout((int)getClient().getReceiveTimeout());
+ connectionFactory.createConnection(getProxy(clientPolicy), currentURL);
+ connection.setDoOutput(true);
+
+ //TODO using Message context to deceided HTTP send properties
+
+ connection.setConnectTimeout((int)clientPolicy.getConnectionTimeout());
+ connection.setReadTimeout((int)clientPolicy.getReceiveTimeout());
connection.setUseCaches(false);
if (connection instanceof HttpURLConnection) {
@@ -174,14 +182,14 @@
} else {
hc.setRequestMethod("POST");
}
- if (getClient().isAutoRedirect()) {
+ if (clientPolicy.isAutoRedirect()) {
//cannot use chunking if autoredirect as the request will need to be
//completely cached locally and resent to the redirect target
hc.setInstanceFollowRedirects(true);
} else {
hc.setInstanceFollowRedirects(false);
if (!hc.getRequestMethod().equals("GET")
- && getClient().isAllowChunking()) {
+ && clientPolicy.isAllowChunking()) {
hc.setChunkedStreamingMode(2048);
}
}
@@ -404,16 +412,26 @@
private void initConfig() {
//Initialize some default values for the configuration
- client = endpointInfo.getTraversedExtensor(new HTTPClientPolicy(), HTTPClientPolicy.class);
+
+ // wsdl extensors are superseded by policies which in turn are superseded by injection
+
+ PolicyEngine pe = bus.getExtension(PolicyEngine.class);
+ if (null != pe && pe.isEnabled()) {
+ client = PolicyUtils.getClient(pe, endpointInfo, this);
+ }
+
+ if (null == client) {
+ client = endpointInfo.getTraversedExtensor(new HTTPClientPolicy(), HTTPClientPolicy.class);
+ }
+
authorization = endpointInfo.getTraversedExtensor(new AuthorizationPolicy(),
AuthorizationPolicy.class);
proxyAuthorization = endpointInfo.getTraversedExtensor(new AuthorizationPolicy(),
AuthorizationPolicy.class);
}
- private Proxy getProxy() {
- Proxy proxy = null;
- HTTPClientPolicy policy = getClient();
+ private Proxy getProxy(HTTPClientPolicy policy) {
+ Proxy proxy = null;
if (policy.isSetProxyServer()) {
proxy = new Proxy(Proxy.Type.valueOf(policy.getProxyServerType().toString()),
new InetSocketAddress(policy.getProxyServer(),
@@ -475,7 +493,7 @@
Arrays.asList(new String[] {type}));
}
}
- HTTPClientPolicy policy = getClient();
+ HTTPClientPolicy policy = getClient(message);
if (policy.isSetCacheControl()) {
headers.put("Cache-Control",
Arrays.asList(new String[] {policy.getCacheControl().value()}));
@@ -532,6 +550,10 @@
public void setAuthorization(AuthorizationPolicy authorization) {
this.authorization = authorization;
}
+
+ public HTTPClientPolicy getClient(Message message) {
+ return PolicyUtils.getClient(message, client);
+ }
public HTTPClientPolicy getClient() {
return client;
@@ -662,6 +684,14 @@
incomingObserver.onMessage(inMessage);
}
+ }
+
+ public void assertMessage(Message message) {
+ PolicyUtils.assertClientPolicy(message, client);
+ }
+
+ public boolean canAssert(QName type) {
+ return PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(type);
}
}
Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/HTTPClientAssertionBuilder.java Fri Apr 6 04:21:45 2007
@@ -25,6 +25,7 @@
import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertionBuilder;
import org.apache.neethi.Assertion;
+import org.apache.neethi.PolicyComponent;
/**
*
@@ -32,7 +33,7 @@
public class HTTPClientAssertionBuilder extends JaxbAssertionBuilder<HTTPClientPolicy> {
public HTTPClientAssertionBuilder() throws JAXBException {
- super(HTTPClientPolicy.class, PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME);
+ super(HTTPClientPolicy.class, PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME);
}
@Override
@@ -54,7 +55,28 @@
}
return null;
}
+
+ @Override
+ protected JaxbAssertion<HTTPClientPolicy> buildAssertion() {
+ return new HTTPClientPolicyAssertion();
+ }
-
+ class HTTPClientPolicyAssertion extends JaxbAssertion<HTTPClientPolicy> {
+ HTTPClientPolicyAssertion() {
+ super(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, false);
+ }
+ @Override
+ public boolean equal(PolicyComponent policyComponent) {
+ if (!super.equal(policyComponent)) {
+ return false;
+ }
+ JaxbAssertion<HTTPClientPolicy> other = JaxbAssertion.cast((Assertion)policyComponent);
+ return PolicyUtils.equals(this.getData(), other.getData());
+ }
+ }
+
+
+
+
}
Added: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties?view=auto&rev=526120
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties (added)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties Fri Apr 6 04:21:45 2007
@@ -0,0 +1,21 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS = Incompatible HTTPClientPolicy assertions.
Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/Messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/policy/PolicyUtils.java Fri Apr 6 04:21:45 2007
@@ -19,19 +19,24 @@
package org.apache.cxf.transport.http.policy;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.xml.namespace.QName;
-import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
import org.apache.cxf.ws.policy.AssertionInfo;
import org.apache.cxf.ws.policy.AssertionInfoMap;
import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.cxf.ws.policy.PolicyException;
import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
import org.apache.neethi.Assertion;
@@ -43,9 +48,11 @@
public static final String HTTPCONF_NAMESPACE =
"http://cxf.apache.org/transports/http/configuration";
public static final QName HTTPCLIENTPOLICY_ASSERTION_QNAME =
- new QName(HTTPCONF_NAMESPACE, "HTTPClientPolicy");
+ new QName(HTTPCONF_NAMESPACE, "client");
public static final QName HTTPSERVERPOLICY_ASSERTION_QNAME =
- new QName(HTTPCONF_NAMESPACE, "HTTPServerPolicy");
+ new QName(HTTPCONF_NAMESPACE, "server");
+
+ private static final Logger LOG = LogUtils.getL7dLogger(PolicyUtils.class);
/**
* Prevents instantiation.
@@ -56,112 +63,84 @@
/**
- * Returns the HTTPClientPolicy for the specified message or null if no assertions of this type
- * pertain to the underlying message.
- * If on the other hand there is more than one such assertion, the first one is taken.
- * TODO:
- * This should be replaced by computing an merged assertion if this is possible, e.g. one in
- * which the connection timeout is set to be to the minimum of all connections timeouts.
- * If there are conflicting assertions, resulting e.g. from a client element that is included
- * in a policy attached to the endpoint and another client element, included in a policy
- * attached to the underlying message, in which chunking is disallowed, a exception should be thrown.
- *
+ * Returns a HTTPClientPolicy that is compatible with the assertions included in the
+ * service, endpoint, operation and message policy subjects AND the HTTPClientPolicy configured
+ * for the conduit.
* @param message the message
* @return the HTTPClientPolicy for the message
*/
- public static HTTPClientPolicy getClient(Message message) {
+ public static HTTPClientPolicy getClient(Message message, HTTPClientPolicy confPolicy) {
AssertionInfoMap amap = message.get(AssertionInfoMap.class);
if (null == amap) {
- return null;
+ return confPolicy;
}
Collection<AssertionInfo> ais = amap.get(HTTPCLIENTPOLICY_ASSERTION_QNAME);
- if (null != ais) {
- for (AssertionInfo ai : ais) {
- JaxbAssertion<HTTPClientPolicy> ja =
- JaxbAssertion.cast(ai.getAssertion(), HTTPClientPolicy.class);
- return ja.getData();
- }
- }
- return null;
- }
-
- /**
- * Returns the HTTPServerPolicy for the specified message or null if no assertions of this type
- * pertain to the underlying message.
- */
- public static HTTPServerPolicy getServer(Message message) {
- AssertionInfoMap amap = message.get(AssertionInfoMap.class);
- if (null == amap) {
- return null;
+ if (null == ais) {
+ return confPolicy;
}
- Collection<AssertionInfo> ais = amap.get(HTTPSERVERPOLICY_ASSERTION_QNAME);
- if (null != ais) {
- for (AssertionInfo ai : ais) {
- JaxbAssertion<HTTPServerPolicy> ja =
- JaxbAssertion.cast(ai.getAssertion(), HTTPServerPolicy.class);
- return ja.getData();
+ Collection<Assertion> alternative = new ArrayList<Assertion>();
+ for (AssertionInfo ai : ais) {
+ alternative.add(ai.getAssertion());
+ }
+ HTTPClientPolicy compatible = getClient(alternative);
+ if (null != compatible && null != confPolicy) {
+ if (PolicyUtils.compatible(compatible, confPolicy)) {
+ compatible = intersect(compatible, confPolicy);
+ } else {
+ LogUtils.log(LOG, Level.SEVERE, "INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS");
+ throw new PolicyException(new org.apache.cxf.common.i18n.Message(
+ "INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS", LOG));
}
}
- return null;
+ return compatible;
}
/**
- * Returns the first HTTPClientPolicy element specified in the http client policy assertions
- * or null if there are no such assertions.
- * TODO: Return a merged value if there are multiple such assertions, or report conflict
+ * Returns a HTTPClientPolicy that is compatible with the assertions included in the
+ * service and endpoint policy subjects, or null if there are no such assertions.
*/
- public static HTTPClientPolicy getClient(Collection<Assertion> alternative) {
+ public static HTTPClientPolicy getClient(PolicyEngine pe, EndpointInfo ei, Conduit c) {
+ Collection<Assertion> alternative = pe.getClientEndpointPolicy(ei, c).getChosenAlternative();
+
+ HTTPClientPolicy compatible = null;
for (Assertion a : alternative) {
if (HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(a.getName())) {
- return JaxbAssertion.cast(a, HTTPClientPolicy.class).getData();
- }
- }
- return null;
- }
-
- /**
- * Returns the first HTTPServerPolicy element specified in the http client policy assertions
- * or null if there are no such assertions.
- * TODO: Return a merged value if there are multiple such assertions, or report conflict
- */
- public static HTTPServerPolicy getServer(Collection<Assertion> alternative) {
- for (Assertion a : alternative) {
- if (HTTPSERVERPOLICY_ASSERTION_QNAME.equals(a.getName())) {
- return JaxbAssertion.cast(a, HTTPServerPolicy.class).getData();
+ HTTPClientPolicy p = JaxbAssertion.cast(a, HTTPClientPolicy.class).getData();
+ if (null == compatible) {
+ compatible = p;
+ } else {
+ compatible = intersect(compatible, p);
+ if (null == compatible) {
+ LogUtils.log(LOG, Level.SEVERE, "INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS");
+ throw new PolicyException(new org.apache.cxf.common.i18n.Message(
+ "INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS", LOG));
+ }
+ }
}
}
- return null;
+ return compatible;
+
}
- public static void assertClientPolicy(PolicyEngine engine, Message message) {
+ public static void assertClientPolicy(Message message, HTTPClientPolicy client) {
+
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
return;
}
- Collection<AssertionInfo> ais = aim.get(HTTPCLIENTPOLICY_ASSERTION_QNAME);
+ Collection<AssertionInfo> ais = aim.get(HTTPCLIENTPOLICY_ASSERTION_QNAME);
if (null == ais || ais.size() == 0) {
return;
- }
+ }
- // assert the endpoint level assertion(s) and any message specific ones that are compatible
- // with these
+ // assert all assertion(s) that are compatible with the value configured for the conduit
- if (MessageUtils.isOutbound(message)) {
- System.out.println("message is outbound");
- Endpoint e = message.getExchange().get(Endpoint.class);
- EndpointInfo ei = e.getEndpointInfo();
- Collection<Assertion> endpointAssertions = engine.getClientEndpointPolicy(ei, null)
- .getChosenAlternative();
- for (Assertion a : endpointAssertions) {
- if (HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(a.getName())) {
- HTTPClientPolicy p1 = (JaxbAssertion.cast(a, HTTPClientPolicy.class)).getData();
- for (AssertionInfo ai : ais) {
- HTTPClientPolicy p2 = (JaxbAssertion.cast(ai.getAssertion(),
- HTTPClientPolicy.class)).getData();
- if (compatible(p1, p2)) {
- ai.setAsserted(true);
- }
- }
+ if (MessageUtils.isOutbound(message)) {
+ for (AssertionInfo ai : ais) {
+ HTTPClientPolicy p = (JaxbAssertion.cast(ai.getAssertion(),
+ HTTPClientPolicy.class)).getData();
+ if (compatible(p, client)) {
+ ai.setAsserted(true);
}
}
} else {
@@ -434,7 +413,80 @@
return s1 == null ? s2 : s1;
}
+ private static boolean equals(String s1, String s2) {
+ return s1 == null ? s2 == null : s1.equals(s2);
+ }
+
private static boolean compatible(String s1, String s2) {
return s1 == null || s2 == null || s1.equals(s2);
+ }
+
+ private static HTTPClientPolicy getClient(Collection<Assertion> alternative) {
+ HTTPClientPolicy compatible = null;
+ for (Assertion a : alternative) {
+ if (HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(a.getName())) {
+ HTTPClientPolicy p = JaxbAssertion.cast(a, HTTPClientPolicy.class).getData();
+ if (null == compatible) {
+ compatible = p;
+ } else {
+ compatible = intersect(compatible, p);
+ if (null == compatible) {
+ LogUtils.log(LOG, Level.SEVERE, "INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS");
+ org.apache.cxf.common.i18n.Message m =
+ new org.apache.cxf.common.i18n.Message(
+ "INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS", LOG);
+ throw new PolicyException(m);
+ }
+ }
+ }
+ }
+ return compatible;
+ }
+
+ public static String toString(HTTPClientPolicy p) {
+ StringBuffer buf = new StringBuffer();
+ buf.append(p);
+ buf.append("[DecoupledEndpoint=\"");
+ buf.append(p.getDecoupledEndpoint());
+ buf.append("\", ReceiveTimeout=");
+ buf.append(p.getReceiveTimeout());
+ buf.append("])");
+ return buf.toString();
+
+ }
+
+ public static boolean equals(HTTPClientPolicy p1, HTTPClientPolicy p2) {
+ if (p1 == p2) {
+ return true;
+ }
+ boolean result = true;
+ result &= p1.isAllowChunking() == p2.isAllowChunking()
+ && p1.isAutoRedirect() == p2.isAutoRedirect()
+ && equals(p1.getAccept(), p2.getAccept())
+ && equals(p1.getAcceptEncoding(), p2.getAcceptEncoding())
+ && equals(p1.getAcceptLanguage(), p2.getAcceptLanguage())
+ && equals(p1.getBrowserType(), p2.getBrowserType());
+ if (!result) {
+ return false;
+ }
+
+ result &= p1.getCacheControl() == null
+ ? p2.getCacheControl() == null
+ : p1.getCacheControl().value().equals(p2.getCacheControl().value())
+ && p1.getConnection().value().equals(p2.getConnection().value())
+ && p1.getConnectionTimeout() == p2.getConnectionTimeout()
+ && equals(p1.getContentType(), p2.getContentType())
+ && equals(p1.getCookie(), p2.getCookie())
+ && equals(p1.getDecoupledEndpoint(), p2.getDecoupledEndpoint())
+ && equals(p1.getHost(), p2.getHost());
+ if (!result) {
+ return false;
+ }
+ result &= equals(p1.getProxyServer(), p2.getProxyServer())
+ && p1.getProxyServerPort() == p2.getProxyServerPort()
+ && p1.getProxyServerType().value().equals(p2.getProxyServerType().value())
+ && p1.getReceiveTimeout() == p2.getReceiveTimeout()
+ && equals(p1.getReferer(), p2.getReferer());
+ return result;
}
}
Modified: incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java (original)
+++ incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/policy/PolicyUtilsTest.java Fri Apr 6 04:21:45 2007
@@ -23,17 +23,13 @@
import java.util.Collection;
import java.util.Collections;
-import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
-import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
import org.apache.cxf.ws.policy.AssertionInfo;
import org.apache.cxf.ws.policy.AssertionInfoMap;
-import org.apache.cxf.ws.policy.EndpointPolicy;
-import org.apache.cxf.ws.policy.PolicyEngine;
import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
import org.apache.neethi.Assertion;
import org.easymock.classextension.EasyMock;
@@ -133,7 +129,7 @@
Message message = control.createMock(Message.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
control.replay();
- PolicyUtils.assertClientPolicy(null, message);
+ PolicyUtils.assertClientPolicy(message, null);
control.verify();
control.reset();
@@ -141,7 +137,7 @@
AssertionInfoMap aim = new AssertionInfoMap(as);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
control.replay();
- PolicyUtils.assertClientPolicy(null, message);
+ PolicyUtils.assertClientPolicy(message, null);
control.verify();
}
@@ -157,9 +153,9 @@
void testAssertClientPolicy(boolean outbound) {
Message message = control.createMock(Message.class);
- PolicyEngine pe = control.createMock(PolicyEngine.class);
HTTPClientPolicy ep = new HTTPClientPolicy();
HTTPClientPolicy cmp = new HTTPClientPolicy();
+
cmp.setConnectionTimeout(60000L);
HTTPClientPolicy icmp = new HTTPClientPolicy();
icmp.setAllowChunking(false);
@@ -186,23 +182,14 @@
aim.put(PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME, ais);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
Exchange ex = control.createMock(Exchange.class);
- EasyMock.expect(message.getExchange()).andReturn(ex).times(outbound ? 2 : 1);
+ EasyMock.expect(message.getExchange()).andReturn(ex);
EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null);
if (!outbound) {
EasyMock.expect(ex.getOutFaultMessage()).andReturn(null);
- } else {
- Endpoint e = control.createMock(Endpoint.class);
- EasyMock.expect(ex.get(Endpoint.class)).andReturn(e);
- EndpointInfo ei = control.createMock(EndpointInfo.class);
- EasyMock.expect(e.getEndpointInfo()).andReturn(ei);
- EndpointPolicy endpointPolicy = control.createMock(EndpointPolicy.class);
- EasyMock.expect(pe.getClientEndpointPolicy(ei, null)).andReturn(endpointPolicy);
- Collection<Assertion> alt = CastUtils.cast(Collections.singleton(ea), Assertion.class);
- EasyMock.expect(endpointPolicy.getChosenAlternative()).andReturn(alt);
}
control.replay();
- PolicyUtils.assertClientPolicy(pe, message);
+ PolicyUtils.assertClientPolicy(message, ep);
assertTrue(eai.isAsserted());
assertTrue(cmai.isAsserted());
assertTrue(outbound ? !icmai.isAsserted() : icmai.isAsserted());
Modified: incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml (original)
+++ incubator/cxf/trunk/rt/ws/addr/src/main/resources/META-INF/cxf/cxf-extension-addr.xml Fri Apr 6 04:21:45 2007
@@ -38,6 +38,7 @@
</property>
<property name="inFaultInterceptors">
<list>
+ <ref bean="org.apache.cxf.ws.addressing.soap.MAPCodec"/>
<ref bean="org.apache.cxf.ws.addressing.MAPAggregator"/>
</list>
</property>
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AbstractPolicyInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AbstractPolicyInterceptor.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AbstractPolicyInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/AbstractPolicyInterceptor.java Fri Apr 6 04:21:45 2007
@@ -20,10 +20,13 @@
package org.apache.cxf.ws.policy;
import org.apache.cxf.Bus;
+import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.service.model.BindingFaultInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.Destination;
/**
*
@@ -38,6 +41,23 @@
public Bus getBus() {
return bus;
+ }
+
+ protected void getTransportAssertions(Message message) {
+ Exchange ex = message.getExchange();
+ Assertor assertor = null;
+ Conduit conduit = ex.getConduit();
+ if (conduit instanceof Assertor) {
+ assertor = (Assertor)conduit;
+ } else {
+ Destination destination = ex.getDestination();
+ if (destination instanceof Assertor) {
+ assertor = (Assertor)destination;
+ }
+ }
+ if (null != assertor) {
+ assertor.assertMessage(message);
+ }
}
protected BindingFaultInfo getBindingFaultInfo(Message msg, Exception ex, BindingOperationInfo boi) {
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java Fri Apr 6 04:21:45 2007
@@ -68,14 +68,17 @@
return;
}
- Conduit conduit = msg.getConduit();
+ Conduit conduit = exchange.getConduit();
+ 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);
+ EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit);
+ LOG.fine("ep: " + ep);
List<Interceptor> faultInterceptors = ep.getFaultInterceptors();
+ LOG.fine("faultInterceptors: " + faultInterceptors);
for (Interceptor i : faultInterceptors) {
msg.getInterceptorChain().add(i);
LOG.log(Level.INFO, "Added interceptor of type {0}", i.getClass().getSimpleName());
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java Fri Apr 6 04:21:45 2007
@@ -68,7 +68,7 @@
return;
}
- Conduit conduit = msg.getConduit();
+ Conduit conduit = exchange.getConduit();
// 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.
@@ -87,6 +87,8 @@
if (null != assertions) {
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
+
+ // if the conduit implements the Assertor interface,
}
}
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java Fri Apr 6 04:21:45 2007
@@ -75,12 +75,12 @@
return;
}
- Conduit conduit = msg.getConduit();
+ Conduit conduit = exchange.getConduit();
// add the required interceptors
EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(ei, boi, conduit);
- PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
+ PolicyUtils.logPolicy(LOG, Level.FINE, "Using effective policy: ", effectivePolicy.getPolicy());
List<Interceptor> interceptors = effectivePolicy.getInterceptors();
for (Interceptor i : interceptors) {
@@ -92,6 +92,14 @@
Collection<Assertion> assertions = effectivePolicy.getChosenAlternative();
if (null != assertions) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("Chosen alternative: ");
+ String nl = System.getProperty("line.separator");
+ buf.append(nl);
+ for (Assertion a : assertions) {
+ PolicyUtils.printPolicyComponent(a, buf, 1);
+ }
+ LOG.fine(buf.toString());
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
}
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java Fri Apr 6 04:21:45 2007
@@ -24,11 +24,14 @@
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.service.model.BindingFaultInfo;
@@ -45,7 +48,8 @@
*/
public class EffectivePolicyImpl implements EffectivePolicy {
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(EffectivePolicyImpl.class);
+ private static final ResourceBundle BUNDLE = BundleUtils.getBundle(EffectivePolicyImpl.class);
+ private static final Logger LOG = LogUtils.getL7dLogger(EffectivePolicyImpl.class);
protected Policy policy;
protected Collection<Assertion> chosenAlternative;
@@ -124,6 +128,7 @@
return;
}
}
+ PolicyUtils.logPolicy(LOG, Level.FINE, "No alternative supported.", getPolicy());
throw new PolicyException(new Message("NO_ALTERNATIVE_EXC", BUNDLE));
}
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties Fri Apr 6 04:21:45 2007
@@ -23,5 +23,4 @@
NOT_A_POLICY_ELEMENT_EXC = Specified element is not a Policy element.
NOT_A_POLICYREF_ELEMENT_EXC = Specified element is not a PolicyReference element.
NO_ALTERNATIVE_EXC = None of the policy alternatives can be satisfied.
-UNRESOLVED_POLICY_REEFERENCE_EXC = Policy reference {0} could not be resolved.
-NOT_ASSERTED_EXC = Assertion of type {0} could not be asserted.
\ No newline at end of file
+UNRESOLVED_POLICY_REEFERENCE_EXC = Policy reference {0} could not be resolved.
\ No newline at end of file
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java Fri Apr 6 04:21:45 2007
@@ -56,7 +56,7 @@
private Bus bus;
private PolicyRegistry registry;
private Collection<PolicyProvider> policyProviders;
- private boolean registerInterceptors;
+ private boolean enabled;
private Map<BindingOperation, EffectivePolicy> clientRequestInfo;
@@ -78,6 +78,10 @@
// configuration
+ public boolean isEnabled() {
+ return enabled;
+ }
+
public void setBus(Bus b) {
bus = b;
}
@@ -101,13 +105,9 @@
public PolicyRegistry getRegistry() {
return registry;
}
-
- public boolean getRegisterInterceptors() {
- return registerInterceptors;
- }
- public void setRegisterInterceptors(boolean ri) {
- registerInterceptors = ri;
+ public void setEnabled(boolean e) {
+ enabled = e;
}
// BusExtension interface
@@ -128,7 +128,7 @@
if (c instanceof Assertor) {
assertor = (Assertor)c;
}
- epi.initialise(ei, boi, this, assertor, true);
+ epi.initialise(ei, bo.getBindingOperation(), this, assertor, true);
clientRequestInfo.put(bo, epi);
effectivePolicy = epi;
}
@@ -151,7 +151,7 @@
if (d instanceof Assertor) {
assertor = (Assertor)d;
}
- epi.initialise(ei, boi, this, assertor, false);
+ epi.initialise(ei, bo.getBindingOperation(), this, assertor, false);
serverResponseInfo.put(bo, epi);
effectivePolicy = epi;
}
@@ -213,7 +213,7 @@
EffectivePolicy effectivePolicy = serverRequestInfo.get(bo);
if (null == effectivePolicy) {
EffectivePolicyImpl epi = createOutPolicyInfo();
- epi.initialisePolicy(ei, boi, this, false);
+ epi.initialisePolicy(ei, bo.getBindingOperation(), this, false);
serverRequestInfo.put(bo, epi);
effectivePolicy = epi;
}
@@ -231,7 +231,7 @@
EffectivePolicy effectivePolicy = clientResponseInfo.get(bo);
if (null == effectivePolicy) {
EffectivePolicyImpl epi = createOutPolicyInfo();
- epi.initialisePolicy(ei, boi, this, true);
+ epi.initialisePolicy(ei, bo.getBindingOperation(), this, true);
clientResponseInfo.put(bo, epi);
effectivePolicy = epi;
}
@@ -293,7 +293,7 @@
@PostConstruct
public void addBusInterceptors() {
- if (null == bus || !registerInterceptors) {
+ if (null == bus || !enabled) {
return;
}
@@ -454,10 +454,7 @@
vocabulary.add(a.getName());
}
return vocabulary;
- }
-
-
-
+ }
EndpointPolicyImpl createEndpointPolicyInfo(EndpointInfo ei, boolean isRequestor, Assertor assertor) {
EndpointPolicyImpl epi = createEndpointPolicyInfo();
@@ -465,11 +462,7 @@
endpointInfo.put(ei, epi);
return epi;
- }
-
-
-
-
+ }
/**
* Check if a given list of assertions can potentially be supported by
@@ -485,7 +478,7 @@
for (Assertion a : alternative) {
if (!(a.isOptional()
|| (null != pipr.get(a.getName()))
- || (null != assertor && assertor.asserts(a)))) {
+ || (null != assertor && assertor.canAssert(a.getName())))) {
return false;
}
}
@@ -497,12 +490,20 @@
* Class used as key in the client request policy and server response policy maps.
*/
class BindingOperation {
- EndpointInfo ei;
- BindingOperationInfo boi;
+ private EndpointInfo ei;
+ private BindingOperationInfo boi;
BindingOperation(EndpointInfo e, BindingOperationInfo b) {
ei = e;
- boi = b;
+ boi = b.isUnwrapped() ? b.getWrappedOperation() : b;
+ }
+
+ EndpointInfo getEndpoint() {
+ return ei;
+ }
+
+ BindingOperationInfo getBindingOperation() {
+ return boi;
}
@Override
@@ -528,12 +529,20 @@
* Class used as key in the server fault policy map.
*/
class BindingFault {
- EndpointInfo ei;
- BindingFaultInfo bfi;
+ private EndpointInfo ei;
+ private BindingFaultInfo bfi;
BindingFault(EndpointInfo e, BindingFaultInfo b) {
ei = e;
bfi = b;
+ }
+
+ EndpointInfo getEndpoint() {
+ return ei;
+ }
+
+ BindingFaultInfo getBindingFault() {
+ return bfi;
}
@Override
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java Fri Apr 6 04:21:45 2007
@@ -107,6 +107,9 @@
if (((Assertion)pc).isOptional()) {
buf.append(" (optional)");
}
+ buf.append(" (");
+ buf.append((Assertion)pc);
+ buf.append(")");
nl(buf);
if (pc instanceof NestedPrimitiveAssertion) {
PolicyComponent nested = ((NestedPrimitiveAssertion)pc).getNested();
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptor.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptor.java Fri Apr 6 04:21:45 2007
@@ -53,6 +53,7 @@
public void handleMessage(Message message) throws Fault {
if (!MessageUtils.isRequestor(message)) {
+ LOG.fine("Not a requestor.");
return;
}
@@ -80,7 +81,7 @@
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
return;
- }
+ }
Exception ex = message.getContent(Exception.class);
if (null == ex) {
@@ -93,6 +94,8 @@
LOG.fine("No binding fault info.");
return;
}
+
+ getTransportAssertions(message);
EffectivePolicy effectivePolicy = pe.getEffectiveClientFaultPolicy(ei, bfi);
aim.checkEffectivePolicy(effectivePolicy.getPolicy());
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptor.java Fri Apr 6 04:21:45 2007
@@ -80,6 +80,8 @@
return;
}
+ getTransportAssertions(message);
+
EffectivePolicy effectivePolicy = null;
if (MessageUtils.isRequestor(message)) {
effectivePolicy = pe.getEffectiveClientResponsePolicy(ei, boi);
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptor.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptor.java Fri Apr 6 04:21:45 2007
@@ -19,13 +19,9 @@
package org.apache.cxf.ws.policy;
-import java.util.Collection;
-import java.util.ResourceBundle;
import java.util.logging.Logger;
-import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.phase.Phase;
@@ -37,9 +33,6 @@
private static final Logger LOG
= LogUtils.getL7dLogger(PolicyVerificationOutInterceptor.class);
- private static final ResourceBundle BUNDLE
- = BundleUtils.getBundle(PolicyVerificationOutInterceptor.class);
-
public PolicyVerificationOutInterceptor() {
setPhase(Phase.POST_STREAM);
}
@@ -51,7 +44,7 @@
* to predict if these interceptors actually have asserted their assertions.
* @param message
*/
- public void handleMessage(Message message) throws Fault {
+ public void handleMessage(Message message) {
if (MessageUtils.isPartialResponse(message)) {
LOG.fine("Not verifying policies on outbound partial response.");
@@ -62,14 +55,11 @@
if (null == aim) {
return;
}
- for (Collection<AssertionInfo> ais : aim.values()) {
- for (AssertionInfo ai : ais) {
- if (!ai.isAsserted()) {
- throw new PolicyException(new org.apache.cxf.common.i18n.Message(
- "NOT_ASSERTED_EXC", BUNDLE, ai.getAssertion().getName()));
- }
- }
- }
+
+ getTransportAssertions(message);
+
+ aim.check();
+
LOG.fine("Verified policies for outbound message.");
}
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java Fri Apr 6 04:21:45 2007
@@ -72,18 +72,18 @@
assertNotNull(engine.getRegistry());
assertNull(engine.getBus());
assertNull(engine.getPolicyProviders());
- assertTrue(!engine.getRegisterInterceptors());
+ assertTrue(!engine.isEnabled());
Bus bus = control.createMock(Bus.class);
engine.setBus(bus);
List<PolicyProvider> providers = CastUtils.cast(Collections.EMPTY_LIST, PolicyProvider.class);
engine.setPolicyProviders(providers);
PolicyRegistry reg = control.createMock(PolicyRegistry.class);
engine.setRegistry(reg);
- engine.setRegisterInterceptors(true);
+ engine.setEnabled(true);
assertSame(bus, engine.getBus());
assertSame(providers, engine.getPolicyProviders());
assertSame(reg, engine.getRegistry());
- assertTrue(engine.getRegisterInterceptors());
+ assertTrue(engine.isEnabled());
assertNotNull(engine.createOutPolicyInfo());
assertNotNull(engine.createEndpointPolicyInfo());
@@ -112,10 +112,13 @@
engine = new PolicyEngineImpl();
EndpointInfo ei = control.createMock(EndpointInfo.class);
BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+ EasyMock.expect(boi.isUnwrapped()).andReturn(false).times(2);
EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
+ control.replay();
engine.setEffectiveClientRequestPolicy(ei, boi, effectivePolicy);
assertSame(effectivePolicy,
- engine.getEffectiveClientRequestPolicy(ei, boi, (Conduit)null));
+ engine.getEffectiveClientRequestPolicy(ei, boi, (Conduit)null));
+ control.verify();
}
@Test
@@ -141,10 +144,13 @@
engine = new PolicyEngineImpl();
EndpointInfo ei = control.createMock(EndpointInfo.class);
BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+ EasyMock.expect(boi.isUnwrapped()).andReturn(false).times(2);
EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
+ control.replay();
engine.setEffectiveServerResponsePolicy(ei, boi, effectivePolicy);
assertSame(effectivePolicy,
- engine.getEffectiveServerResponsePolicy(ei, boi, (Destination)null));
+ engine.getEffectiveServerResponsePolicy(ei, boi, (Destination)null));
+ control.verify();
}
@Test
@@ -197,9 +203,12 @@
engine = new PolicyEngineImpl();
EndpointInfo ei = control.createMock(EndpointInfo.class);
BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+ EasyMock.expect(boi.isUnwrapped()).andReturn(false).times(2);
EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
+ control.replay();
engine.setEffectiveServerRequestPolicy(ei, boi, effectivePolicy);
- assertSame(effectivePolicy, engine.getEffectiveServerRequestPolicy(ei, boi));
+ assertSame(effectivePolicy, engine.getEffectiveServerRequestPolicy(ei, boi));
+ control.verify();
}
@Test
@@ -224,9 +233,12 @@
engine = new PolicyEngineImpl();
EndpointInfo ei = control.createMock(EndpointInfo.class);
BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+ EasyMock.expect(boi.isUnwrapped()).andReturn(false).times(2);
EffectivePolicy epi = control.createMock(EffectivePolicy.class);
+ control.replay();
engine.setEffectiveClientResponsePolicy(ei, boi, epi);
- assertSame(epi, engine.getEffectiveClientResponsePolicy(ei, boi));
+ assertSame(epi, engine.getEffectiveClientResponsePolicy(ei, boi));
+ control.verify();
}
@Test
@@ -323,9 +335,9 @@
doTestAddBusInterceptors(true);
}
- private void doTestAddBusInterceptors(boolean add) {
+ private void doTestAddBusInterceptors(boolean enabled) {
engine = new PolicyEngineImpl();
- engine.setRegisterInterceptors(add);
+ engine.setEnabled(enabled);
Bus bus = control.createMock(Bus.class);
engine.setBus(bus);
@@ -333,7 +345,7 @@
List<Interceptor> in = new ArrayList<Interceptor>();
List<Interceptor> inFault = new ArrayList<Interceptor>();
List<Interceptor> outFault = new ArrayList<Interceptor>();
- if (add) {
+ if (enabled) {
EasyMock.expect(bus.getOutInterceptors()).andReturn(out).times(3);
EasyMock.expect(bus.getInInterceptors()).andReturn(in).times(3);
EasyMock.expect(bus.getInFaultInterceptors()).andReturn(inFault).times(2);
@@ -343,7 +355,7 @@
engine.addBusInterceptors();
- if (add) {
+ if (enabled) {
Set<String> idsOut = getInterceptorIds(out);
Set<String> idsIn = getInterceptorIds(in);
Set<String> idsInFault = getInterceptorIds(inFault);
@@ -367,7 +379,7 @@
assertEquals(0, inFault.size());
assertEquals(0, outFault.size());
}
- if (add) {
+ if (enabled) {
control.verify();
}
}
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java Fri Apr 6 04:21:45 2007
@@ -355,7 +355,7 @@
if (isClient) {
conduit = control.createMock(Conduit.class);
- EasyMock.expect(message.getConduit()).andReturn(conduit);
+ EasyMock.expect(exchange.getConduit()).andReturn(conduit);
} else {
destination = control.createMock(Destination.class);
EasyMock.expect(message.getDestination()).andReturn(destination);
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java Fri Apr 6 04:21:45 2007
@@ -19,6 +19,8 @@
package org.apache.cxf.ws.policy;
+import java.lang.reflect.Method;
+
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.message.Exchange;
@@ -57,9 +59,12 @@
}
@Test
- public void testHandleMessage() {
+ public void testHandleMessage() throws NoSuchMethodException {
+ Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getTransportAssertions",
+ new Class[] {Message.class});
+
PolicyVerificationInFaultInterceptor interceptor =
- new PolicyVerificationInFaultInterceptor();
+ control.createMock(PolicyVerificationInFaultInterceptor.class, new Method[] {m});
interceptor.setBus(bus);
setupMessage(false, false, false, false, false, false);
@@ -99,6 +104,8 @@
control.reset();
setupMessage(true, true, true, true, true, true);
+ interceptor.getTransportAssertions(message);
+ EasyMock.expectLastCall();
EffectivePolicyImpl effectivePolicy = control.createMock(EffectivePolicyImpl.class);
EasyMock.expect(engine.getEffectiveClientFaultPolicy(ei, bfi)).andReturn(effectivePolicy);
Policy policy = control.createMock(Policy.class);
@@ -116,6 +123,7 @@
boolean setupPolicyEngine,
boolean setupAssertionInfoMap,
boolean setupBindingFaultInfo) {
+
if (null == message) {
message = control.createMock(Message.class);
}
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java Fri Apr 6 04:21:45 2007
@@ -19,8 +19,7 @@
package org.apache.cxf.ws.policy;
-import java.util.ArrayList;
-import java.util.List;
+import java.lang.reflect.Method;
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Endpoint;
@@ -31,7 +30,6 @@
import org.apache.neethi.Policy;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
-import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -50,24 +48,18 @@
private EndpointInfo ei;
private PolicyEngine engine;
private AssertionInfoMap aim;
- private List<Object> mocks = new ArrayList<Object>();
-
+
@Before
public void setUp() {
control = EasyMock.createNiceControl();
bus = control.createMock(Bus.class);
- mocks.add(bus);
- }
-
- @After
- public void clearMocks() {
- mocks.clear();
}
@Test
- public void testHandleMessage() {
+ public void testHandleMessageNoOp() throws NoSuchMethodException {
+
PolicyVerificationInInterceptor interceptor = new PolicyVerificationInInterceptor();
- interceptor.setBus(bus);
+ interceptor.setBus(bus);
setupMessage(false, false, false, false);
control.replay();
@@ -91,41 +83,55 @@
interceptor.handleMessage(message);
control.verify();
+ /*
control.reset();
setupMessage(true, true, true, true);
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE);
- EffectivePolicyImpl effectivePolicy = control.createMock(EffectivePolicyImpl.class);
- mocks.add(effectivePolicy);
- EasyMock.expect(engine.getEffectiveServerRequestPolicy(ei, boi)).andReturn(effectivePolicy);
- Policy policy = control.createMock(Policy.class);
- mocks.add(policy);
- EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
- aim.checkEffectivePolicy(policy);
- EasyMock.expectLastCall();
+ EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.TRUE);
control.replay();
interceptor.handleMessage(message);
control.verify();
+ */
+ }
+
+ @Test
+ public void testHandleMessage() throws NoSuchMethodException {
control.reset();
+ Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getTransportAssertions",
+ new Class[] {Message.class});
+ PolicyVerificationInInterceptor interceptor =
+ control.createMock(PolicyVerificationInInterceptor.class, new Method[] {m});
+ interceptor.setBus(bus);
setupMessage(true, true, true, true);
- EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.TRUE);
+ EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE);
+ interceptor.getTransportAssertions(message);
+ EasyMock.expectLastCall();
+ EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
+ EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);
+ EasyMock.expect(engine.getEffectiveClientResponsePolicy(ei, boi)).andReturn(effectivePolicy);
+ Policy policy = control.createMock(Policy.class);
+ EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
+ aim.checkEffectivePolicy(policy);
+ EasyMock.expectLastCall();
control.replay();
interceptor.handleMessage(message);
control.verify();
control.reset();
setupMessage(true, true, true, true);
- EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(null);
- EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);
- EasyMock.expect(engine.getEffectiveClientResponsePolicy(ei, boi)).andReturn(effectivePolicy);
+ EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE);
+ interceptor.getTransportAssertions(message);
+ EasyMock.expectLastCall();
+ effectivePolicy = control.createMock(EffectivePolicy.class);
+ EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE);
+ EasyMock.expect(engine.getEffectiveServerRequestPolicy(ei, boi)).andReturn(effectivePolicy);
+ policy = control.createMock(Policy.class);
EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
aim.checkEffectivePolicy(policy);
EasyMock.expectLastCall();
- EasyMock.expectLastCall();
control.replay();
interceptor.handleMessage(message);
control.verify();
-
}
void setupMessage(boolean setupBindingOperationInfo,
@@ -154,7 +160,6 @@
return;
}
ei = control.createMock(EndpointInfo.class);
- mocks.add(ei);
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
if (setupPolicyEngine && null == engine) {
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java Fri Apr 6 04:21:45 2007
@@ -19,13 +19,9 @@
package org.apache.cxf.ws.policy;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import javax.xml.namespace.QName;
+import java.lang.reflect.Method;
import org.apache.cxf.message.Message;
-import org.apache.neethi.Assertion;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
import org.junit.Assert;
@@ -45,8 +41,11 @@
}
@Test
- public void testHandleMessage() {
- PolicyVerificationOutInterceptor interceptor = new PolicyVerificationOutInterceptor();
+ public void testHandleMessage() throws NoSuchMethodException {
+ Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getTransportAssertions",
+ new Class[] {Message.class});
+ PolicyVerificationOutInterceptor interceptor =
+ control.createMock(PolicyVerificationOutInterceptor.class, new Method[] {m});
Message message = control.createMock(Message.class);
EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.TRUE);
@@ -61,46 +60,14 @@
interceptor.handleMessage(message);
control.verify();
- control.reset();
- Collection<Assertion> assertions = new ArrayList<Assertion>();
- AssertionInfoMap aim = new AssertionInfoMap(assertions);
-
- Assertion a1 = control.createMock(Assertion.class);
- AssertionInfo ai1 = new AssertionInfo(a1);
- Assertion a2 = control.createMock(Assertion.class);
- AssertionInfo ai2 = new AssertionInfo(a2);
- Assertion a3 = control.createMock(Assertion.class);
- AssertionInfo ai3 = new AssertionInfo(a3);
-
- QName n1 = new QName("http://x.b.c/x", "a1");
- QName n2 = new QName("http://x.b.c/x", "a2");
-
- Collection<AssertionInfo> c = new ArrayList<AssertionInfo>();
- c.add(ai1);
- c.add(ai2);
- aim.put(n1, c);
- c = new ArrayList<AssertionInfo>();
- c.add(ai3);
- aim.put(n2, c);
-
+ control.reset();
EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(null);
+ AssertionInfoMap aim = control.createMock(AssertionInfoMap.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
-
- control.replay();
- try {
- interceptor.handleMessage(message);
- fail("Expected PolicyException not thrown.");
- } catch (PolicyException ex) {
- // expected
- }
- control.verify();
-
- control.reset();
- ai1.setAsserted(true);
- ai2.setAsserted(true);
- ai3.setAsserted(true);
-
- EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
+ interceptor.getTransportAssertions(message);
+ EasyMock.expectLastCall();
+ aim.check();
+ EasyMock.expectLastCall();
control.replay();
interceptor.handleMessage(message);
Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java Fri Apr 6 04:21:45 2007
@@ -253,7 +253,7 @@
} else if (subject instanceof BindingFaultInfo) {
EasyMock.expect(attachment.appliesTo((BindingFaultInfo)subject)).andReturn(applies);
} else {
- System.out.println("subject class: " + subject.getClass());
+ System.err.println("subject class: " + subject.getClass());
}
if (applies) {
EasyMock.expect(attachment.getPolicy()).andReturn(policy);
Modified: incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMEndpoint.java?view=diff&rev=526120&r1=526119&r2=526120
==============================================================================
--- incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMEndpoint.java (original)
+++ incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMEndpoint.java Fri Apr 6 04:21:45 2007
@@ -245,7 +245,7 @@
void setPolicies() {
// use same WS-policies as for application endpoint
PolicyEngine engine = manager.getBus().getExtension(PolicyEngine.class);
- if (null == engine) {
+ if (null == engine || !engine.isEnabled()) {
return;
}