I have a REST service in my application and I want to get the IP of the client that is calling, use Spring-mvc in this project, here is the source of the service
/**
* HttpServletRequest.
*/
@Autowired
private HttpServletRequest request;
@ResponseBody
@RequestMapping("/buscar/{sessionid}/{codUsuario}")
public List<ProdutoVersaoVO> buscarProdutoCliente(
@PathVariable("sessionid") String sessionid,
@PathVariable("codUsuario") String codUsuario)
throws ParseException {
System.out.println(request.getLocalAddr());
System.out.println(request.getRemoteAddr());
}
When I start the ip that came in the request "127.0.0.1", I'm invoking the service that is on a server with ip 192.168.0.33, internal server only for testing and my ip is 192.168.0.63, I do the request of my machine soon in my entiment should print 192.168.0.62 which is my ip, I will post the client code that makes the request
public static List<ProdutoVersaoVO> buscarListaProdutoCliente(String usuarioId) throws IOException {
final String sessionId = login();
final HttpURLConnection urlConnection = getHttpUrlConnectionAreaCliente(URL_AREA_CLIENTE
+ "spring/produto/buscar/" + sessionId + "/" + usuarioId);
urlConnection.setUseCaches(false);
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
final String resposta = readStringResponse(urlConnection);
if (!resposta.isEmpty()) {
final ObjectMapper mapper = getObjectMapper();
return mapper.readValue(resposta, new TypeReference<List<ProdutoVersaoVO>>() {
});
} else {
return null;
}
}
private static String readStringResponse(HttpURLConnection urlConnection) throws IOException {
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
final StringBuilder str = new StringBuilder("");
String line = "";
while ((line = in.readLine()) != null) {
str.append(line);
}
return str.toString();
}
private static HttpURLConnection getHttpUrlConnectionAreaCliente(String enderecoWeb) throws IOException {
final URL url = new URL(enderecoWeb);
return (HttpURLConnection) url.openConnection();
}
Any suggestions on why the ip print is 127.0.01?