@WebMethod 呼び出しがあります
@WebMethod
public int cancelCampaign(String campaignId, String reason);
CampaignId フィールドを必須としてマークしたいと思います。それを行う方法がわからない。
JBOSS 7.1 サーバーを使用しています。
@WebMethod 呼び出しがあります
@WebMethod
public int cancelCampaign(String campaignId, String reason);
CampaignId フィールドを必須としてマークしたいと思います。それを行う方法がわからない。
JBOSS 7.1 サーバーを使用しています。
同様の要件があり、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 パラメータとすべての必要なカスタム タイプのゲッターに対してこれを行う必要がありました。
...
@WebMethod( operationName = "getItems" )
@WebResult( name = "item" )
public List<Item> getItems(
@WebParam( name = "itemType" ) @XmlElement( required = true ) String itemType );
...
@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 */
}
これを行う唯一の方法は、注釈のフラグJAX-WS
を指定するいくつかのラッパー クラスを記述することです。request 要素は次のようになります。required=true
XmlElement
@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 要素で生成するように指示されますJAXB
。minOccurs=1
XSD
campaignId