java - JAXWS - 设置 WSDL 请求超时所需的帮助

标签 java soap jax-ws java-metro-framework

我正在使用 Metro 2.0 和 J2SE5。我编写的应用程序在编译时不知道外部 WebService,它在运行时根据业务逻辑 XML 文件找到它们,因此我执行 WSDL 请求。

我写的示例代码如下:

字符串 wsdlServiceName = ...; 字符串 wsdlURL = ...; 文档有效负载 = ...;

final 字符串 nsURI = ...;
final QName serviceName = new QName(nsURI, wsdlServiceName + "Service");
final QName servicePort = new QName(nsURI, wsdlServiceName + "端口");

//为 SOAP 消息创建服务和调度程序
服务 service = Service.create(new URL(wsdlURL), serviceName);
dispatch = service.createDispatch(servicePort, SOAPMessage.class, Service.Mode.MESSAGE);

//设置超时
dispatch.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 3000);
dispatch.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", 3000);

//创建传出 SOAP 请求
SOAPBinding soapBinding = (SOAPBinding) dispatch.getBinding();
request = soapBinding.getMessageFactory().createMessage();

SOAPBody requestBody = request.getSOAPBody();
requestBody.addDocument(负载);

//调用网络服务操作
SOAPMessage 响应 = dispatch.invoke(request);

调用 Web 服务 ( dispatcher.invoke(request) ) 时超时正常工作

但是在设置超时之前请求 WSDL,如果 Web 服务没有响应,连接超时前需要 90 秒。

是否可以在请求 WSDL 之前设置超时?您需要一个调度程序来设置超时,但这是在创建请求 WSDL 的服务之后完成的?! (即 Service.create() )

最佳答案

尝试设置系统属性

sun.net.client.defaultConnectTimeout 

但来自Networking Properties它说在未来的版本中可能不支持它

但是我建议缓存 WSDL 而不是远程访问它。
这是更好的性能明智,特别是如果您正在使用预计不会经常更改的 WSDL。

关于java - JAXWS - 设置 WSDL 请求超时所需的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4387393/

相关文章:

java - 是否有一些完全配置的 Spring Wicket Hibernate 原型(prototype),包括注释?

java - 如何避免 "Root WebApplicationContext: initialization started"加载两次?

soap - 传输独立/依赖协议(protocol)是什么意思?

web-services - 什么是 SOAP 非 wsdl 模式选项中的 uri

java - Jersey 2 客户端将数据流逐 block 写入 POST 调用

Java SSL : client handshake failure and server no cipher suites in common

java - DependONGroups 注释 testng

python - 如何为 factory.create() 指定完整的命名空间

java - 公开一个以对象作为参数的方法的 Web 服务

ssl - 使用 2 路 SSL 的 Weblogic(10.3) 中的 Web 服务客户端 (JAX-WS) 无法完成握手