我开始使用 Spring Boot 学习和实现 SOAP 客户端,以使用来自 SOAP 服务的一些数据。
我无法像这样从 WSDL 生成 POJO 类:
<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:Bakoelbuzz" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:Bakoelbuzz">
<types>
<xsd:schema targetNamespace="urn:Bakoelbuzz">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
</xsd:schema>
</types>
<message name="mitraInfoRequest"></message>
<message name="mitraInfoResponse">
<part name="return" type="xsd:Array" />
</message>
...
在我的 Chrome 上打开了这么多标签之后
我创建了一个类来发出请求并且它有效
package bbl.wsdl;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"quota"
})
@XmlRootElement(name = "ppMitraInfo")
public class PpMitraInfo {
@XmlElement(name = "quota", required = true)
protected String quota;
public String getQuota() { return quota; }
public void setQuota(String quota) { this.quota = quota; }
}
它生成一个像这样的请求 xml:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<ns3:ppMitraInfo xmlns:ns3="http://xxxxxx" xmlns:sn3="urn:Bakoelbuzz" />
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我得到了这样的回复:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:ppMitraInfoResponse xmlns:ns1="http://xxxxxx">
<return>
<quota xsi:type="xsd:string">7738143573</quota>
<Description xsi:type="xsd:string">DEVELMODE BY WHO</Description>
</return>
</ns1:ppMitraInfoResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我的挫败感依然存在,如何获取响应数据?
我尝试创建一个,只是给了我 null
package bbl.wsdl;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = {
"quota", "Description"
})
@XmlRootElement(name = "ppMitraInfoResponse")
public class PpMitraInfoResponse {
@XmlElement(required = true)
protected String quota;
@XmlElement(required = true)
protected String Description;
public String getQuota() { return quota; }
public void setQuota(String quota) { this.quota = quota; }
public String getDescription() { return Description; }
public void setDescription(String Description) { this.Description = Description; }
void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) {
System.out.println("Before Unmarshaller Callback -> ");
}
void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
System.out.println("After Unmarshaller Callback");
}
}
如何创建一个类来处理响应?
最佳答案
关于java - 如何从 XML Soap 响应手动创建 POJO 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56164989/