简体   繁体   English

从xfire和agesi一起使用Jaxb迁移到CXF

[英]Migrating to CXF with Jaxb from xfire with agesi

I'm migrating my xfire soap project which uses aegis for databinding to cxf with jaxb. 我正在迁移我的xfire soap项目,该项目使用aegis将数据绑定到jaxb与cxf。 I got the new cxf project working for old xfire requests with aegis binding. 我得到了新的cxf项目,该项目适用于带有宙斯盾绑定的旧xfire请求。 But when i move the databinding to jaxb unmarshalling errror occurs. 但是,当我将数据绑定移至jaxb时,就会发生解组错误。

This is my cxf web service definition. 这是我的cxf Web服务定义。

   <!--<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. 我在DTO上使用了@XMLRootElement Annotaion,如下所示。

     @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 我测试的一种方法是在肥皂请求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. 但是,旧的xfire会产生以下请求,我已经记下了区别。

      <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. 当我尝试将xfire请求发送到cxf服务时,出现以下异常。

  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. 所以我认为我需要向cxf请求添加其他标签,以便与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. 默认情况下,JAXB使用不合格的元素,而Aegis / XFire默认情况下使用合格的元素。 Couple ways around that: 有几种解决方法:

1) For every element, specify the namespace. 1)为每个元素指定名称空间。

@XmlElement(name = "tag", namespace = "http:...") @XmlElement(name =“ tag”,名称空间=“ http:...”)

likely easier: 可能更容易:

2) Add a package-info.java with: 2)添加一个package-info.java:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://......", elementFormDefault = XmlNsForm.QUALIFIED) @ javax.xml.bind.annotation.XmlSchema(namespace =“ http:// ......”,elementFormDefault = XmlNsForm.QUALIFIED)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM