Skip to content

Commit 7b4360e

Browse files
committed
CXF-8977: add support for MTOM Serialization Policy Assertion 1.1
1 parent 460927e commit 7b4360e

7 files changed

Lines changed: 95 additions & 14 deletions

File tree

rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMAssertionBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
public class MTOMAssertionBuilder implements AssertionBuilder<Element> {
3535
private static final QName[] KNOWN_ELEMENTS
36-
= {MetadataConstants.MTOM_ASSERTION_QNAME};
36+
= {MetadataConstants.MTOM_ASSERTION_QNAME, MetadataConstants.MTOM11_ASSERTION_QNAME};
3737

3838
public Assertion build(Element elem, AssertionBuilderFactory f) {
3939
String localName = elem.getLocalName();
@@ -47,6 +47,8 @@ public Assertion build(Element elem, AssertionBuilderFactory f) {
4747

4848
if (MetadataConstants.MTOM_ASSERTION_QNAME.equals(qn)) {
4949
return new PrimitiveAssertion(MetadataConstants.MTOM_ASSERTION_QNAME, optional);
50+
} else if (MetadataConstants.MTOM11_ASSERTION_QNAME.equals(qn)) {
51+
return new PrimitiveAssertion(MetadataConstants.MTOM11_ASSERTION_QNAME, optional);
5052
}
5153

5254
return null;

rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import java.util.Collection;
2323

24+
import javax.xml.namespace.QName;
25+
2426
import org.apache.cxf.interceptor.Fault;
2527
import org.apache.cxf.message.Message;
2628
import org.apache.cxf.message.MessageUtils;
@@ -39,7 +41,14 @@ public void handleMessage(Message message) throws Fault {
3941

4042
// extract Assertion information
4143
if (aim != null) {
42-
Collection<AssertionInfo> ais = aim.get(MetadataConstants.MTOM_ASSERTION_QNAME);
44+
assertAssertion(message, aim, MetadataConstants.MTOM_ASSERTION_QNAME);
45+
assertAssertion(message, aim, MetadataConstants.MTOM11_ASSERTION_QNAME);
46+
}
47+
}
48+
49+
private static void assertAssertion(Message message, AssertionInfoMap aim, QName type) {
50+
Collection<AssertionInfo> ais = aim.get(type);
51+
if (ais != null) {
4352
for (AssertionInfo ai : ais) {
4453
if (MessageUtils.isRequestor(message)) {
4554
//just turn on MTOM

rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptorProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class MTOMPolicyInterceptorProvider extends AbstractPolicyInterceptorProv
3737
static {
3838
Collection<QName> types = new ArrayList<>();
3939
types.add(MetadataConstants.MTOM_ASSERTION_QNAME);
40+
types.add(MetadataConstants.MTOM11_ASSERTION_QNAME);
4041
ASSERTION_TYPES = types;
4142
}
4243

rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MetadataConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public final class MetadataConstants {
2525
public static final QName MTOM_ASSERTION_QNAME =
2626
new QName("http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization",
2727
"OptimizedMimeSerialization");
28+
public static final QName MTOM11_ASSERTION_QNAME =
29+
new QName("http://www.w3.org/2007/08/soap12-mtom-policy", "MTOM");
2830

2931

3032
private MetadataConstants() {

systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
public class MtomPolicyTest extends AbstractBusClientServerTestBase {
6060
public static final String PORT = TestUtil.getPortNumber(MtomPolicyTest.class);
6161
public static final String PORT2 = TestUtil.getPortNumber(MtomPolicyTest.class, 2);
62+
public static final String PORT3 = TestUtil.getPortNumber(MtomPolicyTest.class, 3);
63+
public static final String PORT4 = TestUtil.getPortNumber(MtomPolicyTest.class, 4);
6264

6365
static TestUtilities testUtilities = new TestUtilities(MtomPolicyTest.class);
6466

@@ -72,7 +74,7 @@ public static void createTheBus() throws Exception {
7274
@Test
7375
public void testRequiredMtom() throws Exception {
7476
String address = "http://localhost:" + PORT + "/EchoService";
75-
setupServer(true, address);
77+
setupServer("mtom-policy.xml", address);
7678

7779
sendMtomMessage(address);
7880

@@ -88,7 +90,7 @@ public void testRequiredMtom() throws Exception {
8890
@Test
8991
public void testOptionalMtom() throws Exception {
9092
String address = "http://localhost:" + PORT2 + "/EchoService";
91-
setupServer(false, address);
93+
setupServer("mtom-policy-optional.xml", address);
9294

9395
sendMtomMessage(address);
9496

@@ -97,7 +99,34 @@ public void testOptionalMtom() throws Exception {
9799
testUtilities.assertNoFault(res);
98100
}
99101

100-
public void setupServer(boolean mtomRequired, String address) throws Exception {
102+
@Test
103+
public void testRequiredMtom11() throws Exception {
104+
String address = "http://localhost:" + PORT3 + "/EchoService";
105+
setupServer("mtom11-policy.xml", address);
106+
107+
sendMtomMessage(address);
108+
109+
Node res = testUtilities.invoke(address, "http://schemas.xmlsoap.org/soap/http", "nonmtom.xml");
110+
111+
NodeList list = testUtilities.assertValid("//faultstring", res);
112+
String text = list.item(0).getTextContent();
113+
assertTrue(text.contains("These policy alternatives can not be satisfied: "));
114+
assertTrue(text.contains("{http://www.w3.org/2007/08/soap12-mtom-policy}MTOM"));
115+
}
116+
117+
@Test
118+
public void testOptionalMtom11() throws Exception {
119+
String address = "http://localhost:" + PORT4 + "/EchoService";
120+
setupServer("mtom11-policy-optional.xml", address);
121+
122+
sendMtomMessage(address);
123+
124+
Node res = testUtilities.invoke(address, "http://schemas.xmlsoap.org/soap/http", "nonmtom.xml");
125+
126+
testUtilities.assertNoFault(res);
127+
}
128+
129+
public void setupServer(String policyResource, String address) throws Exception {
101130
getStaticBus().getExtension(PolicyEngine.class).setAlternativeSelector(
102131
new FirstAlternativeSelector());
103132
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
@@ -107,15 +136,9 @@ public void setupServer(boolean mtomRequired, String address) throws Exception {
107136

108137
WSPolicyFeature policyFeature = new WSPolicyFeature();
109138
List<Element> policyElements = new ArrayList<>();
110-
if (mtomRequired) {
111-
policyElements.add(StaxUtils.read(
112-
getClass().getResourceAsStream("mtom-policy.xml"))
113-
.getDocumentElement());
114-
} else {
115-
policyElements.add(StaxUtils.read(
116-
getClass().getResourceAsStream("mtom-policy-optional.xml"))
117-
.getDocumentElement());
118-
}
139+
policyElements.add(StaxUtils.read(
140+
getClass().getResourceAsStream(policyResource))
141+
.getDocumentElement());
119142
policyFeature.setPolicyElements(policyElements);
120143

121144
sf.getFeatures().add(policyFeature);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<wsp:Policy xmlns:wsp="http://www.w3.org/2006/07/ws-policy" xmlns:mtom="http://www.w3.org/2007/08/soap12-mtom-policy">
21+
<mtom:MTOM wsp:Optional="true"/>
22+
</wsp:Policy>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:mtom="http://www.w3.org/2007/08/soap12-mtom-policy">
21+
<mtom:MTOM/>
22+
</wsp:Policy>

0 commit comments

Comments
 (0)