jboss - JAXB-WS - 使用 @WebMethod 强制设置字段

标签 jboss annotations jax-ws

我有一个@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 参数和 getter 执行此操作,如下所示:

在网络服务中:
...
 @WebMethod( operationName = "getItems" )
   @WebResult( name = "item" )
   public List<Item> getItems(
     @WebParam( name = "itemType" ) @XmlElement( required = true ) String itemType );
...

在我的 POJO 类(class)中:
@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 */

}

关于jboss - JAXB-WS - 使用 @WebMethod 强制设置字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12642335/

相关文章:

java.lang.NoClassDefFoundError : org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl weblogic 10. 3.6

java - JBoss EJB Bean 未绑定(bind)

java - 如何验证注解仅在某些类上使用?

java - RPC/Encoded Jboss 问题

java - 标记注释与标记界面

c# - ReSharper 代码注释异步任务<T>

java - 如何在 JAX-WS Web 服务上引发自定义错误?

Java : Is `@WebParam` optional?

java - 如何使用 JBoss 服务器在 MyEclipse 中调试 Web 项目?

java - 如何在 JBoss 6.4 中禁用 javax.validation.api