使输入参数成为强制JAX-WS

时间:2015-02-23 08:03:45

标签: java web-services jax-ws

我的webservice方法的输入参数是AddSingleDocRequest类的Object。此类包含所有输入字段作为类实例变量及其getter和setter。我想强制一些输入字段。实现这一目标的最佳方法是什么?

以下是代码段:

**//webservice method

public String uploadDoc(AddSingleDocRequest request)
    {
    }

**//Request Class**

public class AddSingleDocRequest 
{

  private String sFilepath;

  private String sDataClass;

  public void setDataClassName(String dataClassName) 
{
        this.sDataClass= dataClassName;
    }


    public String getDataClassName() {
        return sDataClass;
    }

   public void setFilePath(String filePath)
    {
        this.sFilepath=filePath;
    }

    public String getFilePath()
    {
        return sFilepath;
    }
}

我想将sFilePath参数作为必需参数。

1 个答案:

答案 0 :(得分:0)

添加下一个JAX-B注释:

@XmlType(name = "AddSingleDocRequestType", propOrder = {
    "sFilepath", "sDataClass"
})
public class AddSingleDocRequest {

    @XmlElement(name = "sFilepath", required = true)
    private String sFilepath;

    @XmlElement(name = "sDataClass", required = false)
    private String sDataClass;

    public void setDataClassName(String dataClassName) {
        this.sDataClass = dataClassName;
    }

    public String getDataClassName() {
        return sDataClass;
    }

    public void setFilePath(String filePath) {
        this.sFilepath = filePath;
    }

    public String getFilePath() {
        return sFilepath;
    }
}

Using JAXB to customize mapping for JAX-WS web services中查看更多内容。