Я попытался создать несколько списков из существующего веб-сервиса SOAP. Но проблема в том, что я всегда получаю нулевое значение, когда пытаюсь его сгенерировать.
Может быть, кто-то может прокомментировать, почему эта проблема происходит со мной?
Спасибо!
Шаги, которые я делаю:
Я сгенерировал wsdl из WSDL_link
Сгенерированные файлы wsdl с плагином:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<!-- Following configuration will pass ${project.basedir}/src/remote-xjc/bindings.xjc
and ${project.basedir}/src/jaxws/bindings-default.xjc to wsimport. -->
<configuration>
<wsdlUrls>
<wsdlUrl>${project.basedir}/src/main/resources/wsdl/FxRates_12.wsdl</wsdlUrl>
</wsdlUrls>
</configuration>
</execution>
</executions>
</plugin>
Я использовал этот плагин, потому что другие плагины всегда дают мне ошибки.
И попытался позвонить с помощью:
@RestController
public class GetRatesController {
private static final String soapEndpointUrl = "http://old.lb.lt/webservices/FxRates/FxRates.asmx";
private static final String soapAction = "http://www.lb.lt/WebServices/FxRates/getCurrencyList";
@RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/xml")
public ResponseEntity<GetCurrencyListResponse> getIndexView() {
GetCurrencyListResponse response = new GetCurrencyListResponse();
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
GetCurrencyList getCurrencyList = new GetCurrencyList();
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(soapAction, getCurrencyList), soapEndpointUrl);
JAXBContext jaxbContext = JAXBContext.newInstance(GetCurrencyListResponse.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
response = (GetCurrencyListResponse) unmarshaller.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
} catch (Exception e) {
System.err.println("\nError occurred while sending SOAP Request to Server!\nMake sure you have the correct endpoint URL and SOAPAction!\n");
e.printStackTrace();
}
System.out.println(response.getGetCurrencyListResult().getContent());
return new ResponseEntity<>(response, HttpStatus.OK);
}
private static <T> SOAPMessage createSOAPRequest(String soapAction, T requestClass) throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
createSoapEnvelope(soapMessage, requestClass);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
soapMessage.saveChanges();
return soapMessage;
}
private static <T> void createSoapEnvelope(SOAPMessage soapMessage, T requestClass) throws SOAPException, JAXBException {
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
JAXBContext jaxbContext = JAXBContext.newInstance(requestClass.getClass());
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
StringWriter sw = new StringWriter();
// SOAP Body
SOAPBody soapBody = envelope.getBody();
jaxbMarshaller.marshal(requestClass, sw);
System.out.println(sw.toString());
soapBody.addTextNode(sw.toString());
}
}
Но результат, который я получаю, равен нулю.
Какая часть не так? Как получить список валют, какой сервис должен вернуть?
XML службы списка валют: XML