2012-07-25 102 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

相关问题