Gau*_*rma 7 jboss annotations jax-ws
我有@WebMethod电话
@WebMethod
public int cancelCampaign(String campaignId, String reason);
Run Code Online (Sandbox Code Playgroud)
我想将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>
Run Code Online (Sandbox Code Playgroud)
代替
<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>
Run Code Online (Sandbox Code Playgroud)
在JAX-WS Metro 2.0 RI中的一个出路是用每个参数注释
@XmlElement( required = true )
Run Code Online (Sandbox Code Playgroud)
在我的情况下,我必须这样做需要WebMethod参数和所有我需要的自定义类型的getter,如下所示:
...
@WebMethod( operationName = "getItems" )
@WebResult( name = "item" )
public List<Item> getItems(
@WebParam( name = "itemType" ) @XmlElement( required = true ) String itemType );
...
Run Code Online (Sandbox Code Playgroud)
@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 */
}
Run Code Online (Sandbox Code Playgroud)
执行此操作的唯一方法JAX-WS是编写一些包装类来指定注释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
}
Run Code Online (Sandbox Code Playgroud)
你的网络方法应该如下所示:
@WebMethod
public int cancelCampaign(@WebParam(name = "request") YourRequest request) {
String campaignId = request.getCampaignId();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这将告诉您在for元素中JAXB生成。minOccurs=1XSDcampaignId
| 归档时间: |
|
| 查看次数: |
13209 次 |
| 最近记录: |