org.springframework.ws.endpoint
Class PayloadValidatingInterceptor

java.lang.Object
  extended by org.springframework.ws.endpoint.PayloadValidatingInterceptor
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, EndpointInterceptor, SoapEndpointInterceptor

public class PayloadValidatingInterceptor
extends java.lang.Object
implements SoapEndpointInterceptor, org.springframework.beans.factory.InitializingBean

Interceptor that validates the contents of WebServiceMessages using a schema. Allows for both W3C XML and RELAX NG schemas.

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.

Author:
Arjen Poutsma
See Also:
setSchema(org.springframework.core.io.Resource), setValidateRequest(boolean), setValidateResponse(boolean)

Constructor Summary
PayloadValidatingInterceptor()
           
 
Method Summary
 void afterPropertiesSet()
           
 boolean handleFault(MessageContext messageContext, java.lang.Object endpoint)
          Returns true, i.e.
 boolean handleRequest(MessageContext messageContext, java.lang.Object endpoint)
          Validates the request message in the given message context.
 boolean handleResponse(MessageContext messageContext, java.lang.Object endpoint)
          Validates the response message in the given message context.
 void setSchema(org.springframework.core.io.Resource schema)
          Sets the schema resource to use for validation.
 void setSchemaLanguage(java.lang.String schemaLanguage)
          Sets the schema language.
 void setValidateRequest(boolean validateRequest)
          Indicates whether the request should be validated against the schema.
 void setValidateResponse(boolean validateResponse)
          Indicates whether the response should be validated against the schema.
 boolean understands(SoapHeaderElement header)
          Returns false, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PayloadValidatingInterceptor

public PayloadValidatingInterceptor()
Method Detail

setSchema

public void setSchema(org.springframework.core.io.Resource schema)
Sets the schema resource to use for validation.


setSchemaLanguage

public void setSchemaLanguage(java.lang.String schemaLanguage)
Sets the schema language. Default is the W3C XML Schema: http://www.w3.org/2001/XMLSchema".

See Also:
XmlValidatorFactory.SCHEMA_W3C_XML, XmlValidatorFactory.SCHEMA_RELAX_NG

setValidateRequest

public void setValidateRequest(boolean validateRequest)
Indicates whether the request should be validated against the schema. Default is true.


setValidateResponse

public void setValidateResponse(boolean validateResponse)
Indicates whether the response should be validated against the schema. Default is false.


handleRequest

public boolean handleRequest(MessageContext messageContext,
                             java.lang.Object endpoint)
                      throws java.io.IOException,
                             org.xml.sax.SAXException
Validates the request message in the given message context. Validation only occurs if validateRequest is set to true, which is the default.

Returns true if the request is valid, or false if it isn't. Additionally, when the messageContext is a SoapMessageContext, a SOAP Fault is added as response.

Specified by:
handleRequest in interface EndpointInterceptor
Parameters:
messageContext - the message context
endpoint -
Returns:
true if the message is valid; false otherwise
Throws:
java.io.IOException
org.xml.sax.SAXException
See Also:
setValidateRequest(boolean)

handleResponse

public boolean handleResponse(MessageContext messageContext,
                              java.lang.Object endpoint)
                       throws java.io.IOException,
                              org.xml.sax.SAXException
Validates the response message in the given message context. Validation only occurs if validateResponse is set to true, which is not the default.

Returns true if the request is valid, or false if it isn't.

Specified by:
handleResponse in interface EndpointInterceptor
Parameters:
messageContext - the message context.
endpoint -
Returns:
true if the response is valid; false otherwise
Throws:
java.io.IOException
org.xml.sax.SAXException
See Also:
setValidateResponse(boolean)

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

handleFault

public boolean handleFault(MessageContext messageContext,
                           java.lang.Object endpoint)
                    throws java.lang.Exception
Returns true, i.e. SOAP Faults are not validated.

Specified by:
handleFault in interface SoapEndpointInterceptor
Parameters:
messageContext - contains both request and response messages, the response should contains a SOAP Fault
endpoint - chosen endpoint to invoke
Returns:
true to continue processing of the reponse interceptor chain; false to indicate blocking of the response handler chain.
Throws:
java.lang.Exception

understands

public boolean understands(SoapHeaderElement header)
Returns false, i.e. all SOAP Headers are not understood.

Specified by:
understands in interface SoapEndpointInterceptor
Parameters:
header - the header
Returns:
true if understood, false otherwise


Copyright © 2002-2006. All Rights Reserved.