我只想知道有什么方法可以在 Play 框架中使用 SOAP 网络服务,特别是版本 1.x.x
谢谢
最佳答案
其他答案当然有效,但 Play 为此类内容提供了一些方便的类。不过,您需要手动解析响应。
从 WS
类开始。它可用于发布/获取或任何与各种服务相关的内容。例如,我将它用于 SOAP 请求和 REST 调用。
例子:
HttpResponse httpResponse = null;
String username = "";
String password = "";
String url = "";
String postBody = "";
try {
httpResponse = WS.url(url)
.authenticate(username, password)
.setHeader("Content-Type", "text/xml; charset=UTF-8")
.setHeader("SOAPAction", "")
.body(postBody).post();
Document document = httpResponse.getXml();
String value = XPath.selectText("//value", document);
Node node = XPath.selectNode("//node", document);
// Do things with the nodes, value and so on
} catch (Exception e) {
Logger.error("Do something with the connection error: %s", e);
}
如您所见,我使用XPath
类来解析返回的Document
。它提供了各种有用的方法来遍历文档。
关于java - 在 Play 1.x 框架中使用 SOAP Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15653821/