I'm migrating my xfire soap project which uses aegis for databinding to cxf with jaxb. I got the new cxf project working for old xfire requests with aegis binding. But when i move the databinding to jaxb unmarshalling errror occurs.
This is my cxf web service definition.
<!--<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope="prototype"/> -->
<bean id="jaxbBean" class="org.apache.cxf.jaxb.JAXBDataBinding" scope="prototype"/>
<bean id="jaxws-and-aegis-service-factory" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
scope="prototype">
<property name="dataBinding" ref="jaxbBean"/>
<property name="serviceConfigurations">
<list>
<bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration"/>
<bean class="org.apache.cxf.aegis.databinding.XFireCompatibilityServiceConfiguration"/>
<bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/>
</list>
</property>
</bean>
<jaxws:endpoint id="trace" address="/trace" implementor="#traceImplBean">
<jaxws:serviceFactory>
<ref bean="jaxws-and-aegis-service-factory"/>
</jaxws:serviceFactory>
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
</jaxws:outInterceptors>
</jaxws:endpoint>
I used @XMLRootElement Annotaion on my DTOs as following.
@XmlRootElement(name = "context" )
public class Context implements Serializable {
private KeyValues keyValues;
.....
}
@XmlRootElement(name = "keyValues" )
public class KeyValues implements Serializable {
private String tag;
private String value;
....
}
One method which i tested generated following soap request for cxf
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pay="http://example.project.com">
<soapenv:Header/>
<soapenv:Body>
<pay:trace>
<pay:context>
<keyValues>
<tag>tag</tag>
<value>value</value>
</keyValues>
</pay:context>
</pay:trace>
</soapenv:Body>
</soapenv:Envelope>
HOWEVER old xfire generate following request, I have mark the difference.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pay="http://example.project.com" xmlns:api="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<pay:trace>
<pay:context>
<api:keyValues>
***<api:KeyValues>***
<api:tag>tag</api:tag>
<api:value>value</api:value>
***</api:KeyValues>***
</api:keyValues>
</pay:context>
</pay:trace>
</soapenv:Body>
</soapenv:Envelope>
I got following exception when i tried to send xfire request to cxf service.
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://example.project.com", local:"keyValues"). Expected elements are <{}keyValues>
So I think i need to add additional tags to cxf request inorder to compatible with xfire. Does anyone knows how to resolve this ?
Thanks in advance.
JAXB, by default, uses unqualified elements whereas Aegis/XFire by default used qualified elements. Couple ways around that:
1) For every element, specify the namespace.
@XmlElement(name = "tag", namespace = "http:...")
likely easier:
2) Add a package-info.java with:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://......", elementFormDefault = XmlNsForm.QUALIFIED)