1

My camel cxf (2.15.2) route is working fine. Then requirement says we need to validate soap request against xsd. I try adding validator component:

from ("direct:xxx")  
  .to("validator:/path/to/CustomerRequest.xsd")

My CustomerRequest.xsd has imported other xsd(s).

<xsd:import schemaLocation="../vo/Address.xsd" namespace="http://vo.customer.com" />
<xsd:import schemaLocation="../vo/CustSourceEnum.xsd" namespace="http://vo.customer.com"></xsd:import>

but when I run start app, error happens. It complains about CustSourceEnum

 org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[validator:/path/to/xsd/CustomerRequest.xsd]. 
 Reason: org.xml.sax.SAXParseException; lineNumber: 27; columnNumber: 115; src-resolve: Cannot resolve the name 'vo:CustSourceEnum' to a(n) 'type definition' component.
    at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:407)
    ...
Caused by: org.xml.sax.SAXParseException; lineNumber: 27; columnNumber: 115; src-resolve: Cannot resolve the name 'vo:CustSourceEnum' to a(n) 'type definition' component.  

I double checked all the references in xsd are okay.

Now, the weird thing is if I change the order of import: Address first, and then CustSourceEnum:

<xsd:import schemaLocation="../vo/CustSourceEnum.xsd" namespace="http://vo.customer.com"></xsd:import>
<xsd:import schemaLocation="../vo/Address.xsd" namespace="http://vo.customer.com" />

Then an error still happens, BUT now it complains about 'vo:Address'. If I try to modify CustomerRequest.xsd just to import ONLY ONE schema, then it works. And of course, if I remove the camel validator component then everything works fine again.

David
  • 3,538
  • 9
  • 39
  • 50
  • I have just generated xml file from xsd (using a xml tool) then i got error when i validate that xml file against xsd. I have not change anything in xsd.When i debug the code inside com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema . I see that xerces only recognize the first import xsd. – David Aug 05 '15 at 15:07

1 Answers1

2

Your problem is that you are trying import the same namespace from multiple files, what isn't a good idea. Aplication imports only first file and skip others with the same namespace. There is good answer about this problem, and possible work around: https://stackoverflow.com/a/4998182/3703819

But better idea is to make one namespace per one xsd file.

Community
  • 1
  • 1
dey
  • 3,022
  • 1
  • 15
  • 25