diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java index 85cdebbf745..54df51391e4 100644 --- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java +++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java @@ -33,7 +33,7 @@ public class MTOMAssertionBuilder implements AssertionBuilder { private static final QName[] KNOWN_ELEMENTS - = {MetadataConstants.MTOM_ASSERTION_QNAME}; + = {MetadataConstants.MTOM_ASSERTION_QNAME, MetadataConstants.MTOM11_ASSERTION_QNAME}; public Assertion build(Element elem, AssertionBuilderFactory f) { String localName = elem.getLocalName(); @@ -47,6 +47,8 @@ public Assertion build(Element elem, AssertionBuilderFactory f) { if (MetadataConstants.MTOM_ASSERTION_QNAME.equals(qn)) { return new PrimitiveAssertion(MetadataConstants.MTOM_ASSERTION_QNAME, optional); + } else if (MetadataConstants.MTOM11_ASSERTION_QNAME.equals(qn)) { + return new PrimitiveAssertion(MetadataConstants.MTOM11_ASSERTION_QNAME, optional); } return null; diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java index 6b432696779..b38bf789377 100644 --- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java +++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java @@ -21,6 +21,8 @@ import java.util.Collection; +import javax.xml.namespace.QName; + import org.apache.cxf.interceptor.Fault; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageUtils; @@ -39,7 +41,14 @@ public void handleMessage(Message message) throws Fault { // extract Assertion information if (aim != null) { - Collection ais = aim.get(MetadataConstants.MTOM_ASSERTION_QNAME); + assertAssertion(message, aim, MetadataConstants.MTOM_ASSERTION_QNAME); + assertAssertion(message, aim, MetadataConstants.MTOM11_ASSERTION_QNAME); + } + } + + private static void assertAssertion(Message message, AssertionInfoMap aim, QName type) { + Collection ais = aim.get(type); + if (ais != null) { for (AssertionInfo ai : ais) { if (MessageUtils.isRequestor(message)) { //just turn on MTOM diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptorProvider.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptorProvider.java index 1f646441d0f..32d566afe9a 100644 --- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptorProvider.java +++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptorProvider.java @@ -37,6 +37,7 @@ public class MTOMPolicyInterceptorProvider extends AbstractPolicyInterceptorProv static { Collection types = new ArrayList<>(); types.add(MetadataConstants.MTOM_ASSERTION_QNAME); + types.add(MetadataConstants.MTOM11_ASSERTION_QNAME); ASSERTION_TYPES = types; } diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java index a25331ddc1a..706467c13bb 100644 --- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java +++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java @@ -25,6 +25,8 @@ public final class MetadataConstants { public static final QName MTOM_ASSERTION_QNAME = new QName("http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization", "OptimizedMimeSerialization"); + public static final QName MTOM11_ASSERTION_QNAME = + new QName("http://www.w3.org/2007/08/soap12-mtom-policy", "MTOM"); private MetadataConstants() { diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java index 0b30994b16e..c4548d99038 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java @@ -59,6 +59,8 @@ public class MtomPolicyTest extends AbstractBusClientServerTestBase { public static final String PORT = TestUtil.getPortNumber(MtomPolicyTest.class); public static final String PORT2 = TestUtil.getPortNumber(MtomPolicyTest.class, 2); + public static final String PORT3 = TestUtil.getPortNumber(MtomPolicyTest.class, 3); + public static final String PORT4 = TestUtil.getPortNumber(MtomPolicyTest.class, 4); static TestUtilities testUtilities = new TestUtilities(MtomPolicyTest.class); @@ -72,7 +74,7 @@ public static void createTheBus() throws Exception { @Test public void testRequiredMtom() throws Exception { String address = "http://localhost:" + PORT + "/EchoService"; - setupServer(true, address); + setupServer("mtom-policy.xml", address); sendMtomMessage(address); @@ -88,7 +90,7 @@ public void testRequiredMtom() throws Exception { @Test public void testOptionalMtom() throws Exception { String address = "http://localhost:" + PORT2 + "/EchoService"; - setupServer(false, address); + setupServer("mtom-policy-optional.xml", address); sendMtomMessage(address); @@ -97,7 +99,34 @@ public void testOptionalMtom() throws Exception { testUtilities.assertNoFault(res); } - public void setupServer(boolean mtomRequired, String address) throws Exception { + @Test + public void testRequiredMtom11() throws Exception { + String address = "http://localhost:" + PORT3 + "/EchoService"; + setupServer("mtom11-policy.xml", address); + + sendMtomMessage(address); + + Node res = testUtilities.invoke(address, "http://schemas.xmlsoap.org/soap/http", "nonmtom.xml"); + + NodeList list = testUtilities.assertValid("//faultstring", res); + String text = list.item(0).getTextContent(); + assertTrue(text.contains("These policy alternatives can not be satisfied: ")); + assertTrue(text.contains("{http://www.w3.org/2007/08/soap12-mtom-policy}MTOM")); + } + + @Test + public void testOptionalMtom11() throws Exception { + String address = "http://localhost:" + PORT4 + "/EchoService"; + setupServer("mtom11-policy-optional.xml", address); + + sendMtomMessage(address); + + Node res = testUtilities.invoke(address, "http://schemas.xmlsoap.org/soap/http", "nonmtom.xml"); + + testUtilities.assertNoFault(res); + } + + public void setupServer(String policyResource, String address) throws Exception { getStaticBus().getExtension(PolicyEngine.class).setAlternativeSelector( new FirstAlternativeSelector()); JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean(); @@ -107,15 +136,9 @@ public void setupServer(boolean mtomRequired, String address) throws Exception { WSPolicyFeature policyFeature = new WSPolicyFeature(); List policyElements = new ArrayList<>(); - if (mtomRequired) { - policyElements.add(StaxUtils.read( - getClass().getResourceAsStream("mtom-policy.xml")) - .getDocumentElement()); - } else { - policyElements.add(StaxUtils.read( - getClass().getResourceAsStream("mtom-policy-optional.xml")) - .getDocumentElement()); - } + policyElements.add(StaxUtils.read( + getClass().getResourceAsStream(policyResource)) + .getDocumentElement()); policyFeature.setPolicyElements(policyElements); sf.getFeatures().add(policyFeature); diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/mtom11-policy-optional.xml b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/mtom11-policy-optional.xml new file mode 100644 index 00000000000..0fe9255c81a --- /dev/null +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/mtom11-policy-optional.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/mtom11-policy.xml b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/mtom11-policy.xml new file mode 100644 index 00000000000..a3f8ecc2b35 --- /dev/null +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/mtom11-policy.xml @@ -0,0 +1,22 @@ + + + + +