仅使用XSD的JAX WS WebService实现

时间:2016-01-14 13:36:10

标签: java web-services soap xsd jax-ws

我有一个现有的SOAP客户端,它根据该XSD描述发送SOAP消息。我的WebService接受呼叫,但我的项目列表为空。

如果我将WebMethod声明更改为

 @WebMethod
public Integer transferPalletRecords2(@WebParam(name = "arg0") List<Item> items) 

然后我收到1个包含所有NULL字段的项目。

DEBUG got [{RESERVED3=null, RESERVED2=null, RESERVED1=null, WAREHOUSENUM=null, LINENUM=null, QUANTITY=null, SHELFLIFE=null, RESERVED5=null, RESERVED4=null, INDICATOR=null, NAME=null, HUIDENT=null, UOM=null, DLV_NO=null, COUNTRYOFORIGIN=null, CITY=null, BATCH=null, MATNR=null, EAN13=null}] items!

有什么建议吗?

XSD file content screenshot

SOAP Envelop screenshot

我的WebService实现:

@WebService(targetNamespace = "http://xml....")
public class TransferPalletRecords {

    public static final String XML_DELIVERY_NUM = "DLV_NO";
    public static final String XML_WAREHOUSE_NUM = "WAREHOUSENUM";
    public static final String XML_LINE_NUM = "LINENUM";
    public static final String XML_HU_IDENTNUMBER = "HUIDENT";
    public static final String XML_PRODUCT_NUMBER = "MATNR";
    public static final String XML_PRODUCT_EAN = "EAN13";
    public static final String XML_PRODUCT_NAME = "NAME";
    public static final String XML_QUANTITY = "QUANTITY";
    public static final String XML_UOM = "UOM";
    public static final String XML_BATCH = "BATCH";
    public static final String XML_INDICATOR = "INDICATOR";
    public static final String XML_SHELF_LIFE = "SHELFLIFE";
    public static final String XML_COUNTRY_OF_ORIGIN = "COUNTRYOFORIGIN";
    public static final String XML_CITY = "CITY";
    public static final String XML_RESERVED1 = "Reserved1";
    public static final String XML_RESERVED2 = "Reserved2";
    public static final String XML_RESERVED3 = "Reserved3";
    public static final String XML_RESERVED4 = "Reserved4";
    public static final String XML_RESERVED5 = "Reserved5";

    @Resource
    WebServiceContext wsContext;

    @WebMethod
    public Integer transferPalletRecords2(@WebParam(name = "arg0") Item[] items) {
        try {
            System.err.println("DEBUG got " + items.length + " items!");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @XmlRootElement(name = "item")
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Item {

        @XmlElement(name = XML_DELIVERY_NUM, required = true)
        private String deliveryNum;

        @XmlElement(name = XML_WAREHOUSE_NUM, required = true)
        private String wareHouseNum;

        @XmlElement(name = XML_LINE_NUM, required = true)
        private String lineNum;

        @XmlElement(name = XML_HU_IDENTNUMBER, required = true)
        private String huIdent;

        @XmlElement(name = XML_PRODUCT_NUMBER, required = true)
        private String productNumber;

        @XmlElement(name = XML_PRODUCT_EAN, required = true)
        private String productEAN;

        @XmlElement(name = XML_PRODUCT_NAME, required = true)
        private String productName;

        @XmlElement(name = XML_QUANTITY, required = true)
        private Integer quantity;

        @XmlElement(name = XML_UOM, required = true)
        private String uom;

        @XmlElement(name = XML_BATCH, required = true)
        private String batch;

        @XmlElement(name = XML_INDICATOR, required = true)
        private String indicator;

        @XmlElement(name = XML_SHELF_LIFE, required = true)
        private Integer shelflife;

        @XmlElement(name = XML_COUNTRY_OF_ORIGIN, required = true)
        private String countryOfOrigin;

        @XmlElement(name = XML_CITY, required = true)
        private String city;

        @XmlElement(name = XML_RESERVED1, required = false)
        private String reserved1;

        @XmlElement(name = XML_RESERVED2, required = false)
        private String reserved2;

        @XmlElement(name = XML_RESERVED3, required = false)
        private String reserved3;

        @XmlElement(name = XML_RESERVED4, required = false)
        private String reserved4;

        @XmlElement(name = XML_RESERVED5, required = false)
        private String reserved5;

        public String getDeliveryNum() {
            return deliveryNum;
        }

        public String getWareHouseNum() {
            return wareHouseNum;
        }

        public String getLineNum() {
            return lineNum;
        }

        public String getHUIdent() {
            return huIdent;
        }

        public String getProductNumber() {
            return productNumber;
        }

        public String getProductEAN() {
            return productEAN;
        }

        public String getProductName() {
            return productName;
        }

        public Integer getQuantity() {
            return quantity;
        }

        public String getUOM() {
            return uom;
        }

        public String getBatch() {
            return batch;
        }

        public String getIndicator() {
            return indicator;
        }

        public Integer getShelflife() {
            return shelflife;
        }

        public String getCountryOfOrigin() {
            return countryOfOrigin;
        }

        public String getCity() {
            return city;
        }

        public String getReserved1() {
            return reserved1;
        }

        public String getReserved2() {
            return reserved2;
        }

        public String getReserved3() {
            return reserved3;
        }

        public String getReserved4() {
            return reserved4;
        }

        public String getReserved5() {
            return reserved5;
        }

    }

}

2 个答案:

答案 0 :(得分:1)

问题解决了。我已经使用SOAPUI为我的WSDL生成SOAP请求。解决方案是:

    @WebMethod
public Integer transferPalletRecords2(PalletRecord2Array palRec) {
    try {
        System.out("Got " + palRec.getItems().size() + " items!");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

// PalletRecord XML Struktur
@XmlRootElement(name = "arg0")
@XmlAccessorType(XmlAccessType.FIELD)
public static class PalletRecord2Array {

    @XmlElement(name = "item", required = true)
    protected List<Item> items;

    public List<Item> getItems() {
        if (items == null) {
            items = new ArrayList<>();
        }
        return items;
    }

}

public static class Item {
...
}

答案 1 :(得分:0)

您还可以列出客户端代码吗? 大多数情况下,当您收到空列表时,由于根元素名称和命名空间不匹配,因此请确保它们相同。

找到问题并更正问题的最简单方法是生成Web服务的WSDL并从SOAP请求程序(如SoapUI)获取模板请求,并且一旦成功,尝试在客户端上复制相同的SOAP信封内容侧