gpt4 book ai didi

java - 仅使用 XSD 的 JAX WS WebService 实现

转载 作者:行者123 更新时间:2023-12-02 04:01:58 26 4
gpt4 key购买 nike

我有一个现有的 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;
}

}

}

最佳答案

问题已经解决了。我已经使用 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 {
...
}

关于java - 仅使用 XSD 的 JAX WS WebService 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34791042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com