public abstract class AbstractValidatingInterceptor extends TransformerObjectSupport implements ClientInterceptor, org.springframework.beans.factory.InitializingBean
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.
getValidationRequestSource(WebServiceMessage),
getValidationResponseSource(WebServiceMessage)logger| Constructor and Description |
|---|
AbstractValidatingInterceptor() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterCompletion(MessageContext messageContext,
Exception ex)
Does nothing by default.
|
void |
afterPropertiesSet() |
String |
getSchemaLanguage() |
org.springframework.core.io.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)
Does nothing by default.
|
boolean |
handleRequest(MessageContext messageContext)
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)
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(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 the
XsdSchema to use for validation. |
void |
setXsdSchemaCollection(XsdSchemaCollection schemaCollection)
Sets the
XsdSchemaCollection to use for validation. |
createTransformer, getTransformerFactory, newTransformerFactory, setTransformerFactoryClass, transformpublic String getSchemaLanguage()
public void setSchemaLanguage(String schemaLanguage)
http://www.w3.org/2001/XMLSchema".public org.springframework.core.io.Resource[] getSchemas()
public void setSchema(org.springframework.core.io.Resource schema)
xsdSchemaCollection, schema, or schemas is required.public void setSchemas(org.springframework.core.io.Resource[] schemas)
xsdSchemaCollection, schema, or schemas is required.public void setXsdSchema(XsdSchema schema) throws IOException
XsdSchema to use for validation. Setting this property, xsdSchemaCollection, schema, or schemas is required.schema - the xsd schema to useIOException - in case of I/O errorspublic void setXsdSchemaCollection(XsdSchemaCollection schemaCollection) throws IOException
XsdSchemaCollection to use for validation. Setting this property, xsdSchema, schema, or schemas is required.schemaCollection - the xsd schema collection to useIOException - in case of I/O errorspublic void setValidateRequest(boolean validateRequest)
true.public void setValidateResponse(boolean validateResponse)
false.public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic boolean handleRequest(MessageContext messageContext) throws WebServiceClientException
validateRequest is set to true, which is the default.
Returns true if the request is valid, or false if it isn't.
handleRequest in interface ClientInterceptormessageContext - the message contexttrue if the message is valid; false otherwiseWebServiceClientException - in case of errorssetValidateRequest(boolean)protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)
Default implementation logs all errors, and throws a WebServiceValidationException. Subclasses can
override this method to customize this behavior.
messageContext - the message contexterrors - the validation errorstrue to continue processing the request, false otherwisepublic boolean handleResponse(MessageContext messageContext) throws WebServiceClientException
validateResponse is set to true, which is not the
default.
Returns true if the request is valid, or false if it isn't.
handleResponse in interface ClientInterceptormessageContext - the message context.true if the response is valid; false otherwiseWebServiceClientException - in case of errorssetValidateResponse(boolean)protected boolean handleResponseValidationErrors(MessageContext messageContext, SAXParseException[] errors) throws WebServiceValidationException
Default implementation logs all errors, and returns false, i.e. do not cot continue to process the
respone interceptor chain.
messageContext - the message contexterrors - the validation errorstrue to continue the reponse interceptor chain, false (the default) otherwiseWebServiceValidationExceptionpublic boolean handleFault(MessageContext messageContext) throws WebServiceClientException
handleFault in interface ClientInterceptormessageContext - contains the outgoing request messagetrue to continue processing of the request interceptors; false to indicate
blocking of the request endpoint chainWebServiceClientException - in case of errorsMessageContext.getResponse(),
FaultAwareWebServiceMessage.hasFault()public void afterCompletion(MessageContext messageContext, Exception ex) throws WebServiceClientException
afterCompletion in interface ClientInterceptormessageContext - contains both request and response messages, the response should contains a Faultex - exception thrown on handler execution, if anyWebServiceClientException - in case of errorsprotected abstract Source getValidationRequestSource(WebServiceMessage request)
request - the request messagenull not to validate anythingprotected abstract Source getValidationResponseSource(WebServiceMessage response)
response - the response messagenull not to validate anything