Sunday, August 31, 2014

[WSO2 ESB] Using [resource] attribute for [xsd:import] elements in a scheme file with Validate Mediator

The Validate Mediator in WSO2 ESB is used for schema validation of messages. Then this message is validated against the schema specified.

When we use validate mediator against a schema that schema file itself can contain some other schema references under <xsd:import> elements like below.

If our schema file is like this, in this scenario validate mediator tries to map and find the internal schemas which are defined in <xsd:import> elements. If these cannot be found, ESB will log an error saying that "The resource "{resource_file_name} can not be located"

Therefore in order to use these schema files with validate mediator follow the steps given below.

1. First add all the xsd files as local entries to ESB. These is no relative paths or nested folders supported so the xsd files has to be in local-entries folder itself. However if you put the schemas into registry nested folders are supported.

2. In the validate mediator there is an attribute called <resource>. Use this option to tell the validate mediator on where to find the files to import as below. Make sure ‘location’ and ‘schemaLocation’ entries has the same file name in order to map those correctly. Then the 'key' attribute is used to specify the current location of this schema file as shown in the given exmaple.

If you have added the schema files as registry entries, and when there are relative paths mentioned in parent schema, validate mediator can be used in  the following manner.


  1. Hi Ishara,

    Interesting post. I have a quick question that I require your assistance with please. I noticed that when you reference the XSD files, you do so with the .xsd extension. However, if you create the XSD file via the Local Entries, it creates a fphysical file with a .xml extension. Does this affect the way the XSD should be invoked? Should it be reference as "key=MockDataTypes.xsd" or "key="MockDataTypes"?

    Many thanks

  2. Hi,
    The best practice is adding the schema files into a registry project and externalize it. Because if you add it into a local entry, whenever the schema changes it is required to redeploy the car (*.car file). if it is in registry this is not needed. However if you add schema file as a xml in local entry, call it as a named reference, as key="MockDataTypes". I have not tested this out (i always use registry for schemas), so better try and see whether it works.