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

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

问题描述

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

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



我正在使用Apache Axis生成的客户端/存根,您只需使用 org。 apache.axis.client.Stub.setTimeout()设置超时。



对于我的生活,我无法弄清楚如何使用使用JAXRPC-RI创建的存根时设置超时:




  • 我实例化的端口类扩展 com。 sun.xml.rpc.client.StubBase 并实现 javax.xml.rpc.Stub com.sun.xml .rpc.spi.runtime.StubBase

  • The Ja没有这些类的vaDocs提到任何类型的超时或方法来执行此操作。

  • 尝试代码如 stub._setProperty(axis.connection.timeout,1000 ); 在运行时导致异常: javax.xml.rpc.JAXRPCException:Stub无法识别属性:axis.connection.timeout



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

解决方案

您可能有运气设置属性,例如 sun.net.client。 defaultConnectTimeout sun.net.client.defaultReadTimeout ,但这会引入系统范围的超时。



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

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

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

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


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.

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.

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.

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

  • 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

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

解决方案

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

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天全站免登陆