Spring RestTemplate Client - connection refused exception

社会主义新天地 提交于 2019-12-18 19:40:52

问题


I am new to webservices and trying to write a RESTFul webservice's client using RestTemplate. I am using org.springframework.http.converter.xml.MarshallingHttpMessageConverter as message converter and org.springframework.oxm.xstream.XStreamMarshaller as marshaller.

Is there any way to debug this further or find out the root cause of this issue?

My consumer class looks like this -

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

}

Exception :

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)

Caused by: java.net.ConnectException: Connection refused: connect at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:359)


回答1:


the webServiceURL you are trying to call is not reachable. Ensure the webServiceURL path is correct and is listening.

PS. Also check if there is some firewall issue at Server side.

Wireshark may help you to debug further.

http://www.wireshark.org/



来源:https://stackoverflow.com/questions/11648706/spring-resttemplate-client-connection-refused-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!