开发者

How to set a timeout to a SOAP call

开发者 https://www.devze.com 2023-03-29 08:47 出处:网络
I need to set a timeout to a SOAP call using javax.xml.soap over HTTPS However I don\'t know how to do that, there must be a trick to do it but I could not find it.

I need to set a timeout to a SOAP call using javax.xml.soap over HTTPS However I don't know how to do that, there must be a trick to do it but I could not find it.

SOAPMessage sm = null;
SOAPMessage response = null;

SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();

MessageFactory mf = MessageFactory.newInstance();
sm = mf.createMessage();
...
...
URL url = new URL("https://server:XXXX/blablabla);
response = connection.call(sm, url);

I saw someone doing:

if (xxxSoapService instanceof Stub)
            ((Stub) xxxSoapService).setTimeout(10000);
开发者_如何学Python

xxxSoapService extends java.rmi.Remote and Stub is from import org.apache.axis.client.Stub;

There is probably something I am missing there.


Assuming you're already doing your .call() in a background thread. You can have a timer fire on a different thread and kill the loading thread.

Alternately, since SOAPMessage has all of your data you can just use HttpUrlConnection to send the message.

HttpUrlConnection connection = // initialize me!
connection.setReadTimeout(TIMEOUT_VALUE);
SOAPMessage sm = // initialize me!

// more stuff for your message

connection.connect();

sm.writeTo(connection.getOutputStream());

This should work, unless I'm mistaken about the behavior of writeTo().

0

精彩评论

暂无评论...
验证码 换一张
取 消