diff --git a/core/src/main/java/org/springframework/ws/server/endpoint/interceptor/AbstractValidatingInterceptor.java b/core/src/main/java/org/springframework/ws/server/endpoint/interceptor/AbstractValidatingInterceptor.java index ecae1988..fc72be50 100644 --- a/core/src/main/java/org/springframework/ws/server/endpoint/interceptor/AbstractValidatingInterceptor.java +++ b/core/src/main/java/org/springframework/ws/server/endpoint/interceptor/AbstractValidatingInterceptor.java @@ -17,13 +17,9 @@ package org.springframework.ws.server.endpoint.interceptor; import java.io.IOException; -import java.util.Locale; -import javax.xml.namespace.QName; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; import org.springframework.util.Assert; @@ -32,12 +28,6 @@ import org.springframework.util.StringUtils; import org.springframework.ws.WebServiceMessage; import org.springframework.ws.context.MessageContext; import org.springframework.ws.server.EndpointInterceptor; -import org.springframework.ws.soap.SoapBody; -import org.springframework.ws.soap.SoapFault; -import org.springframework.ws.soap.SoapFaultDetail; -import org.springframework.ws.soap.SoapFaultDetailElement; -import org.springframework.ws.soap.SoapMessage; -import org.springframework.xml.namespace.QNameUtils; import org.springframework.xml.transform.TransformerObjectSupport; import org.springframework.xml.validation.XmlValidator; import org.springframework.xml.validation.XmlValidatorFactory; @@ -50,8 +40,7 @@ import org.xml.sax.SAXParseException; * getValidationResponseSource template methods. *

