Spring consume rest json web-service error

658 views Asked by At

below code cause error

public ArrayList<model.SampleObject> getObjectByNameGet(String name) {

    final String uri = "http://127.0.0.1:8080/services/example/{name}" ;


    Map<String, String> map = new HashMap<String, String>();
    map.put("name", name);


    RestTemplate restTemplate = new RestTemplate();
    ResponseEntity<SampleObject[]> responseEntity = null;
    try {
        responseEntity = restTemplate.getForEntity(uri, SampleObject[].class,map);
    } catch (HttpStatusCodeException e) {
        String errorpayload = e.getResponseBodyAsString();
        throw e;
    } catch (RestClientException e) {
        throw e;
    }

    model.SampleObject result = restTemplate.getForObject(uri, model.SampleObject.class);
    SampleObject resultOut[] = responseEntity.getBody();

    ArrayList<SampleObject> arrayList = new ArrayList<SampleObject>(Arrays.asList(resultOut));
    return arrayList;

}

on this line:

responseEntity = restTemplate.getForEntity(uri, SampleObject[].class,map);

but service is live and reachable, its local: service is run

error:

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://127.0.0.1:8080/services/example/m":Permission denied: connect; nested exception is java.net.SocketException: Permission denied: connect
org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:543)
org.springframework.web.client.RestTemplate.execute(RestTemplate.java:497)
org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:258)
code.Client.getObjectByNameGet(Client.java:32)
org.apache.jsp.index_jsp._jspService(index_jsp.java:146)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

I add -Djava.net.preferIPv4Stack=true to intellij VM Options also with no luck.

Whats the cause of error? thanks in advance

1

There are 1 answers

0
Ehsan On BEST ANSWER

after long google and study, I found root of the problem. there is a bug in window 8 that cause java socket failed to connect to any URL.

there was no problem in windows 7 tests.