java - Java Soap 客户端太慢了
问题描述
我有一个 Java Soap 客户端,它将带有服务和方法的 XML 请求发送到远程服务器,但它异常缓慢并且不能专业使用。有没有办法加快速度,或者有没有更快的方法来做肥皂请求?
谢谢您的回答。这是我的 Soap 客户端的摘录。
private SOAPMessage makeMessage(String nodeName, String xmlStr, boolean asResponse) throws Exception {
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/1999/XMLSchema-instance");
envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/1999/XMLSchema");
SOAPBody body = envelope.getBody();
SOAPElement element = body.addChildElement(envelope.createName("ns1:" + this.method + (asResponse ? "Response" : "")));
element.addAttribute(envelope.createName("xmlns:ns1"), "urn:" + this.service);
element.addAttribute(envelope.createName("ns1"), "http://schemas.xmlsoap.org/soap/encoding");
SOAPElement ele2 = element.addChildElement(envelope.createName(nodeName));
ele2.addAttribute(envelope.createName("xsi:type"), "xsd:string");
ele2.addTextNode(xmlStr);
if (!asResponse) message.saveChanges();
return message;
}
private boolean sendRequest() throws Exception {
try {
SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
SOAPConnection con = conFactory.createConnection();
URL endpoint = new URL(this.getURI());
SOAPMessage message = this.makeMessage("msgstr", this.request.toString(), false);
SOAPMessage retval = con.call(message, endpoint);
//extraction du XML en String lisible du message SOAP
this.response = extractXML(retval);
} catch (Exception e) {
this.response = e.getMessage();
}
return true;
}
解决方案
您应该启用您正在为客户端使用的框架的所有跟踪/日志信息,以便查看问题出在哪里。
如果您使用的是 jax-ws,一种简单的方法是:
System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");
推荐阅读
- php - 以下问题需要什么 SQL 命令?
- python - mypy 是否有子类可接受的返回类型?
- node.js - 在 promise.then 和 res.send 之前未按需要修改对象字段
- google-cloud-platform - 如何在 YAML/JINJA 中基于已部署的 VM 创建实例模板
- rest - 如何使用ngrx从API发出GET请求?(Angular 7)
- node.js - 如何在 node.js 中集成 neo4j 驱动程序
- c# - 检查 db ef 6 中存在的实体“列表”
- java - 无法将存储在 firebase 中的内容查看到回收站视图
- angular - 材质树控件不显示来自 http 服务的异步数据
- c++ - 在单元测试中测试连接丢失(在节俭的 C++ 应用程序中或一般情况下)