Class AbstractValidatingInterceptor
java.lang.Object
org.springframework.xml.transform.TransformerObjectSupport
org.springframework.ws.client.support.interceptor.AbstractValidatingInterceptor
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, ClientInterceptor
- Direct Known Subclasses:
PayloadValidatingInterceptor
public abstract class AbstractValidatingInterceptor
extends TransformerObjectSupport
implements ClientInterceptor, org.springframework.beans.factory.InitializingBean
Abstract base class for
ClientInterceptor implementations that validate part of
the message using a schema. The exact message part is determined by the
getValidationRequestSource(WebServiceMessage) and
getValidationResponseSource(WebServiceMessage) template methods.
By default, only the request message is validated, but this behaviour can be changed
using the validateRequest and validateResponse properties.
- Since:
- 1.5.4
- See Also:
-
Field Summary
Fields inherited from class TransformerObjectSupport
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterCompletion(MessageContext messageContext, @Nullable Exception ex) Does nothing by default.voidorg.springframework.core.io.Resource[]Returns the schema resources to use for validation.protected abstract @Nullable SourceAbstract template method that returns the part of the request message that is to be validated.protected abstract @Nullable SourcegetValidationResponseSource(WebServiceMessage response) Abstract template method that returns the part of the response message that is to be validated.booleanhandleFault(MessageContext messageContext) Does nothing by default.booleanhandleRequest(MessageContext messageContext) Validates the request message in the given message context.protected booleanhandleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors) Template method that is called when the request message contains validation errors.booleanhandleResponse(MessageContext messageContext) Validates the response message in the given message context.protected booleanhandleResponseValidationErrors(MessageContext messageContext, SAXParseException[] errors) Template method that is called when the response message contains validation errors.voidsetSchema(org.springframework.core.io.Resource schema) Sets the schema resource to use for validation.voidsetSchemaLanguage(String schemaLanguage) Sets the schema language.voidsetSchemas(org.springframework.core.io.Resource... schemas) Sets the schema resources to use for validation.voidsetValidateRequest(boolean validateRequest) Indicates whether the request should be validated against the schema.voidsetValidateResponse(boolean validateResponse) Indicates whether the response should be validated against the schema.voidsetXsdSchema(XsdSchema schema) Sets theXsdSchemato use for validation.voidsetXsdSchemaCollection(XsdSchemaCollection schemaCollection) Sets theXsdSchemaCollectionto use for validation.Methods inherited from class 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".- See Also:
-
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,schemas, orxsdSchemais required. -
setSchemas
public void setSchemas(org.springframework.core.io.Resource... schemas) Sets the schema resources to use for validation. Setting this property,xsdSchemaCollection,schema, orxsdSchemais required. -
setXsdSchema
Sets theXsdSchemato use for validation. Setting this property,xsdSchemaCollection,schema, orschemasis required.- Parameters:
schema- the xsd schema to use- Throws:
IOException- in case of I/O errors
-
setXsdSchemaCollection
Sets theXsdSchemaCollectionto use for validation. Setting this property,xsdSchema,schema, orschemasis 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 istrue. -
setValidateResponse
public void setValidateResponse(boolean validateResponse) Indicates whether the response should be validated against the schema. Default isfalse. -
afterPropertiesSet
-
handleRequest
Validates the request message in the given message context. Validation only occurs ifvalidateRequestis set totrue, which is the default.Returns
trueif the request is valid, orfalseif it isn't.- Specified by:
handleRequestin interfaceClientInterceptor- Parameters:
messageContext- the message context- Returns:
trueif the message is valid;falseotherwise- Throws:
WebServiceClientException- in case of errors- See Also:
-
handleRequestValidationErrors
protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors) Template method that is called when the request message contains validation errors.Default implementation logs all errors, and throws a
WebServiceValidationException. Subclasses can override this method to customize this behavior.- Parameters:
messageContext- the message contexterrors- the validation errors- Returns:
trueto continue processing the request,falseotherwise
-
handleResponse
Validates the response message in the given message context. Validation only occurs ifvalidateResponseis set totrue, which is not the default.Returns
trueif the request is valid, orfalseif it isn't.- Specified by:
handleResponsein interfaceClientInterceptor- Parameters:
messageContext- the message context.- Returns:
trueif the response is valid;falseotherwise- Throws:
WebServiceClientException- in case of errors- See Also:
-
handleResponseValidationErrors
protected boolean handleResponseValidationErrors(MessageContext messageContext, SAXParseException[] errors) throws WebServiceValidationException 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 contexterrors- the validation errors- Returns:
trueto continue the reponse interceptor chain,false(the default) otherwise- Throws:
WebServiceValidationException
-
handleFault
Does nothing by default. Faults are not validated.- Specified by:
handleFaultin interfaceClientInterceptor- Parameters:
messageContext- contains the outgoing request message- Returns:
trueto continue processing of the request interceptors;falseto indicate blocking of the request endpoint chain- Throws:
WebServiceClientException- in case of errors- See Also:
-
afterCompletion
public void afterCompletion(MessageContext messageContext, @Nullable Exception ex) throws WebServiceClientException Does nothing by default.- Specified by:
afterCompletionin interfaceClientInterceptor- Parameters:
messageContext- contains both request and response messages, the response should contains a Faultex- exception thrown on handler execution, if any- Throws:
WebServiceClientException- in case of errors
-
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
nullnot 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
nullnot to validate anything
-