Как обрабатывать несколько запросов SOAP в одном конверте с помощью веб-службы Java?

Вопрос:

В настоящее время у меня есть веб-сервис с помощью метода:

@Override
@WebResult(Name="OIPResponse")
public  Map<String, Object> getOIP(@WebParam(name = "invoice") String invoiceNumber,@WebParam(name = "part") String partNumber)

Обычный SOAP-запрос, который я использую для вызова, выглядит следующим образом:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oip="http://oip.mycompany.com/">
<soapenv:Header/>
<soapenv:Body>
<oip:getOIP>
<invoice>41587182</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
</soapenv:Body>
</soapenv:Envelope>

и ответ выглядит примерно так:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getOIPResponse xmlns:ns2="http://oip.mycompany.com/">
<OIPResponse>
<entry>
<key>ERR_CODE</key>
</entry>
<entry>
<key>SELLING_OU</key>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">null</value>
</entry>
...
</OIPResponse>
</ns2:getOIPResponse>
</soap:Body>
</soap:Envelope>

Я тестировал это, и он отлично работает. Теперь мне интересно, есть ли способ включить несколько запросов в один и тот же SOAP-конверт следующим образом:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oip="http://oip.mycompany.com/">
<soapenv:Header/>
<soapenv:Body>
<oip:getOIP>
<invoice>41587182</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
<oip:getOIP>
<invoice>41587183</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
<oip:getOIP>
<invoice>41587184</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
<oip:getOIP>
<invoice>41587185</invoice>
<part>9ZF2A5-570</part>
</oip:getOIP>
</soapenv:Body>
</soapenv:Envelope>

и верните что-то вроде этого:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getOIPResponse xmlns:ns2="http://oip.mycompany.com/">
<OIPResponse>
...
</OIPResponse>
<OIPResponse>
...
</OIPResponse>
<OIPResponse>
...
</OIPResponse>
...
</ns2:getOIPResponse>
</soap:Body>
</soap:Envelope>

Есть какой-либо способ сделать это?

Ответ №1

Я закончил создание POJO под названием OIPRequest, в котором были два необходимых параметра (счет и номер детали) и новый метод getOIPMultiple, который принимает массив OIPRequests в качестве входного параметра.

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class OIPRequest {
public String invoiceNumber, partNumber;

public OIPRequest(String invoice, String part) {
invoiceNumber = invoice;
partNumber = part;
}

public OIPRequest() {
invoiceNumber = "";
partNumber = "";
}
}

Это делает запрос таким:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<getMultipleOIP xmlns="http://oip.mycompany.com/">
<OIPRequest xmlns="">
<invoiceNumber>41587182</invoiceNumber>
<partNumber>9ZF2A5-570</partNumber>
</OIPRequest>
<OIPRequest xmlns="">
<invoiceNumber>41587182</invoiceNumber>
<partNumber>9ZF2A5-570</partNumber>
</OIPRequest>
<OIPRequest xmlns="">
<invoiceNumber>41587182</invoiceNumber>
<partNumber>9ZF2A5-570</partNumber>
</OIPRequest>
</getMultipleOIP>
</Body>
</Envelope>

Оцените статью
TechArks.Ru
Добавить комментарий