Gennadij Degterjow
Gennadij Degterjow

Reputation: 98

JAX WS WebService implementation with XSD only

I have an existing SOAP client, that send the SOAP message according to that XSD description. My WebService accept the call, but my Item list is empty.

if I change the WebMethod declaration as

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

Then I receive 1 item with all NULL fields.

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!

Any suggestion what is wrong?

XSD file content screenshot

SOAP Envelop screenshot

My WebService implementation:

@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;
        }

    }

}

Upvotes: 0

Views: 327

Answers (2)

Gennadij Degterjow
Gennadij Degterjow

Reputation: 98

The problem is solved. I've used SOAPUI to generate SOAP request for my WSDL. The solution were:

    @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 {
...
}

Upvotes: 2

AuthenticReplica
AuthenticReplica

Reputation: 870

Could you also list the client code? Most of the time when you receive an empty list it's because of a mismatch in the root element name and namespace so make sure they're the same.

Easiest way to find the issue and correct it is to generate a WSDL of your web service and get a template request from a SOAP request program such as SoapUI and once successful from there try to replicate the same SOAP envelope contents on the client side

Upvotes: 0

Related Questions