Using your own WSDL with a WSO2 ESB Proxy Service

wso2-logo-e1412323639751It is common practice to use an external XSD file in your WSDL. This way you can easily reuse your XSD at other places. However if you want to use such WSDL in your WSO2 ESB Proxy Service you have to configure the path to the XSD correctly.
This post describes how to set this up. More background info about this can be found here. I created a Multi Module Maven project and added the WSDL artifact and the XSD’s so I got a result like this:
Screenshot at Dec 06 17-36-43
In the WSDL I imported the ‘EchoElements.xsd’ like this:

<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<wsdl:definitions xmlns:soap='' 
xmlns:tns='' xmlns:elm='' 
xmlns:wsdl='' xmlns:xsd='' name='EchoWsdl' targetNamespace=''>
       <xsd:import namespace=''
		schemaLocation='../xsd/EchoElements.xsd' />

As you can see I go up one directory and look for the XSD file in the ‘xsd’ folder.
In the corresponding EchoElements.xsd I also import another XSD like this:

  <xs:import namespace=''  schemaLocation='./EchoTypes.xsd' />

So in the same folder as the ‘parent’ XSD I am looking for the ‘EchoTypes.xsd’ folder.

Now this will translate to the following proxy service configuration :

  <publishWSDL key='gov:wsdl/EchoWsdl.wsdl'>
     <resource location='../xsd/EchoElements.xsd' key='gov:/xsd/EchoElements.xsd'/>
     <resource location='./EchoTypes.xsd' key='gov:/xsd/EchoTypes.xsd'/>

As you can see the keys defined are pointing to the keys of the artifacts in the registry. Another import thin g to notice is that the location attribute of the resource has to match the defined schema location attribute in the artifact that is importing the resource.
If we for example modify the ‘EchoElements.xsd’ and rewrite the import element to this:

  <xs:import namespace=''  schemaLocation='../xsd/EchoTypes.xsd' />

It would actually point to the same (physical) location as seen from this XSD however if we deploy this configuration the ESB will throw an error because it won’t be able to match the resource with the defined import:

ERROR - ProxyService Error building service from WSDL
org.apache.axis2.AxisFault: WSDLException (at /wsdl:definitions/wsdl:types/xsd:schema/xs:schema): faultCode=PARSER_ERROR: Problem parsing 'file:../xsd/./EchoTypes.xsd'.: ../xsd/./EchoTypes.xsd (No such file or directory)
at org.apache.axis2.AxisFault.makeFault(
at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateService(
at org.apache.synapse.core.axis2.ProxyService.buildAxisService(
at org.apache.synapse.deployers.ProxyServiceDeployer.deploySynapseArtifact(
at org.wso2.carbon.proxyadmin.ProxyServiceDeployer.deploySynapseArtifact(
at org.apache.synapse.deployers.AbstractSynapseArtifactDeployer.deploy(
at org.wso2.carbon.application.deployer.synapse.SynapseAppDeployer.deployArtifacts(
at org.wso2.carbon.application.deployer.internal.ApplicationManager.deployCarbonApp(
at org.wso2.carbon.application.deployer.CappAxis2Deployer.deploy(
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(

If we now also change the resource declaration in the Proxy Service so it matches the import in the XSD it works again:

  <publishWSDL key='gov:wsdl/EchoWsdl.wsdl'>
     <resource location='../xsd/EchoElements.xsd' key='gov:/xsd/EchoElements.xsd'/>
     <resource location='../xsd/EchoTypes.xsd' key='gov:/xsd/EchoTypes.xsd'/>

About Pascal Alma

Pascal is a senior software developer and architect. Pascal has been designing and building applications since 2001. He is particularly interested in Open Source toolstack (Mule, Spring Framework, JBoss) and technologies like Web Services, SOA and Cloud technologies. Lately he is having great fun by building iOS apps with Swift. Specialties: JEE AWS XML/XSD/XSLT Web Services/SOA Mule ESB/ WSO2 ESB Maven Cloud Technology Swift/ iOS
This entry was posted in WSO2, WSO2 ESB, XML/ XSD/ XSLT and tagged , . Bookmark the permalink.