简体   繁体   English

如何在Java中设置SOAP连接超时?

[英]How to set SOAP connection timeout in Java?

I am using the below code to send SOAP request to an endpoint. 我正在使用以下代码将SOAP请求发送到端点。 Since we are experiencing some delay in getting the response from server,i would like to set connection timeout in the code. 由于我们在从服务器获取响应时遇到了一些延迟,因此我想在代码中设置连接超时。

Code: 码:

SOAPConnectionFactory soapConnectionFactory =SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();   
MimeHeaders header = new MimeHeaders();              
header.addHeader("Content-type", "application/soap+xml;charset=UTF-8");
header.addHeader("SOAPAction", soapAction);
InputStream is = new ByteArrayInputStream(reqXML.getBytes());
SOAPMessage request = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(header, is);            
SOAPMessage soapResponse = soapConnection.call(request, endPoint);

Can some one help me to modify my code to add the timeout value? 有人可以帮我修改代码以添加超时值吗?

I have gone through thread Setting socket read timeout with javax.xml.soap.SOAPConnection ralted to same issue.I am unable to use the solution provided here as I get failure if I do not specify the soap version while creating soap message. 我通过javax.xml.soap.SOAPConnection线程设置套接字读取超时遇到了相同的问题。如果在创建肥皂消息时未指定肥皂版本,则会失败,因此无法使用此处提供的解决方案。

Since, SOAP uses jave.net.URLConnection underneath, you can set the system parameters for connection timeout with is going to be valid for SOAP as well. 由于SOAP在下面使用jave.net.URLConnection,因此您可以设置连接超时的系统参数,这对于SOAP也同样有效。 You can set the following parameters 您可以设置以下参数

-Dsun.net.client.defaultConnectTimeout= < timeout> -Dsun.net.client.defaultConnectTimeout = <超时>

-Dsun.rmi.transport.proxy.connectTimeout= < timeout> -Dsun.rmi.transport.proxy.connectTimeout = <超时>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM