简体   繁体   English

Java WebService请求超时

[英]java WebService request timeout

My problem is that I call a remote web service that requires more than 60 seconds to respond and this causes a timeout exception. 我的问题是我调用了一个需要60秒钟以上响应的远程Web服务,这会导致超时异常。 I do not want any timeout check: I just want the sender to wait until the web service ends. 我不需要任何超时检查:我只希望发送方等待直到Web服务结束。 I tried to set: 我试图设置:

HttpSession httpSession = getThreadLocalRequest().getSession();
httpSession.setMaxInactiveInterval(120000);
getThreadLocalRequest().setAttribute("session", httpSession);

to modify the web.xml session-timeout (even though I do not think that it is related with my problem) to create a custom HttpRequest. 修改web.xml会话超时(即使我不认为这与我的问题有关)以创建自定义HttpRequest。 Timeout persists. 超时持续。 Is there any way to shutdown this check? 有什么办法可以关闭此检查?

httpSession.setMaxInactiveInterval is not what you're after. httpSession.setMaxInactiveInterval不是您想要的。 You probably want to set connectTimeout and readTimeout on URLConnection. 您可能要在URLConnection上设置connectTimeout和readTimeout。 How to do that, depends on what tool you use to call the remote webservice. 如何执行此操作,取决于您使用什么工具来调用远程Web服务。

Can you add some more details about the service, if it's a SOAP-service, REST-service etc, and what library you use to call the service? 您可以添加有关该服务的更多详细信息吗(如果它是SOAP服务,REST服务等),以及您用来调用该服务的库是什么?

Found the solution: 找到了解决方案:

/* Connect to the service */
ClientProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
factoryBean.setServiceClass(MyService.class);
factoryBean.setAddress("service-url");
myService = (MyService) factoryBean.create();
/* Retrive HTTP client policy and set the receive timeout */
Client client = ClientProxy.getClient(myService);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = httpConduit.getClient();
httpClientPolicy.setReceiveTimeout(timeoutMilliseconds);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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