Class AbstractValidatingInterceptor
java.lang.Object
org.springframework.xml.transform.TransformerObjectSupport
org.springframework.ws.server.endpoint.interceptor.AbstractValidatingInterceptor
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
,EndpointInterceptor
- Direct Known Subclasses:
AbstractFaultCreatingValidatingInterceptor
public abstract class AbstractValidatingInterceptor
extends TransformerObjectSupport
implements EndpointInterceptor, org.springframework.beans.factory.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:
-
Field Summary
Fields inherited from class org.springframework.xml.transform.TransformerObjectSupport
logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterCompletion
(MessageContext messageContext, Object endpoint, Exception ex) Does nothing by default.void
org.springframework.core.io.Resource[]
Returns the schema resources to use for validation.protected abstract Source
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
setErrorHandler
(ValidationErrorHandler errorHandler) Sets the error handler to use for validation.void
setSchema
(org.springframework.core.io.Resource schema) Sets the schema resource to use for validation.void
setSchemaLanguage
(String schemaLanguage) Sets the schema language.void
setSchemas
(org.springframework.core.io.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 theXsdSchema
to use for validation.void
setXsdSchemaCollection
(XsdSchemaCollection schemaCollection) Sets theXsdSchemaCollection
to use for validation.Methods inherited from class org.springframework.xml.transform.TransformerObjectSupport
createTransformer, getTransformerFactory, newTransformerFactory, setTransformerFactoryClass, transform
-
Constructor Details
-
AbstractValidatingInterceptor
public AbstractValidatingInterceptor()
-
-
Method Details
-
getSchemaLanguage
-
setSchemaLanguage
Sets the schema language. Default is the W3C XML Schema:http://www.w3.org/2001/XMLSchema"
. -
getSchemas
public org.springframework.core.io.Resource[] getSchemas()Returns the schema resources to use for validation. -
setSchema
public void setSchema(org.springframework.core.io.Resource schema) Sets the schema resource to use for validation. Setting this property,xsdSchemaCollection
,schema
, orschemas
is required. -
setSchemas
public void setSchemas(org.springframework.core.io.Resource... schemas) Sets the schema resources to use for validation. Setting this property,xsdSchemaCollection
,schema
, orschemas
is required. -
setXsdSchema
Sets theXsdSchema
to use for validation. Setting this property,xsdSchemaCollection
,schema
, orschemas
is required.- Parameters:
schema
- the xsd schema to use- Throws:
IOException
- in case of I/O errors
-
setXsdSchemaCollection
Sets theXsdSchemaCollection
to use for validation. Setting this property,xsdSchema
,schema
, orschemas
is required.- Parameters:
schemaCollection
- the xsd schema collection to use- Throws:
IOException
- in case of I/O errors
-
setErrorHandler
Sets the error handler to use for validation. If not set, a default error handler will be used.- Parameters:
errorHandler
- the error handler.
-
setValidateRequest
public void setValidateRequest(boolean validateRequest) Indicates whether the request should be validated against the schema. Default istrue
. -
setValidateResponse
public void setValidateResponse(boolean validateResponse) Indicates whether the response should be validated against the schema. Default isfalse
. -
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.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 ifvalidateRequest
is set totrue
, which is the default.Returns
true
if the request is valid, orfalse
if it isn't. Additionally, when the request message is aSoapMessage
, aSoapFault
is added as response.- Specified by:
handleRequest
in interfaceEndpointInterceptor
- Parameters:
messageContext
- the message contextendpoint
- chosen endpoint to invoke- Returns:
true
if the message is valid;false
otherwise- Throws:
IOException
SAXException
TransformerException
- See Also:
-
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 returnsfalse
, i.e. do not process the request.- Parameters:
messageContext
- the message contexterrors
- 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 ifvalidateResponse
is set totrue
, which is not the default.Returns
true
if the request is valid, orfalse
if it isn't.- Specified by:
handleResponse
in interfaceEndpointInterceptor
- Parameters:
messageContext
- the message context.endpoint
- chosen endpoint to invoke- Returns:
true
if the response is valid;false
otherwise- Throws:
IOException
SAXException
- See Also:
-
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 returnsfalse
, i.e. do not cot continue to process the response interceptor chain.- Parameters:
messageContext
- the message contexterrors
- the validation errors- Returns:
true
to continue the response interceptor chain,false
(the default) otherwise
-
handleFault
Does nothing by default. Faults are not validated.- Specified by:
handleFault
in interfaceEndpointInterceptor
- Parameters:
messageContext
- contains both request and response messages, the response should contains a Faultendpoint
- chosen endpoint to invoke- Returns:
true
to continue processing of the response interceptor chain;false
to indicate blocking of the response handler chain.- Throws:
Exception
-
afterCompletion
Does nothing by default.- Specified by:
afterCompletion
in interfaceEndpointInterceptor
- Parameters:
messageContext
- contains both request and response messages, the response should contains a Faultendpoint
- chosen endpoint to invokeex
- exception thrown on handler execution, if any
-
getValidationRequestSource
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
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
-