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.
public Bridge createBridge(final TypeReference typereference)
Then your custom bridge needs to set the marshaller property to set the namespace mapper you want to use.
Here's my example.
@WebService(serviceName = ...)
@UsesJAXBContext(MyContextFactory.class)
public class SoapServer { ... }
and the factory class ...
public static class MyContextFactory implements JAXBContextFactory
{
@Override
public JAXBRIContext createJAXBContext(final SEIModel sei,
@SuppressWarnings("rawtypes") final List<Class> classesToBind, final List<TypeReference> typeReferences)
throws JAXBException
{
JAXBRIContext context = JAXBContextFactory.DEFAULT.createJAXBContext(sei, classesToBind, typeReferences);
return new MyJaxwsContext(context);
}
}
and the JAXB Context impelementation...
public class MyContext extends JAXBRIContext
{
/** the actual context */
private final JAXBRIContext delegate;
public MyContext(final JAXBRIContext createContext)
{
this.delegate = createContext;
}
public Bridge createBridge(final TypeReference arg0)
{
return new MyBridge((JAXBContextImpl) delegate, delegate.createBridge(arg0));
}
and now the Bridge implementation...
public class MyBridge extends Bridge
{
private final Bridge delegate;
protected MyBridge(final JAXBContextImpl context, final Bridge delegate)
{
super(context);
this.delegate = delegate;
}
// an example marshal call. There are many more...
public void marshal(final Marshaller m, final Object object, final ContentHandler contentHandler)
throws JAXBException
{
m.setProperty("com.sun.xml.bind.namespacePrefixMapper", namespaceMapper);
delegate.marshal(m, object, contentHandler);
}
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