Как создать класс POJO вручную из ответа XML Soap? - PullRequest
1 голос
/ 16 мая 2019

Я начал изучать и внедрять клиент SOAP с Spring Boot для использования некоторых данных из службы SOAP.

Я не могу генерировать классы POJO из WSDL следующим образом:

<?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");
    }

}

Как создатькласс для обработки ответа?

1 Ответ

0 голосов
/ 22 мая 2019

Пожалуйста, используйте командную строку и попробуйте ниже, чтобы сгенерировать классы POJO запроса и ответа, используя wsdl url:

wsimport -keep -verbose <wsdl url>

Для справки: Пример

...