[CXF-5687] Update for generated WebFault's to make sure the detail is properly
schema validated.
Conflicts:
testutils/src/main/resources/wsdl/schema_validation.wsdl
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3c19a8a3
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3c19a8a3
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3c19a8a3
Branch: refs/heads/2.7.x-fixes
Commit: 3c19a8a346efaca97f5cd5b5837a6308cae40991
Parents: a5f5fad
Author: Daniel Kulp <[email protected]>
Authored: Mon Apr 14 15:15:37 2014 -0400
Committer: Daniel Kulp <[email protected]>
Committed: Tue Apr 15 16:00:05 2014 -0400
----------------------------------------------------------------------
.../interceptors/WebFaultOutInterceptor.java | 23 +++++++--
.../schema_validation/SchemaValidationImpl.java | 16 ++++--
.../ValidationClientServerTest.java | 54 +++++++++++++++++---
.../schema_validation/ValidationServer.java | 53 ++++++++++++++++++-
.../main/resources/wsdl/schema_validation.wsdl | 35 ++++++++++---
5 files changed, 157 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/3c19a8a3/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
----------------------------------------------------------------------
diff --git
a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
index dc9624e..92f0951 100644
---
a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
+++
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
@@ -29,9 +29,11 @@ import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.validation.Schema;
import javax.xml.ws.WebFault;
import javax.xml.ws.soap.SOAPFaultException;
+import org.apache.cxf.annotations.SchemaValidation.SchemaValidationType;
import org.apache.cxf.binding.soap.SoapFault;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.i18n.BundleUtils;
@@ -39,6 +41,7 @@ import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.databinding.DataWriter;
import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.ServiceUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.FaultOutInterceptor;
import org.apache.cxf.message.FaultMode;
@@ -49,6 +52,7 @@ import org.apache.cxf.service.model.FaultInfo;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.cxf.service.model.OperationInfo;
import org.apache.cxf.staxutils.W3CDOMStreamWriter;
+import org.apache.cxf.ws.addressing.EndpointReferenceUtils;
public class WebFaultOutInterceptor extends FaultOutInterceptor {
@@ -136,7 +140,13 @@ public class WebFaultOutInterceptor extends
FaultOutInterceptor {
try {
DataWriter<XMLStreamWriter> writer
=
service.getDataBinding().createWriter(XMLStreamWriter.class);
-
+
+ if
(ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) {
+ Schema schema =
EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0),
+
message.getExchange().getBus());
+ writer.setSchema(schema);
+ }
+
OperationInfo op =
message.getExchange().get(BindingOperationInfo.class).getOperationInfo();
QName faultName = getFaultName(fault, cause.getClass(), op);
MessagePartInfo part = getFaultMessagePart(faultName, op);
@@ -151,9 +161,14 @@ public class WebFaultOutInterceptor extends
FaultOutInterceptor {
f.setMessage(ex.getMessage());
} catch (Exception nex) {
- //if exception occurs while writing a fault, we'll just let
things continue
- //and let the rest of the chain try handling it as is.
- LOG.log(Level.WARNING, "EXCEPTION_WHILE_WRITING_FAULT", nex);
+ if (nex instanceof Fault) {
+ message.setContent(Exception.class, nex);
+ super.handleMessage(message);
+ } else {
+ //if exception occurs while writing a fault, we'll just
let things continue
+ //and let the rest of the chain try handling it as is.
+ LOG.log(Level.WARNING, "EXCEPTION_WHILE_WRITING_FAULT",
nex);
+ }
}
} else {
FaultMode mode = message.get(FaultMode.class);
http://git-wip-us.apache.org/repos/asf/cxf/blob/3c19a8a3/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/SchemaValidationImpl.java
----------------------------------------------------------------------
diff --git
a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/SchemaValidationImpl.java
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/SchemaValidationImpl.java
index b8eab4b..015a5ad 100644
---
a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/SchemaValidationImpl.java
+++
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/SchemaValidationImpl.java
@@ -24,9 +24,11 @@ import java.util.List;
import javax.jws.WebService;
+import org.apache.schema_validation.DoSomethingFault;
import org.apache.schema_validation.SchemaValidation;
import org.apache.schema_validation.types.ComplexStruct;
import org.apache.schema_validation.types.OccuringStruct;
+import org.apache.schema_validation.types.SomeFault;
import org.apache.schema_validation.types.SomeHeader;
import org.apache.schema_validation.types.SomeRequest;
import org.apache.schema_validation.types.SomeRequestWithHeader;
@@ -36,8 +38,8 @@ import
org.apache.schema_validation.types.SomeResponseWithHeader;
@WebService(serviceName = "SchemaValidationService",
portName = "SoapPort",
endpointInterface =
"org.apache.schema_validation.SchemaValidation",
- targetNamespace = "http://apache.org/schema_validation")
[email protected]
+ targetNamespace = "http://apache.org/schema_validation",
+ wsdlLocation = "classpath:/wsdl/schema_validation.wsdl")
public class SchemaValidationImpl implements SchemaValidation {
public boolean setComplexStruct(ComplexStruct in) {
@@ -70,10 +72,18 @@ public class SchemaValidationImpl implements
SchemaValidation {
}
@Override
- public SomeResponse doSomething(SomeRequest in) {
+ public SomeResponse doSomething(SomeRequest in) throws DoSomethingFault {
SomeResponse response = new SomeResponse();
if (in.getId().equals("1234567890")) {
response.setTransactionId("aaaaaaaaaaxxx"); // invalid transaction
id
+ } else if (in.getId().equals("9999999999")) {
+ SomeFault someFault = new SomeFault();
+ someFault.setErrorCode("1234");
+ throw new DoSomethingFault("Fault", someFault);
+ } else if (in.getId().equals("8888888888")) {
+ SomeFault someFault = new SomeFault();
+ someFault.setErrorCode("1");
+ throw new DoSomethingFault("Fault", someFault);
} else {
response.setTransactionId("aaaaaaaaaa");
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/3c19a8a3/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
----------------------------------------------------------------------
diff --git
a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
index 99e2110..4ebf76c 100644
---
a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
+++
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
@@ -33,14 +33,18 @@ import javax.xml.ws.Service.Mode;
import javax.xml.ws.WebServiceException;
import org.apache.cxf.annotations.SchemaValidation.SchemaValidationType;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.feature.LoggingFeature;
import org.apache.cxf.message.Message;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.schema_validation.DoSomethingFault;
import org.apache.schema_validation.SchemaValidation;
import org.apache.schema_validation.SchemaValidationService;
import org.apache.schema_validation.types.ComplexStruct;
import org.apache.schema_validation.types.OccuringStruct;
import org.apache.schema_validation.types.SomeRequest;
import org.apache.schema_validation.types.SomeResponse;
+
import org.junit.BeforeClass;
import org.junit.Test;
@@ -61,8 +65,18 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
// client and server with schema validation enabled/disabled...
// Only tests client side validation enabled/server side disabled.
@Test
- public void testSchemaValidation() throws Exception {
- SchemaValidation validation = createService(Boolean.TRUE);
+ public void testSchemaValidationServer() throws Exception {
+ SchemaValidation validation = createService(Boolean.FALSE,
"SoapPortValidate");
+ runSchemaValidationTest(validation);
+ ((java.io.Closeable)validation).close();
+ }
+ @Test
+ public void testSchemaValidationClient() throws Exception {
+ SchemaValidation validation = createService(Boolean.TRUE, "SoapPort");
+ runSchemaValidationTest(validation);
+ ((java.io.Closeable)validation).close();
+ }
+ private void runSchemaValidationTest(SchemaValidation validation) {
ComplexStruct complexStruct = new ComplexStruct();
complexStruct.setElem1("one");
// Don't initialize a member of the structure.
@@ -94,8 +108,6 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
assertTrue(e.getMessage().indexOf(expected) != -1);
}
- validation = createService(Boolean.FALSE);
-
try {
// The server will attempt to return an invalid ComplexStruct
// When validation is disabled on the server side, we'll get the
@@ -109,8 +121,6 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
e.getMessage().indexOf(expected) != -1);
}
- validation = createService(Boolean.TRUE);
-
try {
// The server will attempt to return an invalid OccuringStruct
// When validation is disabled on the server side, we'll get the
@@ -122,6 +132,25 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
String expected =
"'{\"http://apache.org/schema_validation/types\":varFloat}' is expected.";
assertTrue(e.getMessage().indexOf(expected) != -1);
}
+
+
+ SomeRequest req = new SomeRequest();
+ req.setId("9999999999");
+ try {
+ validation.doSomething(req);
+ fail("Should have faulted");
+ } catch (DoSomethingFault e) {
+ assertEquals("1234", e.getFaultInfo().getErrorCode());
+ }
+ req.setId("8888888888");
+ try {
+ validation.doSomething(req);
+ fail("Should have faulted");
+ } catch (DoSomethingFault e) {
+ fail("Should not have happened");
+ } catch (WebServiceException e) {
+ e.printStackTrace();
+ }
}
@Test
@@ -221,6 +250,8 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
assertTrue(e.getMessage().contains("Unmarshalling Error"));
assertTrue(e.getMessage().contains("is not facet-valid with
respect to pattern"));
}
+
+ ((java.io.Closeable)service).close();
}
private void assertIgnoredRequestValidation(Object validationConfig)
throws Exception {
@@ -229,6 +260,7 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
// this is an invalid request but validation is turned off.
SomeResponse response = execute(service, "1234567890aaaa");
assertEquals(response.getTransactionId(), "aaaaaaaaaa");
+ ((java.io.Closeable)service).close();
}
private void assertIgnoredResponseValidation(Object validationConfig)
throws Exception {
@@ -237,6 +269,7 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
// the request will result in invalid response but validation is
turned off
SomeResponse response = execute(service, "1234567890");
assertEquals(response.getTransactionId(), "aaaaaaaaaaxxx");
+ ((java.io.Closeable)service).close();
}
private void assertFailedRequestValidation(Object validationConfig) throws
Exception {
@@ -252,9 +285,13 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
assertTrue(e.getMessage().contains("Marshalling Error"));
assertTrue(e.getMessage().contains("is not facet-valid with
respect to pattern"));
}
+ ((java.io.Closeable)service).close();
}
private SchemaValidation createService(Object validationConfig) throws
Exception {
+ return createService(validationConfig, "SoapPort");
+ }
+ private SchemaValidation createService(Object validationConfig, String
postfix) throws Exception {
URL wsdl = getClass().getResource("/wsdl/schema_validation.wsdl");
assertNotNull(wsdl);
@@ -262,10 +299,11 @@ public class ValidationClientServerTest extends
AbstractBusClientServerTestBase
assertNotNull(service);
SchemaValidation validation = service.getPort(portName,
SchemaValidation.class);
- updateAddressPort(validation, PORT);
+ setAddress(validation, "http://localhost:" + PORT + "/SoapContext/" +
postfix);
+
((BindingProvider)validation).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED,
validationConfig);
((BindingProvider)validation).getResponseContext().put(Message.SCHEMA_VALIDATION_ENABLED,
validationConfig);
-
+ new LoggingFeature().initialize((Client)validation, getBus());
return validation;
}
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/3c19a8a3/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
----------------------------------------------------------------------
diff --git
a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
index 3204e11..79f2939 100644
---
a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
+++
b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
@@ -20,23 +20,72 @@
package org.apache.cxf.systest.schema_validation;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jws.WebService;
+import javax.xml.transform.Source;
import javax.xml.ws.Endpoint;
+import javax.xml.ws.Provider;
+import javax.xml.ws.Service;
+import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceProvider;
+import org.apache.cxf.annotations.SchemaValidation;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
public class ValidationServer extends AbstractBusTestServerBase {
public static final String PORT = allocatePort(ValidationServer.class);
+ List<Endpoint> eps = new LinkedList<Endpoint>();
+
public ValidationServer() {
}
protected void run() {
Object implementor = new SchemaValidationImpl();
- String address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
- Endpoint.publish(address, implementor);
+ String address = "http://localhost:" + PORT + "/SoapContext";
+ eps.add(Endpoint.publish(address + "/SoapPort", implementor));
+ eps.add(Endpoint.publish(address + "/SoapPortValidate", new
ValidatingSchemaValidationImpl()));
+ eps.add(Endpoint.publish(address + "/PProvider", new
PayloadProvider()));
+ eps.add(Endpoint.publish(address + "/MProvider", new
MessageProvider()));
+ }
+
+ public void tearDown() throws Exception {
+ while (!eps.isEmpty()) {
+ eps.remove(0).stop();
+ }
+ }
+
+ @WebService(serviceName = "SchemaValidationService",
+ portName = "SoapPort",
+ endpointInterface = "org.apache.schema_validation.SchemaValidation",
+ targetNamespace = "http://apache.org/schema_validation",
+ wsdlLocation = "classpath:/wsdl/schema_validation.wsdl")
+ @SchemaValidation
+ static class ValidatingSchemaValidationImpl extends SchemaValidationImpl {
+
}
+ @WebServiceProvider
+ @ServiceMode(Service.Mode.PAYLOAD)
+ @SchemaValidation
+ static class PayloadProvider implements Provider<Source> {
+ @Override
+ public Source invoke(Source request) {
+ return null;
+ }
+ }
+ @WebServiceProvider
+ @ServiceMode(Service.Mode.MESSAGE)
+ @SchemaValidation
+ static class MessageProvider implements Provider<Source> {
+ @Override
+ public Source invoke(Source request) {
+ return null;
+ }
+ }
public static void main(String[] args) {
try {
http://git-wip-us.apache.org/repos/asf/cxf/blob/3c19a8a3/testutils/src/main/resources/wsdl/schema_validation.wsdl
----------------------------------------------------------------------
diff --git a/testutils/src/main/resources/wsdl/schema_validation.wsdl
b/testutils/src/main/resources/wsdl/schema_validation.wsdl
index 8410671..af574cb 100644
--- a/testutils/src/main/resources/wsdl/schema_validation.wsdl
+++ b/testutils/src/main/resources/wsdl/schema_validation.wsdl
@@ -50,12 +50,27 @@
</element>
<element name="SomeResponse">
- <complexType>
- <sequence>
- <element name="transactionId"
type="x1:ResponseTransactionType"/>
- </sequence>
- </complexType>
- </element>
+ <complexType>
+ <sequence>
+ <element name="transactionId"
type="x1:ResponseTransactionType"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="SomeFault">
+ <complexType>
+ <sequence>
+ <element name="errorCode" minOccurs="1" maxOccurs="1"
nillable="false">
+ <simpleType>
+ <restriction base="string">
+ <pattern value="[\d]{4}" />
+ </restriction>
+ </simpleType>
+ </element>
+ </sequence>
+ </complexType>
+ </element>
+
<element name="SomeRequestWithHeader">
<complexType>
<sequence>
@@ -159,7 +174,9 @@
<wsdl:message name="doSomethingResponse">
<wsdl:part element="x1:SomeResponse" name="in"/>
</wsdl:message>
-
+ <wsdl:message name="doSomethingFault">
+ <wsdl:part element="x1:SomeFault" name="fault"/>
+ </wsdl:message>
<wsdl:message name="doSomethingRequestWithHeader">
<wsdl:part element="x1:SomeRequestWithHeader" name="in"/>
<wsdl:part element="x1:SomeHeader" name="inHeader"/>
@@ -198,6 +215,7 @@
<wsdl:operation name="doSomething">
<wsdl:input message="tns:doSomethingRequest"
name="doSomethingRequest"/>
<wsdl:output message="tns:doSomethingResponse"
name="doSomethingResponse"/>
+ <wsdl:fault message="tns:doSomethingFault"
name="doSomethingFault"/>
</wsdl:operation>
<wsdl:operation name="setComplexStruct">
@@ -236,6 +254,9 @@
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
+ <wsdl:fault name="doSomethingFault">
+ <soap:fault name="doSomethingFault" use="literal"/>
+ </wsdl:fault>
</wsdl:operation>
<wsdl:operation name="doSomethingWithHeader">
<soap:operation style="document"/>