使用jax-ws注释来确定请求/响应包装器元素

时间:2013-07-06 15:41:12

标签: annotations jax-ws bottom-up

我正在尝试使用自下而上的方法创建一个Web服务,首先创建java类。我的实现如下所示:

@WebMethod(operationName = "addNumbers")
public String addNumbers(
        @WebParam(name = "addNumberRequest") @XmlElement(required = true, nillable = false) final AddNumberRequest addNumberRequest) {
    return "Hello World";
}

AddNumberRequest类如下:

@Repository
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "number1", "number2", "number3" })
public class AddNumberRequest {

    private int number1;
    private int number2;
    private int number3;

    public int getNumber1() {
        return number1;
    }

    public void setNumber1(int number1) {
        this.number1 = number1;
    }

    public int getNumber2() {
        return number2;
    }

    public void setNumber2(int number2) {
        this.number2 = number2;
    }

    public int getNumber3() {
        return number3;
    }

    public void setNumber3(int number3) {
        this.number3 = number3;
    }
}

Web服务已发布,但是当我从soapui生成示例请求时,请求如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.service.test.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:addNumbers>
         <addNumberRequest>
            <number1>?</number1>
            <number2>?</number2>
            <number3>?</number3>
         </addNumberRequest>
      </ws:addNumbers>
   </soapenv:Body>
</soapenv:Envelope>

有没有办法简单地使用注释来创建方法的java实现,以便示例请求看起来像这样:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.service.test.com/">
   <soapenv:Header/>
   <soapenv:Body>

         <addNumberRequest>
            <number1>?</number1>
            <number2>?</number2>
            <number3>?</number3>
         </addNumberRequest>

   </soapenv:Body>
</soapenv:Envelope>

我希望能够确定包装元素的名称,例如addNumberRequest,而不必使用ws:addNumbers(默认情况下由operationName生成)元素。

1 个答案:

答案 0 :(得分:1)

尝试使用

addNumbers接口上的@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)