You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2020/01/22 17:05:57 UTC
[cxf] branch master updated: [CXF-7952]MTOM + schema validation
creates invalid SOAP FAULT response
This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 5042b9f [CXF-7952]MTOM + schema validation creates invalid SOAP FAULT response
5042b9f is described below
commit 5042b9f79347f1403ea7fe72165f805362e5f108
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Wed Jan 22 12:05:44 2020 -0500
[CXF-7952]MTOM + schema validation creates invalid SOAP FAULT response
---
.../cxf/interceptor/AttachmentOutInterceptor.java | 11 +++++-
.../apache/cxf/systest/mtom/ClientMtomXopTest.java | 42 ++++++++++++++++++++++
.../java/org/apache/cxf/mtom_xop/TestMtomImpl.java | 3 ++
testutils/src/main/resources/wsdl/mtom_xop.wsdl | 9 ++++-
4 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
index 7371716..e41a826 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/AttachmentOutInterceptor.java
@@ -37,6 +37,8 @@ import org.apache.cxf.phase.Phase;
public class AttachmentOutInterceptor extends AbstractPhaseInterceptor<Message> {
public static final String WRITE_ATTACHMENTS = "write.attachments";
+
+ public static final String ATTACHMENT_OUT_CHECKED = "attachment.out.checked";
private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AttachmentOutInterceptor.class);
@@ -47,7 +49,14 @@ public class AttachmentOutInterceptor extends AbstractPhaseInterceptor<Message>
}
public void handleMessage(Message message) {
-
+ //avoid AttachmentOutInterceptor invoked twice on the
+ //same message
+ if (message.get(ATTACHMENT_OUT_CHECKED) != null
+ && (boolean)message.get(ATTACHMENT_OUT_CHECKED)) {
+ return;
+ } else {
+ message.put(ATTACHMENT_OUT_CHECKED, Boolean.TRUE);
+ }
// Make it possible to step into this process in spite of Eclipse
// by declaring the Object.
boolean mtomEnabled = AttachmentUtil.isMtomEnabled(message);
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
index 39c5e60..16a0a2b 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
@@ -56,6 +56,7 @@ import org.apache.cxf.service.Service;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean;
import org.junit.BeforeClass;
@@ -64,6 +65,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class ClientMtomXopTest extends AbstractBusClientServerTestBase {
public static final String PORT = allocatePort(ClientMtomXopTest.class);
@@ -87,6 +89,7 @@ public class ClientMtomXopTest extends AbstractBusClientServerTestBase {
jaxep.getInInterceptors().add(new LoggingInInterceptor());
jaxep.getOutInterceptors().add(new LoggingOutInterceptor());
SOAPBinding jaxWsSoapBinding = (SOAPBinding) jaxep.getBinding();
+ jaxep.getProperties().put("schema-validation-enabled", "true");
jaxWsSoapBinding.setMTOMEnabled(true);
EndpointImpl endpoint =
(EndpointImpl)javax.xml.ws.Endpoint.publish(addressProvider, new TestMtomProviderImpl());
@@ -212,6 +215,45 @@ public class ClientMtomXopTest extends AbstractBusClientServerTestBase {
}
}
+
+ @Test
+ public void testMtomWithValidationErrorOnServer() throws Exception {
+ TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true, true);
+ try {
+ Holder<DataHandler> param = new Holder<>();
+ Holder<String> name;
+
+ InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
+ int fileSize = 0;
+ for (int i = pre.read(); i != -1; i = pre.read()) {
+ fileSize++;
+ }
+
+ int count = 1;
+ byte[] data = new byte[fileSize * count];
+ for (int x = 0; x < count; x++) {
+ this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data,
+ fileSize * x,
+ fileSize);
+ }
+
+
+ param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
+ //name length > 80 to break the schema
+ //will throw exception on server side
+ name = new Holder<>("break schema");
+ ClientProxy.getClient(mtomPort).getInInterceptors().add(new LoggingInInterceptor());
+ ClientProxy.getClient(mtomPort).getOutInterceptors().add(new LoggingOutInterceptor());
+ ((HTTPConduit)ClientProxy.getClient(mtomPort).getConduit()).getClient().setReceiveTimeout(60000);
+ mtomPort.testXop(name, param);
+ fail("should throw javax.xml.ws.soap.SOAPFaultException");
+
+ } catch (javax.xml.ws.soap.SOAPFaultException ex) {
+ assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
+ } catch (Exception ex) {
+ fail("should throw javax.xml.ws.soap.SOAPFaultException");
+ }
+ }
@Test
public void testMtomXopProvider() throws Exception {
diff --git a/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java b/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java
index 9bec2cb..27aec03 100644
--- a/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java
+++ b/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java
@@ -37,6 +37,9 @@ public class TestMtomImpl implements TestMtom {
public void testXop(Holder<String> name, Holder<DataHandler> attachinfo) {
if ("have name".equals(name.value) && attachinfo.value.getName() != null) {
name.value = "return detail + " + attachinfo.value.getName();
+ } else if ("break schema".equals(name.value)) {
+ name.value = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
+ + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
} else {
name.value = "return detail + " + name.value;
}
diff --git a/testutils/src/main/resources/wsdl/mtom_xop.wsdl b/testutils/src/main/resources/wsdl/mtom_xop.wsdl
index b84ded2..1d89023 100644
--- a/testutils/src/main/resources/wsdl/mtom_xop.wsdl
+++ b/testutils/src/main/resources/wsdl/mtom_xop.wsdl
@@ -33,7 +33,14 @@
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" targetNamespace="http://cxf.apache.org/mime/types" elementFormDefault="qualified">
<complexType name="XopType">
<sequence>
- <element name="name" type="xsd:string"/>
+ <element name="name">
+ <simpleType>
+ <restriction base="xsd:string">
+ <minLength value="1"/>
+ <maxLength value="80"/>
+ </restriction>
+ </simpleType>
+ </element>
<element name="attachinfo" type="xsd:base64Binary" xmime:expectedContentTypes="application/octet-stream"/>
</sequence>
</complexType>