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 2.0新城RI出来的一种方法是用注释
A way out in JAX-WS Metro 2.0 RI is to annotate each parameter with
@XmlElement( required = true )
在我而言,我不得不这样做所需的WebMethod参数和我所有的需要自定义类型的干将,像这样:
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屋!
查看全文