如何避免CXF生成单独的类而不是使用现有的XMLRootElement类(JAXB类)

时间:2013-05-10 11:09:58

标签: jaxb jax-ws cxf

我是CXF和JAXB的新手。我正在尝试使用CXF上的eclipse从Java类(Bottom up Approach)生成WSDL。

创建了Interface作为研究员。

@WebService(name = "EBMData", targetNamespace = "http://business.kp.org/")
public interface EBMData {

    @WebMethod
    public @WebResult OPStatusDetails addEBMFields(InputFields fields);

    @WebMethod
    public @WebResult OPStatusDetails addOLIs(InputOLIs olis);


}

请求XML JAXB类如下

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="InputFields")
@XmlRootElement(name="InputFields")
public class InputFields {

    @XmlElement(name="FieldName", required=true)
    String fieldName;

    @XmlElement(name="Oli", required=true)
    List<String> olis;

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public List<String> getOlis() {
        return olis;
    }

    public void setOlis(List<String> olis) {
        this.olis = olis;
    }



}

响应XML JAXB类如下

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="OPStatusDetails")
@XmlRootElement
public class OPStatusDetails {

    @XmlElement(name="returnMessage", required=true)
    String returnMessage;

    public String getReturnCode() {
        return returnMessage;
    }

    public void setReturnCode(String returnMessage) {
        this.returnMessage = returnMessage;
    }



}

创建上述类后,使用new-&gt; Web服务并使用自下而上方法选项。并生成了WSDL。

生成WSDL后,可能会注意到已创建新包。文件AddEBMFields.java

@XmlRootElement(name = "addEBMFields", namespace = "http://business.kp.org/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addEBMFields", namespace = "http://business.kp.org/")

public class AddEBMFields {

    @XmlElement(name = "arg0")
    private org.kp.business.xmls.InputFields arg0;

    public org.kp.business.xmls.InputFields getArg0() {
        return this.arg0;
    }

    public void setArg0(org.kp.business.xmls.InputFields newArg0)  {
        this.arg0 = newArg0;
    }

}

和AddEBMFieldsResponse.java

@XmlRootElement(name = "addEBMFieldsResponse", namespace = "http://business.kp.org/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addEBMFieldsResponse", namespace = "http://business.kp.org/")

public class AddEBMFieldsResponse {

    @XmlElement(name = "return")
    private org.kp.business.xmls.OPStatusDetails _return;

    public org.kp.business.xmls.OPStatusDetails getReturn() {
        return this._return;
    }

    public void setReturn(org.kp.business.xmls.OPStatusDetails new_return)  {
        this._return = new_return;
    }

}

由于这些文件,我的Request XML生成如下,而不是arg0字段,需要从InputFields.java引用它。你能帮忙吗?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bus="http://business.kp.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <bus:addEBMFields>
         <!--Optional:-->
         <arg0>
            <FieldName>?</FieldName>
            <!--1 or more repetitions:-->
            <Oli>?</Oli>
            <Oli>?</Oli>
            <Oli>?</Oli>
         </arg0>
      </bus:addEBMFields>
   </soapenv:Body>
</soapenv:Envelope>

我也想要

o know how my JAXB class should for the following soap request xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bus="http://business.kp.org/">
       <soapenv:Header/>
       <soapenv:Body>
          <bus:addEBMFields>
             <!--Optional:-->
            <FieldName>?</FieldName>
            <!--1 or more repetitions:-->
            <Oli>?</Oli>
            <Oli>?</Oli>
            <Oli>?</Oli>
          </bus:addEBMFields>
       </soapenv:Body>
    </soapenv:Envelope>

1 个答案:

答案 0 :(得分:1)

添加:

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

到EBMData接口。默认情况下,它将为操作创建包装器。指定BARE模式将直接使用这些类型。