Hi Ian,
I have tried your solution but it seems not work as expected. I'm a beginner
of CXF and I'm not sure my implementation is correct. Could you please take
a look at it?
1. I created cxf.xml on the client side:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:client id="cmwebserviceClient"
serviceClass="cm.webservices.CMWebServicePortType"
address="http://localhost/CMBSpecificWebService/services/CMWebService">
<jaxws:dataBinding>
<bean class="org.apache.cxf.jaxb.JAXBDataBinding">
<property name="marshallerProperties">
<map>
<entry key="com.sun.xml.bind.namespacePrefixMapper">
<bean class="common.webservices.NoNamespacePrefixMapper" />
</entry>
</map>
</property>
<property name="namespaceMap">
<map>
<entry
key="http://www.ibm.com/xmlns/db2/cm/api/1.0/schema">
<value>cm</value>
</entry>
<entry
key="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema">
<value>cmb</value>
</entry>
</map>
</property>
</bean>
</jaxws:dataBinding>
</jaxws:client>
</beans>
<property name="namespaceMap"> is insignificant. If it is removed, the
result is same.
2. Implemented the NoNamespacePrefixMapper:
public class NoNamespacePrefixMapper extends
com.sun.xml.bind.marshaller.NamespacePrefixMapper {
@Override
public String getPreferredPrefix(String arg0, String arg1, boolean
arg2) {
return "";
}
}
3. Get service:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[]{"cxf.xml"});
return (CMWebServicePortType)context.getBean("cmwebserviceClient");
4. Invoke the service operation. The xml message is still as before.
Is there anything wrong in these steps? Thanks!
ianroberts 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
>
>
--
View this message in context:
http://www.nabble.com/How-to-change-the-namespace-position-in-the-generate-xml-message-%28SOAP-message%29--tp16176819p16194418.html
Sent from the cxf-user mailing list archive at Nabble.com.