Столкновение с проблемой при создании мыльного веб-клиента с использованием веб-сервисов SpringJAVA

Программисты JAVA общаются здесь
Anonymous
Столкновение с проблемой при создании мыльного веб-клиента с использованием веб-сервисов Spring

Сообщение Anonymous »

Итак, это один мыльный API, который я хочу вызвать:
[![введите описание изображения здесь][1]][1]
Однако это ответ, который я получаю от API, но все же я хочу написать общий код, чтобы можно было вызывать любые API-интерфейсы мыла.
Вот как я создал класс запроса
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "RetrievePCData", namespace = "http://apcc.com/")
public class RetrievePCDataRequest {

@XmlElement(name = "sSalesOrderNo", namespace = "http://apcc.com/")
private String salesOrderNo;

public RetrievePCDataRequest() {
}

public RetrievePCDataRequest(String salesOrderNo) {
this.salesOrderNo = salesOrderNo;
}

public String getSalesOrderNo() {
return salesOrderNo;
}

public void setSalesOrderNo(String salesOrderNo) {
this.salesOrderNo = salesOrderNo;
}
}

Вот как я делаю мыльный вызов:
public Mono retrievePCData(String salesOrderNo) {
try {
RetrievePCDataRequest retrievePCDataRequest = new RetrievePCDataRequest();
retrievePCDataRequest.setSalesOrderNo(salesOrderNo);
String soapRequest = marshallSoapRequest(retrievePCDataRequest);
logger.info(soapRequest);
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_XML_VALUE);
headers.add("SOAPAction", "http://apcc.com/RetrievePCData");
return webClientService.postXml("http://webservices.apc.com/webservices/ ... ssSvc.asmx",
String.class, headers, soapRequest)
.doOnSuccess(response -> {
logger.info( response);
System.out.println( response);
})
.doOnError(error -> {
logger.error( error.getMessage(), error);
System.out.println("SOAP API Error: " + error.getMessage());
});
} catch (JAXBException e) {
logger.error("Error while marshalling SOAP request", e);
return Mono.error(e);
}

}
private String marshallSoapRequest(RetrievePCDataRequest request) throws JAXBException {
SoapEnvelope envelope = new SoapEnvelope();
SoapBody body = new SoapBody();
body.setRequest(request);
envelope.setBody(body);
JAXBContext context = JAXBContext.newInstance(SoapEnvelope.class);
Marshaller marshaller = context.createMarshaller();
StringWriter writer = new StringWriter();
marshaller.marshal(envelope, writer);
return writer.toString().replace("ns2:", "soap:").replace("xmlns:ns2", "xmlns:soap");
}
```

and in the webclientservice this is how making the call


public Mono postXml(String uri, Class responseType, заголовки HttpHeaders, String xmlBody) {
this.appLogger.info(EXTERNAL_API_POST_CALL_STARTED_MSG + uri);
try {
System.out.println(webClient.post()
.uri("http://webservices.apc.com/webservices/ ... ssSvc.asmx")
.headers(httpHeaders -> httpHeaders.addAll(headers))
.contentType(MediaType.TEXT_XML)
.bodyValue(xmlBody)
.retrieve()
.bodyToMono(String.class) // response body
.block());}

catch(Exception e)
{
System.out.println(e.getMessage());
}



But The error message is not similar to the one which I have added as the screenshot of Soap Ui.
For reference I am sharing the xml that gets generated

652001379

Can you please guide me

[1]: https://i.sstatic.net/DahGXjy4.png


Подробнее здесь: https://stackoverflow.com/questions/790 ... b-services

Вернуться в «JAVA»