I’m using the Metro stack bundled with Java 6 SE to call a web service. The web service expects XML as a parameter. I use JAXB classes to create content and pass my JAXB root element to the web service endpoint.
Now to my Problem: I can’t find any way to make the marshaller include the schemaLocation of the XSD file since I can’t directly access the marshaller. (If you have direct access to the marshaller it is possible do set the schemalocation as a property, but when using metro, all the marshalling seems to be happening internally.)
I’ve tried setting the xsi:schemaLocation in the XmlSchema annotation in the generated package-info.java class, but this had no effect on the xml generated.
Another point is that when creating a web service client and calling a web service in an Java SE environment, certain annotations like @UsesJAXBContext, @WebServiceClient and @XmlSchema seem to be ignored. (I must state here that I am a beginner in terms of Java web services)
Ok, here’s what I now know. This has been a problem for me for months.
First, you have to change the JAXBContext used by JAX-WS. To do this use the @UsesJAXBContext annotation on the server. (com.sun.xml.ws.developer.UsesJAXBContext)
Then, in your factory implementation, you have to return custom Bridges in this method.
Then your custom bridge needs to set the marshaller property to set the namespace mapper you want to use.
Here’s my example.
and the factory class …
and the JAXB Context impelementation…
and now the Bridge implementation…
NOTE: I have just wrapped the existing implementation. All I wanted was to be able to fix the namespace names. From my reading of the source (JAXWS), this is the only way to get to the marshaller.
NOTE2 There is a downcast to an RI final class. This only works with the reference implementation. YMMV