org.springframework.ws.endpoint.interceptor
Class AbstractValidatingInterceptor

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

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. Responses that contains SOAP faults are not validated.

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

Field Summary
static QName DEFAULT_DETAIL_ELEMENT_NAME
          Default SOAP Fault Detail name used when a validation errors occur on the request.
static String DEFAULT_FAULTSTRING_OR_REASON
          Default SOAP Fault string used when a validation errors occur on the request.
protected  Log logger
           
 
Constructor Summary
AbstractValidatingInterceptor()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  void createRequestValidationFault(SoapMessageContext context, SAXParseException[] errors)
          Creates a response soap message containing a SoapFault that descibes the validation errors.
 boolean getAddValidationErrorDetail()
           
 QName getDetailElementName()
          Returns the fault detail element name when validation errors occur on the request.
 String getFaultStringOrReason()
          Sets the SOAP faultstring or Reason used when validation errors occur on the request.
 Locale getFaultStringOrReasonLocale()
          Returns the SOAP fault reason locale used when validation errors occur on the request.
 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 handleRequest(MessageContext messageContext, Object endpoint)
          Validates the request message in the given message context.
 boolean handleResponse(MessageContext messageContext, Object endpoint)
          Validates the response message in the given message context.
 void setAddValidationErrorDetail(boolean addValidationErrorDetail)
          Indicates whether a SOAP Fault detail element should be created when a validation error occurs.
 void setDetailElementName(QName detailElementName)
          Sets the fault detail element name when validation errors occur on the request.
 void setFaultStringOrReason(String faultStringOrReason)
          Sets the SOAP faultstring or Reason used when validation errors occur on the request.
 void setFaultStringOrReasonLocale(Locale faultStringOrReasonLocale)
          Sets the SOAP fault reason locale used when validation errors occur on the request.
 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.
 
Methods inherited from class org.springframework.ws.endpoint.TransformerObjectSupport
createTransformer, createTransformerFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DETAIL_ELEMENT_NAME

public static final QName DEFAULT_DETAIL_ELEMENT_NAME
Default SOAP Fault Detail name used when a validation errors occur on the request.

See Also:
setDetailElementName(javax.xml.namespace.QName)

DEFAULT_FAULTSTRING_OR_REASON

public static final String DEFAULT_FAULTSTRING_OR_REASON
Default SOAP Fault string used when a validation errors occur on the request.

See Also:
setFaultStringOrReason(String), Constant Field Values

logger

protected final Log logger
Constructor Detail

AbstractValidatingInterceptor

public AbstractValidatingInterceptor()
Method Detail

getAddValidationErrorDetail

public boolean getAddValidationErrorDetail()

setAddValidationErrorDetail

public void setAddValidationErrorDetail(boolean 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 Also:
SoapFault.addFaultDetail()

getDetailElementName

public QName getDetailElementName()
Returns the fault detail element name when validation errors occur on the request.


setDetailElementName

public void setDetailElementName(QName detailElementName)
Sets the fault detail element name when validation errors occur on the request. Defaults to DEFAULT_DETAIL_ELEMENT_NAME.

See Also:
DEFAULT_DETAIL_ELEMENT_NAME

getFaultStringOrReason

public String getFaultStringOrReason()
Sets the SOAP faultstring or Reason used when validation errors occur on the request.


setFaultStringOrReason

public void setFaultStringOrReason(String 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 Also:
DEFAULT_FAULTSTRING_OR_REASON

getFaultStringOrReasonLocale

public Locale getFaultStringOrReasonLocale()
Returns the SOAP fault reason locale used when validation errors occur on the request.


setFaultStringOrReasonLocale

public void setFaultStringOrReasonLocale(Locale 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 Also:
Locale.ENGLISH

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.


setSchemas

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


setSchema

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


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,
                             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 messageContext is a SoapMessageContext, a SOAP Fault 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)

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)

afterPropertiesSet

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

createRequestValidationFault

protected void createRequestValidationFault(SoapMessageContext context,
                                            SAXParseException[] errors)
                                     throws TransformerException
Creates a response soap message containing a SoapFault that descibes the validation errors.

Throws:
TransformerException

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


Copyright (c) 2005-2006 The Spring Framework Project.