Spring 消耗休息 json 网络服务错误
Spring consume rest json web-service 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;
}
这一行:
responseEntity = restTemplate.getForEntity(uri, SampleObject[].class,map);
但是服务是在线的并且可以访问,它是本地的:
service is run
错误:
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)
我在 intellij VM 选项中添加 -Djava.net.preferIPv4Stack=true 也没有成功。
错误原因是什么?
提前致谢
经过长时间的google研究,我找到了问题的根源。
window 8 中有一个错误导致 java 套接字无法连接到任何 URL.
windows 7 次测试没有问题。
以下代码导致错误
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;
}
这一行:
responseEntity = restTemplate.getForEntity(uri, SampleObject[].class,map);
但是服务是在线的并且可以访问,它是本地的: service is run
错误:
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)
我在 intellij VM 选项中添加 -Djava.net.preferIPv4Stack=true 也没有成功。
错误原因是什么? 提前致谢
经过长时间的google研究,我找到了问题的根源。 window 8 中有一个错误导致 java 套接字无法连接到任何 URL.
windows 7 次测试没有问题。