JAXB-WS - 使用 @WebMethod 强制字段 [英] JAXB-WS - Making a field mandatory using @WebMethod
本文介绍了JAXB-WS - 使用 @WebMethod 强制字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个@WebMethod 调用
I have a @WebMethod call
@WebMethod
public int cancelCampaign(String campaignId, String reason);
我想将campaignId 字段标记为必填项.不知道该怎么做.
I'd like to make the campaignId field marked as mandatory. Not sure how to do that.
我使用的是 JBOSS 7.1 服务器.
I'm using a JBOSS 7.1 server.
推荐答案
我有类似的需求,从 SoapUI 我注意到我得到了
I had a similar requirement, and from SoapUI I noticed I was getting
<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 中的一个出路是用
A way out in JAX-WS Metro 2.0 RI is to annotate each parameter with
@XmlElement( required = true )
就我而言,我必须对所需的 WebMethod 参数和所有所需自定义类型的 getter 执行此操作,如下所示:
In my case, I had to do this to required WebMethod parameters and getters of all my required custom types, like so:
...
@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 */
}
这篇关于JAXB-WS - 使用 @WebMethod 强制字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文