spring boot SOAP 生产者 - 输入对象列表始终为空
springboot SOAP producer - list of objects on input always empty
我在尝试使用对象列表作为输入在 Springboot 中生成 SOAP Web 服务时遇到问题。
当我调用服务时,标量值正在解组,但列表仅包含空数组。
我不知道我错过了什么....
我无法更改 WSDL 定义。
有点难理解,所以我在Github上重现了这个问题。
这是我的端点定义。一旦代码到达 doc.getDocFormat().getValue()
部分,试图从列表中读取,它就会抛出 Cannot invoke "javax.xml.bind.JAXBElement.getValue(), basically a NullPointerException.
@Endpoint
public class MergeTiffEndpoint {
private static final String NAMESPACE_URI = "urn:Gekon";
Logger logger = LoggerFactory.getLogger(MergeTiffEndpoint.class);
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "MERGE_TIFFRequestElement")
@ResponsePayload
public MERGETIFFReturn merge(@RequestPayload MERGETIFFQuery request) {
List<InputSetRow> list = request.getDocuments().getValue().getDocument();
logger.info("List size is " + list.size());
list.forEach((doc) ->
System.out.println("Value is " + doc.getDocFormat().getValue())
);
return null;
}
}
这是来自客户的电话:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:MERGE_TIFFRequestElement xmlns:ns1="urn:Gekon">
<ns1:documents xsi:type="ns1:InputSet">
<ns1:document xsi:type="ns1:InputSetRow">
<doc_format xsi:type="xsd:string">TIFF</doc_format>
<location xsi:type="xsd:string">c:\Users\zizam\private\gekonTests\file-convertor\files\input\merge_tiff_single.tif</location>
<options xsi:nil="true"/>
</ns1:document>
<ns1:document xsi:type="ns1:InputSetRow">
<doc_format xsi:type="xsd:string">TIFF</doc_format>
<location xsi:type="xsd:string">c:\Users\zizam\private\gekonTests\file-convertor\files\input\merge_tiff_multi.tif</location>
<options xsi:nil="true"/>
</ns1:document>
</ns1:documents>
<ns1:storage_type xsi:type="xsd:string">URL</ns1:storage_type>
<ns1:appl_id xsi:type="xsd:string">MQT_TEST</ns1:appl_id>
</ns1:MERGE_TIFFRequestElement>
</soapenv:Body>
</soapenv:Envelope>
我使用jaxb2-maven-plugin
并从 wsdl 文件生成了 pojo 存根。
生成了以下相关 类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MERGE_TIFFQuery", propOrder = {
"documents",
"storageType",
"applId"
})
public class MERGETIFFQuery {
@XmlElementRef(name = "documents", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<InputSet> documents;
@XmlElementRef(name = "storage_type", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> storageType;
@XmlElementRef(name = "appl_id", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> applId;
-- standard getters and setters
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "InputSet", propOrder = {
"document"
})
public class InputSet {
@XmlElement(nillable = true, namespace = "urn:Gekon")
protected List<InputSetRow> document;
public List<InputSetRow> getDocument() {
if (document == null) {
document = new ArrayList<InputSetRow>();
}
return this.document;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "InputSetRow", propOrder = {
"docFormat",
"location",
"options",
"content"
})
@XmlRootElement
public class InputSetRow {
@XmlElementRef(name = "doc_format", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> docFormat;
@XmlElementRef(name = "location", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> location;
@XmlElementRef(name = "options", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> options;
@XmlElementRef(name = "content", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<Base64Binary> content;
-- standard getters and setters
我真的不知道我错过了什么。
任何帮助表示赞赏。
好的,明白了。
客户端发出的调用没有命名空间引用。
<ns1:document xsi:type="ns1:InputSetRow">
<ns1:doc_format xsi:type="xsd:string">TIFF</doc_format>
<location xsi:type="xsd:string">c:\Users\zizam\private\gekonTests\file-convertor\files\input\merge_tiff_single.tif</location>
<options xsi:nil="true"/>
</ns1:document>
当我以 ns1:doc_format
格式拨打电话时,一切正常。
所以让它工作的唯一方法是将 InutSetRow 中的命名空间引用更改为 InputSetRow 到 namespace = ""
我在尝试使用对象列表作为输入在 Springboot 中生成 SOAP Web 服务时遇到问题。
当我调用服务时,标量值正在解组,但列表仅包含空数组。
我不知道我错过了什么.... 我无法更改 WSDL 定义。
有点难理解,所以我在Github上重现了这个问题。
这是我的端点定义。一旦代码到达 doc.getDocFormat().getValue()
部分,试图从列表中读取,它就会抛出 Cannot invoke "javax.xml.bind.JAXBElement.getValue(), basically a NullPointerException.
@Endpoint
public class MergeTiffEndpoint {
private static final String NAMESPACE_URI = "urn:Gekon";
Logger logger = LoggerFactory.getLogger(MergeTiffEndpoint.class);
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "MERGE_TIFFRequestElement")
@ResponsePayload
public MERGETIFFReturn merge(@RequestPayload MERGETIFFQuery request) {
List<InputSetRow> list = request.getDocuments().getValue().getDocument();
logger.info("List size is " + list.size());
list.forEach((doc) ->
System.out.println("Value is " + doc.getDocFormat().getValue())
);
return null;
}
}
这是来自客户的电话:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:MERGE_TIFFRequestElement xmlns:ns1="urn:Gekon">
<ns1:documents xsi:type="ns1:InputSet">
<ns1:document xsi:type="ns1:InputSetRow">
<doc_format xsi:type="xsd:string">TIFF</doc_format>
<location xsi:type="xsd:string">c:\Users\zizam\private\gekonTests\file-convertor\files\input\merge_tiff_single.tif</location>
<options xsi:nil="true"/>
</ns1:document>
<ns1:document xsi:type="ns1:InputSetRow">
<doc_format xsi:type="xsd:string">TIFF</doc_format>
<location xsi:type="xsd:string">c:\Users\zizam\private\gekonTests\file-convertor\files\input\merge_tiff_multi.tif</location>
<options xsi:nil="true"/>
</ns1:document>
</ns1:documents>
<ns1:storage_type xsi:type="xsd:string">URL</ns1:storage_type>
<ns1:appl_id xsi:type="xsd:string">MQT_TEST</ns1:appl_id>
</ns1:MERGE_TIFFRequestElement>
</soapenv:Body>
</soapenv:Envelope>
我使用jaxb2-maven-plugin
并从 wsdl 文件生成了 pojo 存根。
生成了以下相关 类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MERGE_TIFFQuery", propOrder = {
"documents",
"storageType",
"applId"
})
public class MERGETIFFQuery {
@XmlElementRef(name = "documents", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<InputSet> documents;
@XmlElementRef(name = "storage_type", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> storageType;
@XmlElementRef(name = "appl_id", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> applId;
-- standard getters and setters
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "InputSet", propOrder = {
"document"
})
public class InputSet {
@XmlElement(nillable = true, namespace = "urn:Gekon")
protected List<InputSetRow> document;
public List<InputSetRow> getDocument() {
if (document == null) {
document = new ArrayList<InputSetRow>();
}
return this.document;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "InputSetRow", propOrder = {
"docFormat",
"location",
"options",
"content"
})
@XmlRootElement
public class InputSetRow {
@XmlElementRef(name = "doc_format", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> docFormat;
@XmlElementRef(name = "location", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> location;
@XmlElementRef(name = "options", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<String> options;
@XmlElementRef(name = "content", namespace = "urn:Gekon", type = JAXBElement.class, required = false)
protected JAXBElement<Base64Binary> content;
-- standard getters and setters
我真的不知道我错过了什么。
任何帮助表示赞赏。
好的,明白了。
客户端发出的调用没有命名空间引用。
<ns1:document xsi:type="ns1:InputSetRow">
<ns1:doc_format xsi:type="xsd:string">TIFF</doc_format>
<location xsi:type="xsd:string">c:\Users\zizam\private\gekonTests\file-convertor\files\input\merge_tiff_single.tif</location>
<options xsi:nil="true"/>
</ns1:document>
当我以 ns1:doc_format
格式拨打电话时,一切正常。
所以让它工作的唯一方法是将 InutSetRow 中的命名空间引用更改为 InputSetRow 到 namespace = ""