2013-11-14 26 views
2

我的問題是我調用遠程Web服務需要超過60秒的響應,這會導致超時異常。我不想要任何超時檢查:我只希望發件人等到Web服務結束。我試圖設置:java WebService請求超時

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

修改web.xml中會話超時(儘管我不認爲這是我的問題有關)來創建自定義的HttpRequest。超時仍然存在。有什麼辦法可以關閉這個檢查嗎?

+0

及其基於容器http://stackoverflow.com/questions/141734/what-is-the-default-session-timeout-for-a-java-ee-網站 –

+0

已經嘗試過,已經失敗。更明確地說:我將web.xml和webservice web.xml的session-timeout設置爲60分鐘 – GoGoLander

回答

0

找到了解決方案:

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

httpSession.setMaxInactiveInterval不是你所追求的。 您可能想要在URLConnection上設置connectTimeout和readTimeout。 如何做到這一點,取決於你用什麼工具來調用遠程web服務。

如果是SOAP服務,REST服務等,您可以添加一些關於服務的更多細節,以及您使用什麼庫來調用服務?

+0

它們是返回XML的soap服務。我在javax.xml.ws包中使用Service類打開連接。希望可以幫助... – GoGoLander

+0

對不起,我沒有使用JAX-WS的經驗,我主要使用groovy-wslite調用SOAP服務。 – rlovtang