@ComponentProfile(summary="Validate an XML document against a schema", recommended=CacheConnection.class) public class XmlSchemaValidator extends MessageValidatorImpl
XmlValidationService
to validate an XML message against a schema.
This validates an input XML document against a schema. After first use, it caches the schema for re-use against the URL that was resolved as an expression or from static configuration. This means that until first use, no attempt is made to access the schema URL.
In the adapter configuration file this class is aliased as xml-schema-validator which is the preferred alternative to the fully qualified classname when building your configuration.
log
Constructor and Description |
---|
XmlSchemaValidator() |
XmlSchemaValidator(java.lang.String schema) |
XmlSchemaValidator(java.lang.String schema,
java.lang.String metadataKey)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the component.
|
java.lang.String |
getSchema()
Returns the schema to validate against.
|
AdaptrisConnection |
getSchemaCache() |
java.lang.String |
getSchemaMetadataKey()
Deprecated.
since 3.8.4 use an expression based
setSchema(String) instead. |
void |
init()
Initialises the component.
|
void |
prepare()
Prepare for initialisation.
|
void |
setSchema(java.lang.String s)
Sets the schema to validate against.
|
void |
setSchemaCache(AdaptrisConnection cache)
Configure the internal cache for schemas.
|
void |
setSchemaMetadataKey(java.lang.String s)
Deprecated.
since 3.8.4 use an expression based
setSchema(String) instead. |
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
void |
validate(AdaptrisMessage msg) |
XmlSchemaValidator |
withSchemaCache(AdaptrisConnection c) |
public XmlSchemaValidator()
public XmlSchemaValidator(java.lang.String schema)
@Deprecated public XmlSchemaValidator(java.lang.String schema, java.lang.String metadataKey)
public void validate(AdaptrisMessage msg) throws CoreException
CoreException
public void prepare() throws CoreException
ComponentLifecycleExtension
prepare
in interface ComponentLifecycleExtension
prepare
in class MessageValidatorImpl
CoreException
public void init() throws CoreException
ComponentLifecycle
Component initialisation includes config verification, creation of connections etc.
CoreException
- wrapping any underlying Exception
spublic void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer
, calling start
will begin message delivery.
CoreException
- wrapping any underlying Exception
spublic void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer
, calling stop
will pause message delivery. Throwing a RuntimeException
may cause unintended consequences
public void close()
ComponentLifecycle
A closed component should release any connections it uses, etc. and clean up completely. Throwing a RuntimeException
may
cause unintended consequences
public void setSchema(java.lang.String s)
s
- the schema to validate against, normally a URL.public java.lang.String getSchema()
@Deprecated @Removal(version="3.11.0", message="use an expression based schema value instead.") public java.lang.String getSchemaMetadataKey()
setSchema(String)
instead.@Deprecated @Removal(version="3.11.0", message="use an expression based schema value instead.") public void setSchemaMetadataKey(java.lang.String s)
setSchema(String)
instead.s
- the (optional) metadata key against which a schema can be provided at run timepublic AdaptrisConnection getSchemaCache()
public void setSchemaCache(AdaptrisConnection cache)
While it is possible to configure a distributed cache (a-la ehcache or JSR107) the Schema
object
isn't serializable, so you may run into issues. It will be best to stick with ExpiringMapCache
if you want to enable
caching. The default behaviour is to cache 16 schemas for a max of 2 hours (last-access) if you don't explicitly configure it
differently.
cache
- the cache, generally a CacheConnection
or SharedConnection
.public XmlSchemaValidator withSchemaCache(AdaptrisConnection c)