CXF java2ws: how to include external xsd files?
Asked Answered
N

2

5

I generate WSDL files for several web services (from the server service definitions) where I have already XML schemas (*.XSD) for the beans used as parameters. How do I tell java2ws to reference these (include the external XSD) and not generate its own into the WSDL?

I have tried the -createxsdimports, but that does generate its own XSD files.

Is there a Java Annotation that I can use to let CXF know where the XSD for each file/package is?

Nitroparaffin answered 14/7, 2011 at 17:21 Comment(0)
J
4

Try the @XmlSchema annotation. It includes a location parameter that is used to tell JAXB that a real schema exists:

@XmlSchema(location="http://www.example.com/xsds/foo.xsd")
package com.example.foo;
Jolt answered 14/7, 2011 at 20:48 Comment(1)
Thanks Blaise, how do I define an xsd file in a local project directory. I tried file:/// but CXF (2.4.1) still gives me no schemaLocation="" on the <xsd:import ...>Nitroparaffin
S
3

I have a CXF Webservice that imports external schema files. When I built it; I spent quite a bit of time trying to sort out the exact scenario you're trying to achieve. Unfortunately, it appears that CXF does not respect the @XmlSchema(location="") annotation when generating WSDL from java. Daniel Kulp, the main CXF dev told me at the time this was a known issue but not enough people are complaining about it so it's not high on their list of priorities to fix.

So I ended up writing the WSDL by hand and then generating the SEI from the WSDL file. Of course, if you hand-write the WSDL you can do whatever you want.

Do bear in mind that one side-effect of this is that the external schema file needs to be accessible by an HTTP GET - both while generating the SEI AND when the webservice app starts up - CXF will retrieve the schema file on startup. Same goes for when you generate the client, of course. This does create a bit of a messy architectural dependency; but there appears to be no way to tell CXF "myschema.xsd" is available at http://myurl.com/myschema.xsd but ALSO in /src/main/schema/myschema.xsd.

Somnambulism answered 29/4, 2013 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.