7

@WebMethod 呼び出しがあります

@WebMethod
public int cancelCampaign(String campaignId, String reason);

CampaignId フィールドを必須としてマークしたいと思います。それを行う方法がわからない。

JBOSS 7.1 サーバーを使用しています。

4

2 に答える 2

7

同様の要件があり、SoapUI から取得していることに気付きました

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:bus="http://business.test.com/">
  <soapenv:Header/>
  <soapenv:Body>
     <!-- optional -->
     <bus:addItem>
        <bus:item>
           <id>?</id>
           <!-- optional -->
           <name>?</name>
        </bus:item>
        <!-- optional -->
        <itemType>?</itemType>
     </bus:addItem>
  </soapenv:Body>
</soapenv:Envelope>

それ以外の

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:bus="http://business.test.com/">
  <soapenv:Header/>
  <soapenv:Body>
     <bus:addItem>
        <bus:item>
           <id>?</id>
           <name>?</name>
        </bus:item>
        <itemType>?</itemType>
     </bus:addItem>
  </soapenv:Body>
</soapenv:Envelope>

JAX-WS Metro 2.0 RI での解決策は、各パラメーターに注釈を付けることです。

@XmlElement( required = true )

私の場合、次のように、必要な WebMethod パラメータとすべての必要なカスタム タイプのゲッターに対してこれを行う必要がありました。

Web サービスで:

...
 @WebMethod( operationName = "getItems" )
   @WebResult( name = "item" )
   public List<Item> getItems(
     @WebParam( name = "itemType" ) @XmlElement( required = true ) String itemType );
...

そして私のPOJOクラスでは:

@XmlAccessorType(XmlAccessType.FIELD)
public class Item implements Serializable
{
   private static final long serialVersionUID = 1L;

   @XmlElement( required = true )
   private int               id;

   @XmlElement( required = true )
   private String            name;

   /**
    * Default constructor.
    */
   public Item() { }

   /**
    * @return the id
    *
    */       
   public int getId()
   {
      return id;
   }

   /* setter for id */

   /**
    * @return the name
    */
   public String getName()
   {
      return name;
   }

   /* setter for name */

}
于 2014-08-13T03:07:21.020 に答える
4

これを行う唯一の方法は、注釈のフラグJAX-WSを指定するいくつかのラッパー クラスを記述することです。request 要素は次のようになります。required=trueXmlElement

@XmlType(name="YourRequestType", propOrder={"campaignId", "reason"})
public class YourRequest {
    @XmlElement(name="campaignId", required=true)
    private String campaignId;
    @XmlElement(name="reason", required=false)
    private String reason;

    //Getters and setters        

}

Web メソッドは次のようになります。

@WebMethod
public int cancelCampaign(@WebParam(name = "request") YourRequest request) {
   String campaignId = request.getCampaignId();

   return 0;
}

これにより、 for 要素で生成するように指示されますJAXBminOccurs=1XSDcampaignId

于 2012-09-28T15:17:02.793 に答える