Spring Web Services Framework

org.springframework.ws.server.endpoint.interceptor
Class AbstractValidatingInterceptor

java.lang.Object
  extended by org.springframework.xml.transform.TransformerObjectSupport
      extended by org.springframework.ws.server.endpoint.interceptor.AbstractValidatingInterceptor
All Implemented Interfaces:
InitializingBean, EndpointInterceptor
Direct Known Subclasses:
AbstractFaultCreatingValidatingInterceptor

public abstract class AbstractValidatingInterceptor
extends TransformerObjectSupport
implements EndpointInterceptor, InitializingBean

Abstract base class for EndpointInterceptor implementations that validate part of the message using a schema. The exact message part is determined by the getValidationRequestSource and getValidationResponseSource template methods.

By default, only the request message is validated, but this behaviour can be changed using the validateRequest and validateResponse properties.

Since:
1.0.0
Author:
Arjen Poutsma
See Also:
getValidationRequestSource(org.springframework.ws.WebServiceMessage), getValidationResponseSource(org.springframework.ws.WebServiceMessage)

Field Summary
 
Fields inherited from class org.springframework.xml.transform.TransformerObjectSupport
logger
 
Constructor Summary
AbstractValidatingInterceptor()
           
 
Method Summary
 void afterPropertiesSet()
           
 String getSchemaLanguage()
           
 Resource[] getSchemas()
          Returns the schema resources to use for validation.
protected abstract  Source getValidationRequestSource(WebServiceMessage request)
          Abstract template method that returns the part of the request message that is to be validated.
protected abstract  Source getValidationResponseSource(WebServiceMessage response)
          Abstract template method that returns the part of the response message that is to be validated.
 boolean handleFault(MessageContext messageContext, Object endpoint)
          Does nothing by default.
 boolean handleRequest(MessageContext messageContext, Object endpoint)
          Validates the request message in the given message context.
protected  boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)
          Template method that is called when the request message contains validation errors.
 boolean handleResponse(MessageContext messageContext, Object endpoint)
          Validates the response message in the given message context.
protected  boolean handleResponseValidationErrors(MessageContext messageContext, SAXParseException[] errors)
          Template method that is called when the response message contains validation errors.
 void setSchema(Resource schema)
          Sets the schema resource to use for validation.
 void setSchemaLanguage(String schemaLanguage)
          Sets the schema language.
 void setSchemas(Resource[] schemas)
          Sets the schema resources to use for validation.
 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.
 void setXsdSchema(XsdSchema schema)
          Sets the XsdSchema to use for validation.
 void setXsdSchemaCollection(XsdSchemaCollection schemaCollection)
          Sets the XsdSchemaCollection to use for validation.
 
Methods inherited from class org.springframework.xml.transform.TransformerObjectSupport
createTransformer, getTransformerFactory, newTransformerFactory, setTransformerFactoryClass, transform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractValidatingInterceptor

public AbstractValidatingInterceptor()
Method Detail

getSchemaLanguage

public String getSchemaLanguage()

setSchemaLanguage

public void setSchemaLanguage(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

getSchemas

public Resource[] getSchemas()
Returns the schema resources to use for validation.


setSchema

public void setSchema(Resource schema)
Sets the schema resource to use for validation. Setting this property, xsdSchemaCollection, schema, or schemas is required.


setSchemas

public void setSchemas(Resource[] schemas)
Sets the schema resources to use for validation. Setting this property, xsdSchemaCollection, schema, or schemas is required.


setXsdSchema

public void setXsdSchema(XsdSchema schema)
                  throws IOException
Sets the XsdSchema to use for validation. Setting this property, xsdSchemaCollection, schema, or schemas is required.

Parameters:
schema - the xsd schema to use
Throws:
IOException - in case of I/O errors

setXsdSchemaCollection

public void setXsdSchemaCollection(XsdSchemaCollection schemaCollection)
                            throws IOException
Sets the XsdSchemaCollection to use for validation. Setting this property, xsdSchema, schema, or schemas is required.

Parameters:
schemaCollection - the xsd schema collection to use
Throws:
IOException - in case of I/O errors

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.


afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

handleRequest

public boolean handleRequest(MessageContext messageContext,
                             Object endpoint)
                      throws IOException,
                             SAXException,
                             TransformerException
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 request message is a SoapMessage, a SoapFault is added as response.

Specified by:
handleRequest in interface EndpointInterceptor
Parameters:
messageContext - the message context
endpoint - chosen endpoint to invoke
Returns:
true if the message is valid; false otherwise
Throws:
IOException
SAXException
TransformerException
See Also:
setValidateRequest(boolean)

handleRequestValidationErrors

protected boolean handleRequestValidationErrors(MessageContext messageContext,
                                                SAXParseException[] errors)
                                         throws TransformerException
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.

Parameters:
messageContext - the message context
errors - the validation errors
Returns:
true to continue processing the request, false (the default) otherwise
Throws:
TransformerException

handleResponse

public boolean handleResponse(MessageContext messageContext,
                              Object endpoint)
                       throws IOException,
                              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 - chosen endpoint to invoke
Returns:
true if the response is valid; false otherwise
Throws:
IOException
SAXException
See Also:
setValidateResponse(boolean)

handleResponseValidationErrors

protected boolean handleResponseValidationErrors(MessageContext messageContext,
                                                 SAXParseException[] errors)
Template method that is called when the response message contains validation errors. Default implementation logs all errors, and returns false, i.e. do not cot continue to process the respone interceptor chain.

Parameters:
messageContext - the message context
errors - the validation errors
Returns:
true to continue the reponse interceptor chain, false (the default) otherwise

handleFault

public boolean handleFault(MessageContext messageContext,
                           Object endpoint)
                    throws Exception
Does nothing by default. Faults are not validated.

Specified by:
handleFault in interface EndpointInterceptor
Parameters:
messageContext - contains both request and response messages, the response should contains a 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:
Exception

getValidationRequestSource

protected abstract Source getValidationRequestSource(WebServiceMessage request)
Abstract template method that returns the part of the request message that is to be validated.

Parameters:
request - the request message
Returns:
the part of the message that is to validated, or null not to validate anything

getValidationResponseSource

protected abstract Source getValidationResponseSource(WebServiceMessage response)
Abstract template method that returns the part of the response message that is to be validated.

Parameters:
response - the response message
Returns:
the part of the message that is to validated, or null not to validate anything

Spring Web Services Framework

Copyright © 2005-2010 The Spring Web Services Framework. All Rights Reserved.