簡體   English   中英

從xfire和agesi一起使用Jaxb遷移到CXF

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

我正在遷移我的xfire soap項目,該項目使用aegis將數據綁定到jaxb與cxf。 我得到了新的cxf項目,該項目適用於帶有宙斯盾綁定的舊xfire請求。 但是,當我將數據綁定移至jaxb時,就會發生解組錯誤。

這是我的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>

我在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;
            ....
     }

我測試的一種方法是在肥皂請求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>

但是,舊的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>

當我嘗試將xfire請求發送到cxf服務時,出現以下異常。

  javax.xml.bind.UnmarshalException: unexpected element (uri:"http://example.project.com", local:"keyValues"). Expected elements are <{}keyValues>

所以我認為我需要向cxf請求添加其他標簽,以便與xfire兼容。 有誰知道如何解決這個問題?

提前致謝。

默認情況下,JAXB使用不合格的元素,而Aegis / XFire默認情況下使用合格的元素。 有幾種解決方法:

1)為每個元素指定名稱空間。

@XmlElement(name =“ tag”,名稱空間=“ http:...”)

可能更容易:

2)添加一個package-info.java:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM