简体   繁体   English

如何从XML Soap响应手动创建POJO类?

[英]How to create a POJO Class manually from XML Soap response?

I started learning and implementing SOAP Client with Spring Boot to consume some data from SOAP Service. 我开始学习并使用Spring Boot实现SOAP Client,以使用SOAP Service中的一些数据。

I can't generate POJO Classes from WSDL like this: 我不能从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>
...

After so many tabs on my Chrome 在我的Chrome上浏览了这么多标签
i created a class to make a request and it works 我创建了一个类来发出请求,它可以工作

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

}

It generates a request xml like this: 它生成如下的请求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>

and i got response like this: 我得到了这样的回应:

<?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>

My frustration continues, how to get the response data? 我的挫败感还在继续,如何获取响应数据?
I have tried to create one, just gave me null 我尝试创建一个,只是给了我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");
    }

}

How to create a class to handle the response? 如何创建一个类来处理响应?

Please use command prompt and try below to generate the request & response POJO classes using wsdl url: 请使用命令提示符,然后尝试以下使用wsdl网址生成请求和响应POJO类:

wsimport -keep -verbose <wsdl url>

For reference: Sample 供参考: 样品

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM