使用 JAXRPC-RI Web 服务客户端时如何设置连接超时? [英] How to set a connection timeout when using JAXRPC-RI web services client?

查看:28
本文介绍了使用 JAXRPC-RI Web 服务客户端时如何设置连接超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些使用 JAXRPC-RI(参考实现)库构建的客户端代码与 SOAP Web 服务(我绝对非常厌恶的技术)交互的一些遗留组件.

I'm working with a bit of a legacy component in which we interact with a SOAP web service (a technology which I absolutely, positively abhor) using some client code built using the JAXRPC-RI (reference implementation) library.

我对能够使用存根设置超时很感兴趣,以便万一 Web 服务服务器在 X 秒内没有回复,应用程序不会设置在那里永远等待响应.

I'm interested in being able to set a timeout with the stubs so that in case the web services server does not reply within X seconds, the application isn't setting there forever waiting for a response.

我习惯于使用由 Apache Axis 生成的客户端/存根,您可以在其中简单地使用 org.apache.axis.client.Stub.setTimeout() 来设置超时.

I'm using to working with clients/stubs generated by Apache Axis, in which you can simply use org.apache.axis.client.Stub.setTimeout() to set a timeout.

在我的一生中,我不知道如何在使用通过 JAXRPC-RI 创建的存根时设置超时:

For the life of me I can't figure out how to set a timeout when using Stubs created with JAXRPC-RI:

  • 我正在实例化的端口类扩展了 com.sun.xml.rpc.client.StubBase 并实现了 javax.xml.rpc.Stubcom.sun.xml.rpc.spi.runtime.StubBase.
  • 这些类的 JavaDocs 都没有提到任何类型的超时或执行此操作的方法.
  • 尝试像 stub._setProperty("axis.connection.timeout", 1000); 之类的代码在运行时导致异常:javax.xml.rpc.JAXRPCException:Stub 无法识别属性:axis.connection.timeout
  • The port class I am instantiating extends com.sun.xml.rpc.client.StubBase and implements javax.xml.rpc.Stub and com.sun.xml.rpc.spi.runtime.StubBase.
  • The JavaDocs for none of these classes mention any sort of timeout or method to do this.
  • Trying code like stub._setProperty("axis.connection.timeout", 1000); results in an exception at runtime: javax.xml.rpc.JAXRPCException: Stub does not recognize property: axis.connection.timeout

有人对使用 JAXRPC-RI 客户端时如何设置/强制超时有任何想法吗?甚至有可能吗?

Does anyone have any ideas on how to set/enforce a timeout when using a JAXRPC-RI client? Is it even possible?

推荐答案

你可能有运气设置属性,例如 sun.net.client.defaultConnectTimeoutsun.net.client.defaultReadTimeout,尽管这会引入系统范围的超时.

You may have luck setting properties such as sun.net.client.defaultConnectTimeout or sun.net.client.defaultReadTimeout, though that would then introduce a system-wide timeout.

在代码中,使用字符串设置属性值:

In code the properties values are set using Strings:

System.setProperty("sun.net.client.defaultConnectTimeout", "1000");
System.setProperty("sun.net.client.defaultReadTimeout", "1000");

为了快速测试,设置环境变量 JAVA_OPTS 或使用命令行可能更容易:

For a quick test, it might be easier to set the environment variable JAVA_OPTS or use the command line:

java -Dsun.net.client.defaultConnectTimeout="1000" ...

这篇关于使用 JAXRPC-RI Web 服务客户端时如何设置连接超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