Java WebService 请求超时



我的问题是我调用了一个远程 Web 服务,该服务需要 60 多秒才能响应,这会导致超时异常。我不想要任何超时检查:我只希望发件人等到 Web 服务结束。我尝试设置:

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

修改网络.xml会话超时(即使我认为这与我的问题无关)以创建自定义 HttpRequest。超时仍然存在。有没有办法关闭此检查?

找到了解决方案:

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

httpSession.setMaxInactiveInterval不是你所追求的。您可能希望在 URLConnection 上设置 connectTimeout 和 readTimeout。如何执行此操作取决于您使用什么工具来调用远程 Web 服务。

您能否添加有关该服务的更多详细信息,如果它是 SOAP 服务、REST 服务等,以及您使用哪个库来调用该服务?

最新更新