You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2007/04/24 04:30:44 UTC
svn commit: r531684 - in /incubator/cxf/trunk:
distribution/src/main/assembly/
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/
rt/transports/http/src/main/java/org/apache/cxf/transport/http/
rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ rt...
Author: dandiep
Date: Mon Apr 23 19:30:43 2007
New Revision: 531684
URL: http://svn.apache.org/viewvc?view=rev&rev=531684
Log:
o CXF-593: MTOM Policy support from Chris Moesel with a few slight modifications
o Changed the PolicyVerificationOutInterceptor to check assertions using the
EffectivePolicy (and hence select the most appropriate policy) instead of
doing an arbitrary check() on the first policy available.
o Fix bug where the transport tried to apply policies to EndpointInfos without
a ServiceInfo.
Added:
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java (with props)
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java (with props)
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd (with props)
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml (with props)
Modified:
incubator/cxf/trunk/distribution/src/main/assembly/bin.xml
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.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/PolicyVerificationOutInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java
incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml
incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
Modified: incubator/cxf/trunk/distribution/src/main/assembly/bin.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/assembly/bin.xml?view=diff&rev=531684&r1=531683&r2=531684
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/assembly/bin.xml (original)
+++ incubator/cxf/trunk/distribution/src/main/assembly/bin.xml Mon Apr 23 19:30:43 2007
@@ -22,9 +22,9 @@
<id></id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
+ <format>dir</format>
<format>tar.gz</format>
<format>zip</format>
- <format>dir</format>
</formats>
<fileSets>
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=531684&r1=531683&r2=531684
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java Mon Apr 23 19:30:43 2007
@@ -433,13 +433,13 @@
}
public List<AbstractFeature> getFeatures() {
+ if (features == null) {
+ features = new ArrayList<AbstractFeature>();
+ }
return features;
}
public void setFeatures(List<AbstractFeature> features) {
- if (features == null) {
- features = new ArrayList<AbstractFeature>();
- }
this.features = features;
}
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=531684&r1=531683&r2=531684
==============================================================================
--- 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 Mon Apr 23 19:30:43 2007
@@ -307,7 +307,7 @@
// turn are superseded by injection
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
- if (null != pe && pe.isEnabled()) {
+ if (null != pe && pe.isEnabled() && endpointInfo.getService() != null) {
clientSidePolicy =
PolicyUtils.getClient(pe, endpointInfo, this);
}
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=531684&r1=531683&r2=531684
==============================================================================
--- 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 Mon Apr 23 19:30:43 2007
@@ -80,6 +80,7 @@
// 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> interceptors = effectivePolicy.getInterceptors();
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=531684&r1=531683&r2=531684
==============================================================================
--- 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 Mon Apr 23 19:30:43 2007
@@ -59,7 +59,12 @@
getTransportAssertions(message);
- aim.check();
+ EffectivePolicy policy = message.get(EffectivePolicy.class);
+ if (policy == null) {
+ return;
+ }
+
+ aim.checkEffectivePolicy(policy.getPolicy());
LOG.fine("Verified policies for outbound message.");
}
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java?view=diff&rev=531684&r1=531683&r2=531684
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java Mon Apr 23 19:30:43 2007
@@ -77,6 +77,7 @@
Destination destination = exchange.getDestination();
EffectivePolicy effectivePolicy = pe.getEffectiveServerResponsePolicy(ei, boi, destination);
+ msg.put(EffectivePolicy.class, effectivePolicy);
List<Interceptor> interceptors = effectivePolicy.getInterceptors();
for (Interceptor oi : interceptors) {
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java?view=diff&rev=531684&r1=531683&r2=531684
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java Mon Apr 23 19:30:43 2007
@@ -118,6 +118,9 @@
}
public Collection<Policy> getPolicies() {
+ if (policies == null) {
+ policies = new ArrayList<Policy>();
+ }
return policies;
}
@@ -126,6 +129,9 @@
}
public Collection<Element> getPolicyElements() {
+ if (policyElements == null) {
+ policyElements = new ArrayList<Element>();
+ }
return policyElements;
}
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java?view=auto&rev=531684
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java Mon Apr 23 19:30:43 2007
@@ -0,0 +1,75 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.ws.policy.mtom;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.ws.policy.AssertionBuilder;
+import org.apache.cxf.ws.policy.PolicyConstants;
+import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
+import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder;
+import org.apache.neethi.Assertion;
+
+public class MTOMAssertionBuilder implements AssertionBuilder {
+ private static final Collection<QName> KNOWN = new ArrayList<QName>();
+ static {
+ KNOWN.add(MetadataConstants.MTOM_ASSERTION_QNAME);
+ }
+
+ public Assertion build(Element elem) {
+ String localName = elem.getLocalName();
+ QName qn = new QName(elem.getNamespaceURI(), localName);
+
+ boolean optional = false;
+ Attr attribute = elem.getAttributeNodeNS(PolicyConstants.getNamespace(),
+ PolicyConstants.getOptionalAttrName());
+ if (attribute != null) {
+ optional = Boolean.valueOf(attribute.getValue());
+ }
+
+ if (MetadataConstants.MTOM_ASSERTION_QNAME.equals(qn)) {
+ return new PrimitiveAssertion(MetadataConstants.MTOM_ASSERTION_QNAME, optional);
+ }
+
+ return null;
+ }
+
+ public Collection<QName> getKnownElements() {
+ return KNOWN;
+ }
+
+ public Assertion buildCompatible(Assertion a, Assertion b) {
+ QName qn = a.getName();
+ if (MetadataConstants.MTOM_ASSERTION_QNAME.equals(qn)) {
+ PrimitiveAssertionBuilder pab = new PrimitiveAssertionBuilder();
+ pab.setKnownElements(Collections.singleton(qn));
+ return pab.buildCompatible(a, b);
+ }
+
+ return null;
+ }
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java?view=auto&rev=531684
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java Mon Apr 23 19:30:43 2007
@@ -0,0 +1,54 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.ws.policy.mtom;
+
+import java.util.Collection;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.ws.policy.AssertionInfo;
+import org.apache.cxf.ws.policy.AssertionInfoMap;
+
+public class MTOMPolicyInterceptor extends AbstractPhaseInterceptor<Message> {
+ public MTOMPolicyInterceptor() {
+ setPhase(Phase.POST_LOGICAL);
+ }
+
+ public void handleMessage(Message message) throws Fault {
+ AssertionInfoMap aim = message.get(AssertionInfoMap.class);
+
+ // extract Assertion information
+ if (aim != null) {
+ Collection<AssertionInfo> ais = aim.get(MetadataConstants.MTOM_ASSERTION_QNAME);
+ for (AssertionInfo ai : ais) {
+
+ // set mtom enabled and assert the policy if we find an mtom request
+ String contentType = (String)message.getExchange().getInMessage()
+ .get(Message.CONTENT_TYPE);
+ if (contentType != null && contentType.contains("type=\"application/xop+xml\"")) {
+ ai.setAsserted(true);
+ message.put(Message.MTOM_ENABLED, Boolean.TRUE);
+ }
+ }
+ }
+ }
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java?view=auto&rev=531684
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java Mon Apr 23 19:30:43 2007
@@ -0,0 +1,28 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.ws.policy.mtom;
+
+import javax.xml.namespace.QName;
+
+public class MetadataConstants {
+ public static final QName MTOM_ASSERTION_QNAME =
+ new QName("http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization",
+ "OptimizedMimeSerialization");
+}
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml?view=diff&rev=531684&r1=531683&r2=531684
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml Mon Apr 23 19:30:43 2007
@@ -68,4 +68,7 @@
<constructor-arg ref="cxf"/>
</bean>
+ <!-- MTOM Policy Support -->
+ <bean class="org.apache.cxf.ws.policy.mtom.MTOMAssertionBuilder" />
+ <bean class="org.apache.cxf.ws.policy.mtom.MTOMPolicyInterceptorProvider"/>
</beans>
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=531684&r1=531683&r2=531684
==============================================================================
--- 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 Mon Apr 23 19:30:43 2007
@@ -66,7 +66,12 @@
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
interceptor.getTransportAssertions(message);
EasyMock.expectLastCall();
- aim.check();
+ EffectivePolicy ep = control.createMock(EffectivePolicy.class);
+ EasyMock.expect(message.get(EffectivePolicy.class)).andReturn(ep);
+ EasyMock.expect(ep.getPolicy()).andReturn(null);
+
+ aim.checkEffectivePolicy(null);
+
EasyMock.expectLastCall();
control.replay();
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?view=diff&rev=531684&r1=531683&r2=531684
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Mon Apr 23 19:30:43 2007
@@ -89,7 +89,7 @@
@Test
public void testMtomXop() throws Exception {
- TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class);
+ TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true);
try {
InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
long fileSize = 0;
@@ -110,7 +110,10 @@
}
}
- private static <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface)
+ private static <T> T createPort(QName serviceName,
+ QName portName,
+ Class<T> serviceEndpointInterface,
+ boolean enableMTOM)
throws Exception {
Bus bus = BusFactory.getDefaultBus();
ReflectionServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
@@ -122,7 +125,7 @@
EndpointInfo ei = service.getEndpointInfo(portName);
JaxWsEndpointImpl jaxwsEndpoint = new JaxWsEndpointImpl(bus, service, ei);
SOAPBinding jaxWsSoapBinding = new SOAPBindingImpl(ei.getBinding());
- jaxWsSoapBinding.setMTOMEnabled(true);
+ jaxWsSoapBinding.setMTOMEnabled(enableMTOM);
jaxwsEndpoint.getBinding().getInInterceptors().add(new TestMultipartMessageInterceptor());
jaxwsEndpoint.getBinding().getOutInterceptors().add(new TestAttachmentOutInterceptor());
Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java?view=auto&rev=531684
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java Mon Apr 23 19:30:43 2007
@@ -0,0 +1,149 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.systest.mtom;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+
+import org.w3c.dom.Node;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusException;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.attachment.AttachmentDeserializer;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.test.AbstractCXFTest;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.ConduitInitiator;
+import org.apache.cxf.transport.ConduitInitiatorManager;
+import org.apache.cxf.ws.policy.WSPolicyFeature;
+import org.junit.Test;
+
+public class MtomPolicyTest extends AbstractCXFTest {
+ String address = "http://localhost:9036/EchoService";
+
+ @Test
+ public void testRequiredMtom() throws Exception {
+ setupServer(true);
+
+ sendMtomMessage(address);
+
+ Node res = invoke(address, "http://schemas.xmlsoap.org/soap/http", "nonmtom.xml");
+
+ assertValid("//faultstring[text()='None of the policy alternatives can be satisfied.']", res);
+ }
+
+ @Test
+ public void testOptionalMtom() throws Exception {
+ setupServer(false);
+
+ sendMtomMessage(address);
+
+ Node res = invoke(address, "http://schemas.xmlsoap.org/soap/http", "nonmtom.xml");
+
+ assertNoFault(res);
+ }
+
+ public void setupServer(boolean mtomRequired) throws Exception {
+ JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
+ sf.setServiceBean(new EchoService());
+ sf.setBus(getBus());
+ sf.setAddress(address);
+
+ WSPolicyFeature policy = new WSPolicyFeature();
+ if (mtomRequired) {
+ policy.getPolicyElements().add(DOMUtils.readXml(
+ getClass().getResourceAsStream("mtom-policy.xsd"))
+ .getDocumentElement());
+ } else {
+ policy.getPolicyElements().add(DOMUtils.readXml(
+ getClass().getResourceAsStream("mtom-policy-optional.xsd"))
+ .getDocumentElement());
+ }
+
+ sf.getFeatures().add(policy);
+
+ sf.create();
+ }
+
+ private void sendMtomMessage(String a) throws Exception {
+ EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/wsdl/http");
+ ei.setAddress(a);
+
+ ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
+ ConduitInitiator conduitInit = conduitMgr.getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
+ Conduit conduit = conduitInit.getConduit(ei);
+
+ TestMessageObserver obs = new TestMessageObserver();
+ conduit.setMessageObserver(obs);
+
+ Message m = new MessageImpl();
+ String ct = "multipart/related; type=\"application/xop+xml\"; "
+ + "start=\"<so...@xfire.codehaus.org>\"; "
+ + "start-info=\"text/xml; charset=utf-8\"; "
+ + "boundary=\"----=_Part_4_701508.1145579811786\"";
+
+ m.put(Message.CONTENT_TYPE, ct);
+ conduit.prepare(m);
+
+ OutputStream os = m.getContent(OutputStream.class);
+ InputStream is = getResourceAsStream("request");
+ if (is == null) {
+ throw new RuntimeException("Could not find resource " + "request");
+ }
+
+ IOUtils.copy(is, os);
+
+ os.flush();
+ is.close();
+ os.close();
+
+ byte[] res = obs.getResponseStream().toByteArray();
+ MessageImpl resMsg = new MessageImpl();
+ resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
+ resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
+ AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
+ deserializer.initializeAttachments();
+
+ Collection<Attachment> attachments = resMsg.getAttachments();
+ assertNotNull(attachments);
+ assertEquals(1, attachments.size());
+
+ Attachment inAtt = attachments.iterator().next();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
+ out.close();
+ assertEquals(37448, out.size());
+ }
+
+ @Override
+ protected Bus createBus() throws BusException {
+ return BusFactory.getDefaultBus();
+ }
+
+}
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd?view=auto&rev=531684
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd Mon Apr 23 19:30:43 2007
@@ -0,0 +1,4 @@
+<wsp:Policy xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
+ xmlns:mtom="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization">
+ <mtom:OptimizedMimeSerialization wsp:Optional="true" />
+</wsp:Policy>
\ No newline at end of file
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd?view=auto&rev=531684
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd Mon Apr 23 19:30:43 2007
@@ -0,0 +1,4 @@
+<wsp:Policy xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
+ xmlns:mtom="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization">
+ <mtom:OptimizedMimeSerialization />
+</wsp:Policy>
\ No newline at end of file
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml?view=auto&rev=531684
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml Mon Apr 23 19:30:43 2007
@@ -0,0 +1,11 @@
+<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
+ <env:Body>
+ <m:echo xmlns:m="http://mtom.systest.cxf.apache.org">
+ <m:Data>
+ <m:someData>
+ ABCDEF0123456789
+ </m:someData>
+ </m:Data>
+ </m:echo>
+ </env:Body>
+</env:Envelope>
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Re: svn commit: r531684 - in /incubator/cxf/trunk: distribution/src/main/assembly/
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/
rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ rt...
Posted by Andrea Smyth <an...@iona.com>.
dandiep@apache.org wrote:
>Author: dandiep
>Date: Mon Apr 23 19:30:43 2007
>New Revision: 531684
>
>URL: http://svn.apache.org/viewvc?view=rev&rev=531684
>Log:
>o CXF-593: MTOM Policy support from Chris Moesel with a few slight modifications
>o Changed the PolicyVerificationOutInterceptor to check assertions using the
> EffectivePolicy (and hence select the most appropriate policy) instead of
> doing an arbitrary check() on the first policy available.
>
>
Hi Dan,
This was not an arbitrary check on the 'first policy available' but on a
previously chosen alternative.
There is only ever one policy - at least on the outbound paths where we
know message and operation type for the underlying message, but this
could have several alternatives. Although this would be unusual, the
effective policy could be:
<wsp:Policy>
<wsp:ExactlyOne>
<wsp:All>
<mtom:OptimizedMimeSerialization>
</wsp:All>
<wsp:All>
<wsam:Addressing>
<wsp:Policy ...>
<wsam:Addressing>
</wsp:All>
</wsp:ExactlyOne>
<wsp:Policy>
meaning that to support one of the alternatives we need either the
addressing interceptors or the mtom interceptor on the path, but not both.
There are two options now:
a) The policy framework chooses the alternative upfront, installs only
one set of interceptors. In that case it only needs to verify at the end
of the chain that all assertions in the chosen alternative have indeed
been asserted (the addressing interceptors may have failed in asserting
the addressing assertion depending on the content of the nested Policy).
b) The other option is to defer the choice and add both addressing and
mtom interceptors (in general: interceptors for all assertions types
occurring in any of the alternatives), and then check if there is one
alternative for which all assertions have been asserted (this is the way
it is done on the inbound paths on client and server side).
The advantage of a) is that limiting the number of interceptors is
beneficial to performance (e.g. no encoding/decoding of headers).
The advantage of b) is that we maximise the chances that the message's
effective policy is supported.
If this merge is intended to use b) instead of a) then it is incomplete
as the initialisation phase in EffectivePolicyImpl (calculate effective
policy, choose one of its alternatives, determine interceptors) needs to
be changed accordingly. getChosenAlternative() becomes meaningless and
should be removed from API and implementation.
Also, if the EffectivePolicy object is added to the message in
ClientPolicyOutInterceptor and ServerPolicyOutInterceptor then it should
also be added in ServerPolicyOutFaultInterceptor.
If not, then what are the intentions instead? As it stands the effects
are rather limited - they are not a solution to the problem brought up
in the discussion about the MTOM interceptor's need to know if a given
MTOM assertion is optional.
Regarding the WSPolicyFeature: How are they hooked up with the Policy
Framework? From what I can see they use the AssertionBuilders to parse
child elements and enable the framework. But that alone does not have
much effect. In particular, no interceptors will get added when a
message targeted at that endpoint is processed. For that to happen the
policy framework needs to make the connection between the policy and a
policy subject (service, endpoint, operation, message). Clearly there is
an implied association here between the Policies in a WSFeature and the
endpoint to which this feature applies.
But how should these Policy - (endpoint) subject associations be
reconciled with other, possibly more fine grained associations, to
operation or message subjects? Or with the association between another
Policy and the service subject?
To me the obvious answer would seem to treat them in just the same way
as Policies attached to elements in the underlying wsdl or Policies in
matching PolicyAttachment, i.e. to combine (merge) them with other
Policies applying to the same subject and to other subjects within the
same scope. If there are no objections that's what I will do.
Andrea.
>o Fix bug where the transport tried to apply policies to EndpointInfos without
> a ServiceInfo.
>
>
>Added:
> incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/
> incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java (with props)
> incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java (with props)
> incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java (with props)
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java (with props)
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy-optional.xsd (with props)
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/mtom-policy.xsd (with props)
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/nonmtom.xml (with props)
>Modified:
> incubator/cxf/trunk/distribution/src/main/assembly/bin.xml
> incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
> incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.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/PolicyVerificationOutInterceptor.java
> incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ServerPolicyOutInterceptor.java
> incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
> incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml
> incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
> incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
>
>
>