简体   繁体   中英

How to set SOAP connection timeout in Java?

I am using the below code to send SOAP request to an endpoint. 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.

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. You can set the following parameters

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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