* By default, only the request message is validated, but this behaviour can be changed using the - * validateRequest and validateResponse properties. Responses that contains SOAP faults are - * not validated. + * validateRequest and validateResponse properties. * * @author Arjen Poutsma * @see #getValidationRequestSource(org.springframework.ws.WebServiceMessage) @@ -60,31 +49,6 @@ import org.xml.sax.SAXParseException; public abstract class AbstractValidatingInterceptor extends TransformerObjectSupport implements EndpointInterceptor, InitializingBean { - /** - * Default SOAP Fault Detail name used when a validation errors occur on the request. - * - * @see #setDetailElementName(javax.xml.namespace.QName) - */ - public static final QName DEFAULT_DETAIL_ELEMENT_NAME = - QNameUtils.createQName("http://springframework.org/spring-ws", "ValidationError", "spring-ws"); - - /** - * Default SOAP Fault string used when a validation errors occur on the request. - * - * @see #setFaultStringOrReason(String) - */ - public static final String DEFAULT_FAULTSTRING_OR_REASON = "Validation error"; - - protected final Log logger = LogFactory.getLog(getClass()); - - private boolean addValidationErrorDetail = true; - - private QName detailElementName = DEFAULT_DETAIL_ELEMENT_NAME; - - private String faultStringOrReason = DEFAULT_FAULTSTRING_OR_REASON; - - private Locale faultStringOrReasonLocale = Locale.ENGLISH; - private String schemaLanguage = XmlValidatorFactory.SCHEMA_W3C_XML; private Resource[] schemas; @@ -95,73 +59,6 @@ public abstract class AbstractValidatingInterceptor extends TransformerObjectSup private XmlValidator validator; - public boolean getAddValidationErrorDetail() { - return addValidationErrorDetail; - } - - /** - * Indicates whether a SOAP Fault detail element should be created when a validation error occurs. This detail - * element will contain the exact validation errors. It is only added when the underlying message is a - * SoapMessage. Defaults to true. - * - * @see org.springframework.ws.soap.SoapFault#addFaultDetail() - */ - public void setAddValidationErrorDetail(boolean addValidationErrorDetail) { - this.addValidationErrorDetail = addValidationErrorDetail; - } - - /** - * Returns the fault detail element name when validation errors occur on the request. - */ - public QName getDetailElementName() { - return detailElementName; - } - - /** - * Sets the fault detail element name when validation errors occur on the request. Defaults to - * DEFAULT_DETAIL_ELEMENT_NAME. - * - * @see #DEFAULT_DETAIL_ELEMENT_NAME - */ - public void setDetailElementName(QName detailElementName) { - this.detailElementName = detailElementName; - } - - /** - * Sets the SOAP faultstring or Reason used when validation errors occur on the request. - */ - public String getFaultStringOrReason() { - return faultStringOrReason; - } - - /** - * Sets the SOAP faultstring or Reason used when validation errors occur on the request. - * It is only added when the underlying message is a SoapMessage. Defaults to - * DEFAULT_FAULTSTRING_OR_REASON. - * - * @see #DEFAULT_FAULTSTRING_OR_REASON - */ - public void setFaultStringOrReason(String faultStringOrReason) { - this.faultStringOrReason = faultStringOrReason; - } - - /** - * Returns the SOAP fault reason locale used when validation errors occur on the request. - */ - public Locale getFaultStringOrReasonLocale() { - return faultStringOrReasonLocale; - } - - /** - * Sets the SOAP fault reason locale used when validation errors occur on the request. It is only added when the - * underlying message is a SoapMessage. Defaults to English. - * - * @see java.util.Locale#ENGLISH - */ - public void setFaultStringOrReasonLocale(Locale faultStringOrReasonLocale) { - this.faultStringOrReasonLocale = faultStringOrReasonLocale; - } - public String getSchemaLanguage() { return schemaLanguage; } @@ -236,13 +133,7 @@ public abstract class AbstractValidatingInterceptor extends TransformerObjectSup if (requestSource != null) { SAXParseException[] errors = validator.validate(requestSource); if (!ObjectUtils.isEmpty(errors)) { - for (int i = 0; i < errors.length; i++) { - logger.warn("XML validation error on request: " + errors[i].getMessage()); - } - if (messageContext.getResponse() instanceof SoapMessage) { - createRequestValidationFault((SoapMessage) messageContext.getResponse(), errors); - } - return false; + return handleRequestValidationErrors(messageContext, errors); } else if (logger.isDebugEnabled()) { logger.debug("Request message validated"); @@ -252,6 +143,22 @@ public abstract class AbstractValidatingInterceptor extends TransformerObjectSup return true; } + /** + * Template method that is called when the request message contains validation errors. Default implementation logs + * all errors, and returns false, i.e. do not process the request. + * + * @param messageContext the message context + * @param errors the validation errors + * @return true to continue processing the request, false (the default) otherwise + */ + protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors) + throws TransformerException { + for (int i = 0; i < errors.length; i++) { + logger.warn("XML validation error on request: " + errors[i].getMessage()); + } + return false; + } + /** * Validates the response message in the given message context. Validation only occurs if * validateResponse is set to true, which is not the default. @@ -268,10 +175,7 @@ public abstract class AbstractValidatingInterceptor extends TransformerObjectSup if (responseSource != null) { SAXParseException[] errors = validator.validate(responseSource); if (!ObjectUtils.isEmpty(errors)) { - for (int i = 0; i < errors.length; i++) { - logger.error("XML validation error on response: " + errors[i].getMessage()); - } - return false; + return handleResponseValidationErrors(messageContext, errors); } else if (logger.isDebugEnabled()) { logger.debug("Response message validated"); @@ -281,6 +185,21 @@ public abstract class AbstractValidatingInterceptor extends TransformerObjectSup return true; } + /** + * Template method that is called when the response message contains validation errors. Default implementation logs + * all errors, and returns false, i.e. do not send the response. + * + * @param messageContext the message context + * @param errors the validation errors @return true to continue sending the response, + * false (the default) otherwise + */ + protected boolean handleResponseValidationErrors(MessageContext messageContext, SAXParseException[] errors) { + for (int i = 0; i < errors.length; i++) { + logger.error("XML validation error on response: " + errors[i].getMessage()); + } + return false; + } + public void afterPropertiesSet() throws Exception { Assert.notEmpty(schemas, "setting either the schema or schemas property is required"); Assert.hasLength(schemaLanguage, "schemaLanguage is required"); @@ -293,22 +212,6 @@ public abstract class AbstractValidatingInterceptor extends TransformerObjectSup validator = XmlValidatorFactory.createValidator(schemas, schemaLanguage); } - /** - * Creates a response soap message containing a SoapFault that descibes the validation errors. - */ - protected void createRequestValidationFault(SoapMessage response, SAXParseException[] errors) - throws TransformerException { - SoapBody body = response.getSoapBody(); - SoapFault fault = body.addClientOrSenderFault(getFaultStringOrReason(), getFaultStringOrReasonLocale()); - if (getAddValidationErrorDetail()) { - SoapFaultDetail detail = fault.addFaultDetail(); - for (int i = 0; i < errors.length; i++) { - SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); - detailElement.addText(errors[i].getMessage()); - } - } - } - /** * Abstract template method that returns the part of the request message that is to be validated. * diff --git a/core/src/main/java/org/springframework/ws/soap/server/endpoint/interceptor/AbstractFaultCreatingValidatingInterceptor.java b/core/src/main/java/org/springframework/ws/soap/server/endpoint/interceptor/AbstractFaultCreatingValidatingInterceptor.java new file mode 100644 index 00000000..4f4da67b --- /dev/null +++ b/core/src/main/java/org/springframework/ws/soap/server/endpoint/interceptor/AbstractFaultCreatingValidatingInterceptor.java @@ -0,0 +1,165 @@ +/* + * Copyright 2007 the original author or authors. + * + * Licensed 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.springframework.ws.soap.server.endpoint.interceptor; + +import java.util.Locale; +import javax.xml.namespace.QName; +import javax.xml.transform.TransformerException; + +import org.springframework.ws.context.MessageContext; +import org.springframework.ws.server.endpoint.interceptor.AbstractValidatingInterceptor; +import org.springframework.ws.soap.SoapBody; +import org.springframework.ws.soap.SoapFault; +import org.springframework.ws.soap.SoapFaultDetail; +import org.springframework.ws.soap.SoapFaultDetailElement; +import org.springframework.ws.soap.SoapMessage; +import org.springframework.xml.namespace.QNameUtils; +import org.xml.sax.SAXParseException; + +/** + * Subclass of AbstractValidatingInterceptor that creates a SOAP Fault whenever the request message cannot + * be validated. The contents of the SOAP Fault can be specified by setting the addValidationErrorDetail, + * faultStringOrReason, or detailElementName properties. Further customizing can be + * accomplished by overriding handleRequestValidationErrors. + * + * @author Arjen Poutsma + * @see #setAddValidationErrorDetail(boolean) + * @see #setFaultStringOrReason(String) + * @see #DEFAULT_FAULTSTRING_OR_REASON + * @see #setDetailElementName(javax.xml.namespace.QName) + * @see #DEFAULT_DETAIL_ELEMENT_NAME + * @see #handleResponseValidationErrors(org.springframework.ws.context.MessageContext,org.xml.sax.SAXParseException[]) + */ +public abstract class AbstractFaultCreatingValidatingInterceptor extends AbstractValidatingInterceptor { + + /** + * Default SOAP Fault Detail name used when a validation errors occur on the request. + * + * @see #setDetailElementName(javax.xml.namespace.QName) + */ + public static final QName DEFAULT_DETAIL_ELEMENT_NAME = + QNameUtils.createQName("http://springframework.org/spring-ws", "ValidationError", "spring-ws"); + + /** + * Default SOAP Fault string used when a validation errors occur on the request. + * + * @see #setFaultStringOrReason(String) + */ + public static final String DEFAULT_FAULTSTRING_OR_REASON = "Validation error"; + + private boolean addValidationErrorDetail = true; + + private QName detailElementName = DEFAULT_DETAIL_ELEMENT_NAME; + + private String faultStringOrReason = DEFAULT_FAULTSTRING_OR_REASON; + + private Locale faultStringOrReasonLocale = Locale.ENGLISH; + + /** + * Returns whether a SOAP Fault detail element should be created when a validation error occurs. This detail element + * will contain the exact validation errors. It is only added when the underlying message is a + * SoapMessage. Defaults to true. + * + * @see org.springframework.ws.soap.SoapFault#addFaultDetail() + */ + public boolean getAddValidationErrorDetail() { + return addValidationErrorDetail; + } + + /** + * Indicates whether a SOAP Fault detail element should be created when a validation error occurs. This detail + * element will contain the exact validation errors. It is only added when the underlying message is a + * SoapMessage. Defaults to true. + * + * @see org.springframework.ws.soap.SoapFault#addFaultDetail() + */ + public void setAddValidationErrorDetail(boolean addValidationErrorDetail) { + this.addValidationErrorDetail = addValidationErrorDetail; + } + + /** + * Returns the fault detail element name when validation errors occur on the request. + */ + public QName getDetailElementName() { + return detailElementName; + } + + /** + * Sets the fault detail element name when validation errors occur on the request. Defaults to + * DEFAULT_DETAIL_ELEMENT_NAME. + * + * @see #DEFAULT_DETAIL_ELEMENT_NAME + */ + public void setDetailElementName(QName detailElementName) { + this.detailElementName = detailElementName; + } + + /** + * Sets the SOAP faultstring or Reason used when validation errors occur on the request. + */ + public String getFaultStringOrReason() { + return faultStringOrReason; + } + + /** + * Sets the SOAP faultstring or Reason used when validation errors occur on the request. + * It is only added when the underlying message is a SoapMessage. Defaults to + * DEFAULT_FAULTSTRING_OR_REASON. + * + * @see #DEFAULT_FAULTSTRING_OR_REASON + */ + public void setFaultStringOrReason(String faultStringOrReason) { + this.faultStringOrReason = faultStringOrReason; + } + + /** + * Returns the SOAP fault reason locale used when validation errors occur on the request. + */ + public Locale getFaultStringOrReasonLocale() { + return faultStringOrReasonLocale; + } + + /** + * Sets the SOAP fault reason locale used when validation errors occur on the request. It is only added when the + * underlying message is a SoapMessage. Defaults to English. + * + * @see java.util.Locale#ENGLISH + */ + public void setFaultStringOrReasonLocale(Locale faultStringOrReasonLocale) { + this.faultStringOrReasonLocale = faultStringOrReasonLocale; + } + + protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors) + throws TransformerException { + for (int i = 0; i < errors.length; i++) { + logger.warn("XML validation error on request: " + errors[i].getMessage()); + } + if (messageContext.getResponse() instanceof SoapMessage) { + SoapMessage response = (SoapMessage) messageContext.getResponse(); + SoapBody body = response.getSoapBody(); + SoapFault fault = body.addClientOrSenderFault(getFaultStringOrReason(), getFaultStringOrReasonLocale()); + if (getAddValidationErrorDetail()) { + SoapFaultDetail detail = fault.addFaultDetail(); + for (int i = 0; i < errors.length; i++) { + SoapFaultDetailElement detailElement = detail.addFaultDetailElement(getDetailElementName()); + detailElement.addText(errors[i].getMessage()); + } + } + } + return false; + } +} diff --git a/core/src/main/java/org/springframework/ws/server/endpoint/interceptor/PayloadValidatingInterceptor.java b/core/src/main/java/org/springframework/ws/soap/server/endpoint/interceptor/PayloadValidatingInterceptor.java similarity index 75% rename from core/src/main/java/org/springframework/ws/server/endpoint/interceptor/PayloadValidatingInterceptor.java rename to core/src/main/java/org/springframework/ws/soap/server/endpoint/interceptor/PayloadValidatingInterceptor.java index 9274fcfc..94377ce5 100644 --- a/core/src/main/java/org/springframework/ws/server/endpoint/interceptor/PayloadValidatingInterceptor.java +++ b/core/src/main/java/org/springframework/ws/soap/server/endpoint/interceptor/PayloadValidatingInterceptor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.ws.server.endpoint.interceptor; +package org.springframework.ws.soap.server.endpoint.interceptor; import javax.xml.transform.Source; @@ -27,16 +27,18 @@ import org.springframework.ws.WebServiceMessage; * When the payload is invalid, this interceptor stops processing of the interceptor chain. Additionally, if the message * is a SOAP request message, a SOAP Fault is created as reply. Invalid SOAP responses do not result in a fault. *

- * The schema to validate against is set with the schema property. By default, only the request message is - * validated, but this behaviour can be changed using the validateRequest and validateResponse - * properties. Responses that contains faults are not validated. + * The schema to validate against is set with the schema property or schemas property. By + * default, only the request message is validated, but this behaviour can be changed using the + * validateRequest and validateResponse properties. Responses that contains faults are not + * validated. * * @author Arjen Poutsma - * @see #setSchema + * @see #setSchema(org.springframework.core.io.Resource) + * @see #setSchemas(org.springframework.core.io.Resource[]) * @see #setValidateRequest(boolean) * @see #setValidateResponse(boolean) */ -public class PayloadValidatingInterceptor extends AbstractValidatingInterceptor { +public class PayloadValidatingInterceptor extends AbstractFaultCreatingValidatingInterceptor { /** * Returns the payload source of the given message. diff --git a/core/src/test/java/org/springframework/ws/server/endpoint/interceptor/PayloadValidatingInterceptorTest.java b/core/src/test/java/org/springframework/ws/soap/server/endpoint/interceptor/PayloadValidatingInterceptorTest.java similarity index 85% rename from core/src/test/java/org/springframework/ws/server/endpoint/interceptor/PayloadValidatingInterceptorTest.java rename to core/src/test/java/org/springframework/ws/soap/server/endpoint/interceptor/PayloadValidatingInterceptorTest.java index bdf25263..29dc972e 100644 --- a/core/src/test/java/org/springframework/ws/server/endpoint/interceptor/PayloadValidatingInterceptorTest.java +++ b/core/src/test/java/org/springframework/ws/soap/server/endpoint/interceptor/PayloadValidatingInterceptorTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.ws.server.endpoint.interceptor; +package org.springframework.ws.soap.server.endpoint.interceptor; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -27,8 +27,6 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamSource; -import org.apache.axiom.soap.SOAPFactory; -import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory; import org.custommonkey.xmlunit.XMLTestCase; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @@ -38,7 +36,7 @@ import org.springframework.ws.context.DefaultMessageContext; import org.springframework.ws.context.MessageContext; import org.springframework.ws.soap.SoapMessage; import org.springframework.ws.soap.SoapVersion; -import org.springframework.ws.soap.axiom.AxiomSoapMessage; +import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory; import org.springframework.ws.soap.saaj.SaajSoapMessage; import org.springframework.ws.soap.saaj.SaajSoapMessageFactory; import org.springframework.ws.soap.saaj.support.SaajUtils; @@ -59,9 +57,23 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { private Transformer transformer; + private static final String INVALID_MESSAGE = "invalidMessage.xml"; + + private static final String SCHEMA = "schema.xsd"; + + private static final String VALID_MESSAGE = "validMessage.xml"; + + private static final String PRODUCT_SCHEMA = "productSchema.xsd"; + + private static final String SIZE_SCHEMA = "sizeSchema.xsd"; + + private static final String VALID_SOAP_MESSAGE = "validSoapMessage.xml"; + + private static final String SCHEMA2 = "schema2.xsd"; + protected void setUp() throws Exception { interceptor = new PayloadValidatingInterceptor(); - interceptor.setSchema(new ClassPathResource("schema.xsd", getClass())); + interceptor.setSchema(new ClassPathResource(SCHEMA, getClass())); interceptor.setValidateRequest(true); interceptor.setValidateResponse(true); interceptor.afterPropertiesSet(); @@ -73,7 +85,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { public void testHandleInvalidRequestSoap11() throws Exception { SoapMessage invalidMessage = (SoapMessage) soap11Factory.createWebServiceMessage(); - InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml"); + InputStream inputStream = getClass().getResourceAsStream(INVALID_MESSAGE); transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult()); context = new DefaultMessageContext(invalidMessage, soap11Factory); @@ -92,7 +104,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { public void testHandleInvalidRequestSoap12() throws Exception { SoapMessage invalidMessage = (SoapMessage) soap12Factory.createWebServiceMessage(); - InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml"); + InputStream inputStream = getClass().getResourceAsStream(INVALID_MESSAGE); transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult()); context = new DefaultMessageContext(invalidMessage, soap12Factory); @@ -117,7 +129,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { interceptor.setAddValidationErrorDetail(false); SoapMessage invalidMessage = (SoapMessage) soap11Factory.createWebServiceMessage(); - InputStream inputStream = getClass().getResourceAsStream("invalidMessage.xml"); + InputStream inputStream = getClass().getResourceAsStream(INVALID_MESSAGE); transformer.transform(new StreamSource(inputStream), invalidMessage.getPayloadResult()); context = new DefaultMessageContext(invalidMessage, soap11Factory); @@ -136,7 +148,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { public void testHandlerInvalidRequest() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage(); - request.setPayload(new ClassPathResource("invalidMessage.xml", getClass())); + request.setPayload(new ClassPathResource(INVALID_MESSAGE, getClass())); context = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); boolean result = interceptor.handleRequest(context, null); assertFalse("Invalid response from interceptor", result); @@ -144,7 +156,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { public void testHandleValidRequest() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage(); - request.setPayload(new ClassPathResource("validMessage.xml", getClass())); + request.setPayload(new ClassPathResource(VALID_MESSAGE, getClass())); context = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); boolean result = interceptor.handleRequest(context, null); assertTrue("Invalid response from interceptor", result); @@ -155,7 +167,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { MockWebServiceMessage request = new MockWebServiceMessage(); context = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse(); - response.setPayload(new ClassPathResource("invalidMessage.xml", getClass())); + response.setPayload(new ClassPathResource(INVALID_MESSAGE, getClass())); boolean result = interceptor.handleResponse(context, null); assertFalse("Invalid response from interceptor", result); } @@ -164,7 +176,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { MockWebServiceMessage request = new MockWebServiceMessage(); context = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse(); - response.setPayload(new ClassPathResource("validMessage.xml", getClass())); + response.setPayload(new ClassPathResource(VALID_MESSAGE, getClass())); boolean result = interceptor.handleResponse(context, null); assertTrue("Invalid response from interceptor", result); } @@ -177,11 +189,11 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { System.setProperty("javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI, "org.apache.xerces.jaxp.validation.XMLSchemaFactory"); try { - interceptor.setSchema(new ClassPathResource("schema2.xsd", PayloadValidatingInterceptorTest.class)); + interceptor.setSchema(new ClassPathResource(SCHEMA2, PayloadValidatingInterceptorTest.class)); interceptor.afterPropertiesSet(); MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage saajMessage = - SaajUtils.loadMessage(new ClassPathResource("validSoapMessage.xml", getClass()), messageFactory); + SaajUtils.loadMessage(new ClassPathResource(VALID_SOAP_MESSAGE, getClass()), messageFactory); context = new DefaultMessageContext(new SaajSoapMessage(saajMessage), new SaajSoapMessageFactory(messageFactory)); @@ -208,22 +220,20 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { } public void testHandlerInvalidRequestMultipleSchemas() throws Exception { - interceptor.setSchemas(new Resource[]{new ClassPathResource("productSchema.xsd", getClass()), - new ClassPathResource("sizeSchema.xsd", getClass())}); + interceptor.setSchemas(new Resource[]{new ClassPathResource(PRODUCT_SCHEMA, getClass()), + new ClassPathResource(SIZE_SCHEMA, getClass())}); interceptor.afterPropertiesSet(); - MockWebServiceMessage request = - new MockWebServiceMessage(new ClassPathResource("invalidMessage.xml", getClass())); + MockWebServiceMessage request = new MockWebServiceMessage(new ClassPathResource(INVALID_MESSAGE, getClass())); context = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); boolean result = interceptor.handleRequest(context, null); assertFalse("Invalid response from interceptor", result); } public void testHandleValidRequestMultipleSchemas() throws Exception { - interceptor.setSchemas(new Resource[]{new ClassPathResource("productSchema.xsd", getClass()), - new ClassPathResource("sizeSchema.xsd", getClass())}); + interceptor.setSchemas(new Resource[]{new ClassPathResource(PRODUCT_SCHEMA, getClass()), + new ClassPathResource(SIZE_SCHEMA, getClass())}); interceptor.afterPropertiesSet(); - MockWebServiceMessage request = - new MockWebServiceMessage(new ClassPathResource("validMessage.xml", getClass())); + MockWebServiceMessage request = new MockWebServiceMessage(new ClassPathResource(VALID_MESSAGE, getClass())); context = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); boolean result = interceptor.handleRequest(context, null); @@ -232,40 +242,39 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase { } public void testHandleInvalidResponseMultipleSchemas() throws Exception { - interceptor.setSchemas(new Resource[]{new ClassPathResource("productSchema.xsd", getClass()), - new ClassPathResource("sizeSchema.xsd", getClass())}); + interceptor.setSchemas(new Resource[]{new ClassPathResource(PRODUCT_SCHEMA, getClass()), + new ClassPathResource(SIZE_SCHEMA, getClass())}); interceptor.afterPropertiesSet(); MockWebServiceMessage request = new MockWebServiceMessage(); context = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse(); - response.setPayload(new ClassPathResource("invalidMessage.xml", getClass())); + response.setPayload(new ClassPathResource(INVALID_MESSAGE, getClass())); boolean result = interceptor.handleResponse(context, null); assertFalse("Invalid response from interceptor", result); } public void testHandleValidResponseMultipleSchemas() throws Exception { - interceptor.setSchemas(new Resource[]{new ClassPathResource("productSchema.xsd", getClass()), - new ClassPathResource("sizeSchema.xsd", getClass())}); + interceptor.setSchemas(new Resource[]{new ClassPathResource(PRODUCT_SCHEMA, getClass()), + new ClassPathResource(SIZE_SCHEMA, getClass())}); interceptor.afterPropertiesSet(); MockWebServiceMessage request = new MockWebServiceMessage(); context = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse(); - response.setPayload(new ClassPathResource("validMessage.xml", getClass())); + response.setPayload(new ClassPathResource(VALID_MESSAGE, getClass())); boolean result = interceptor.handleResponse(context, null); assertTrue("Invalid response from interceptor", result); } public void testCreateRequestValidationFaultAxiom() throws Exception { - SOAPFactory soapFactory = new SOAP11Factory(); - AxiomSoapMessage message = new AxiomSoapMessage(soapFactory); LocatorImpl locator = new LocatorImpl(); locator.setLineNumber(0); locator.setColumnNumber(0); SAXParseException[] exceptions = new SAXParseException[]{new SAXParseException("Message 1", locator), new SAXParseException("Message 2", locator),}; - interceptor.createRequestValidationFault(message, exceptions); + MessageContext messageContext = new DefaultMessageContext(new AxiomSoapMessageFactory()); + interceptor.handleRequestValidationErrors(messageContext, exceptions); ByteArrayOutputStream os = new ByteArrayOutputStream(); - message.writeTo(os); + messageContext.getResponse().writeTo(os); assertXMLEqual("" + "" + "" + "" + "soapenv:Client" + "Validation error" + "" + diff --git a/core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/invalidMessage.xml b/core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/invalidMessage.xml similarity index 100% rename from core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/invalidMessage.xml rename to core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/invalidMessage.xml diff --git a/core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/productSchema.xsd b/core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/productSchema.xsd similarity index 87% rename from core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/productSchema.xsd rename to core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/productSchema.xsd index 83146da1..b85cf8db 100644 --- a/core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/productSchema.xsd +++ b/core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/productSchema.xsd @@ -3,7 +3,7 @@ targetNamespace="http://www.springframework.org/spring-ws/test/validation" xmlns:tns="http://www.springframework.org/spring-ws/test/validation" elementFormDefault="qualified"> - + diff --git a/core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/schema.xsd b/core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/schema.xsd similarity index 100% rename from core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/schema.xsd rename to core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/schema.xsd diff --git a/core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/schema2.xsd b/core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/schema2.xsd similarity index 100% rename from core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/schema2.xsd rename to core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/schema2.xsd diff --git a/core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/sizeSchema.xsd b/core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/sizeSchema.xsd similarity index 100% rename from core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/sizeSchema.xsd rename to core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/sizeSchema.xsd diff --git a/core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/validMessage.xml b/core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/validMessage.xml similarity index 100% rename from core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/validMessage.xml rename to core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/validMessage.xml diff --git a/core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/validSoapMessage.xml b/core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/validSoapMessage.xml similarity index 100% rename from core/src/test/resources/org/springframework/ws/server/endpoint/interceptor/validSoapMessage.xml rename to core/src/test/resources/org/springframework/ws/soap/server/endpoint/interceptor/validSoapMessage.xml diff --git a/samples/airline/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml b/samples/airline/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml index e6f137ac..eb750f40 100644 --- a/samples/airline/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml +++ b/samples/airline/src/main/resources/org/springframework/ws/samples/airline/ws/applicationContext-ws.xml @@ -82,7 +82,7 @@ + class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"> This interceptor validates both incoming and outgoing message contents according to the 'airline.xsd' XML Schema file. diff --git a/samples/echo/src/main/webapp/WEB-INF/log4j.properties b/samples/echo/src/main/resources/log4j.properties similarity index 100% rename from samples/echo/src/main/webapp/WEB-INF/log4j.properties rename to samples/echo/src/main/resources/log4j.properties diff --git a/samples/echo/src/main/webapp/WEB-INF/spring-ws-servlet.xml b/samples/echo/src/main/webapp/WEB-INF/spring-ws-servlet.xml index 7c46b465..a480e5fe 100755 --- a/samples/echo/src/main/webapp/WEB-INF/spring-ws-servlet.xml +++ b/samples/echo/src/main/webapp/WEB-INF/spring-ws-servlet.xml @@ -23,7 +23,7 @@ + class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"> This interceptor validates both incoming and outgoing message contents according to the 'echo.xsd' XML Schema file.