2012-07-25 1432 views
9

我是新的webservices,並嘗試使用RestTemplate編寫RESTFul webservice的客戶端。 我使用org.springframework.http.converter.xml.MarshallingHttpMessageConverter作爲消息轉換器,org.springframework.oxm.xstream.XStreamMarshaller作爲編組。春天RestTemplate客戶端 - 連接被拒絕的異常

是否有任何方法進一步調試或找出這個問題的根本原因?

我的消費類看起來是這樣的 -

@SuppressWarnings("unchecked") 
public List<Deal> getClientInformation() throws RestClientException { 
    return restTemplate.getForObject(webServiceURL, List.class); 

}

例外:

Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect 
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:359) 
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:307) 
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:177) 
at main.java.com.sample.consumer.DealConsumer.getClientInformation(Consumer.java:35) 
at main.java.com.client.WebserviceConsumerTestClient.main(WebserviceConsumerTestClient.java:16) 

造成的:java.net.ConnectException:連接被拒絕:在org.springframework連接 .web.client.RestTemplate.doExecute(RestTemplate.java:359)

回答

16

您嘗試調用的webServiceURL無法訪問。確保webServiceURL路徑正確並正在偵聽。

PS。同時檢查服務器端是否存在防火牆問題。

Wireshark可以幫助您進一步調試。

http://www.wireshark.org/

+3

謝謝是的,這是防火牆問題。通過在客戶端代碼中點擊webservice之前添加以下兩行,我能夠解決這個錯誤。 System.setProperty(「proxyHost」,「yourproxy.server.com」); System.setProperty(「proxyPort」,「8080」); – PST 2012-07-25 11:51:40

+2

好得多,現在如果問題解決了,您可以通過將答案標記爲正確來關閉此問題。 – dhamibirendra 2012-07-25 11:58:27

+0

@dhamibirendra謝謝。 – pudaykiran 2014-07-01 07:07:46

相關問題