The CXF JAXB binding has a custom namespace mapper which can be told to control the prefixes. You can override it for further control. However, I'm very skeptical as to the idea modifying where the prefixes are defined. You might need to just make an interceptor that rewrites the XML.
On Thu, Mar 20, 2008 at 8:20 AM, Ian Roberts <[EMAIL PROTECTED]> wrote: > Yuval Zou wrote: > > Hi, > > > > Recently, I'm working on a web services client using CXF. But some > request > > messages can't be parsed by the web services server. I found the problem > is > > related to the namespace and prefix. > > The correct message: > > <?xml version="1.0" encoding="UTF-8"?> > > <CreateItemRequest xmlns=" > http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema"> > > [snip] > > </CreateItemRequest> > > The namespace http://www.ibm.com/xmlns/db2/cm/api/1.0/schema was put in > the > > element that needs it in this correct message. > > > > The mesage can't be parsed by server (sent by CXF): > > <?xml version="1.0" encoding="UTF-8"?> > > <CreateItemRequest xmlns:ns2=" > http://www.ibm.com/xmlns/db2/cm/api/1.0/schema" > > xmlns="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema"> > > [snip] > > </CreateItemRequest> > > > > The namespace http://www.ibm.com/xmlns/db2/cm/api/1.0/schema was put in > the > > root element. > > In XML terms the two messages are exactly the same, so it's more the > fault of whatever is parsing the message on the server side rather than > of the XML generator in CXF. Nontheless... > > If you're using JAXB databinding then you may be able to do what you > want using a custom namespace prefix mapper in the data binding. > Something like this (not tested but you get the idea): > > <jaxws:client ...> > <jaxws:dataBinding> > <bean class="org.apache.cxf.jaxb.JAXBDataBinding"> > <property name="marshallerProperties"> > <map> > <entry key="com.sun.xml.bind.namespacePrefixMapper"> > <bean class="my.package.NoPrefixNamespaceMapper" /> > </entry> > </map> > </property> > </bean> > </jaxws:dataBinding> > </jaxws:client> > > Where NoPrefixNamespaceMapper is an implementation of > com.sun.xml.bind.marshaller.NamespacePrefixMapper whose > getPreferredPrefix method always returns "". This should force the > marshaller to only use prefixes when it absolutely has to. > > Ian > > -- > Ian Roberts | Department of Computer Science > [EMAIL PROTECTED] | University of Sheffield, UK >
