如何设置 SOAP 调用超时

发布于 2024-11-30 06:39:31 字数 708 浏览 0 评论 0原文

我需要通过 HTTPS 使用 javax.xml.soap 为 SOAP 调用设置超时 但是我不知道该怎么做,一定有一个技巧可以做到这一点,但我找不到它。

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);

我看到有人在做:

if (xxxSoapService instanceof Stub)
            ((Stub) xxxSoapService).setTimeout(10000);

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

那里可能有我想念的东西。

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);

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

There is probably something I am missing there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇见了你 2024-12-07 06:39:31

假设您已经在后台线程中执行 .call() 。您可以在不同的线程上触发计时器并终止加载线程。

或者,由于 SOAPMessage 拥有您的所有数据,因此您可以仅使用 HttpUrlConnection 发送消息。

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

// more stuff for your message

connection.connect();

sm.writeTo(connection.getOutputStream());

这应该有效,除非我对 writeTo() 的行为有误解。

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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文