1
I have a REST service in my application and in it I want to pick up the IP of the client who is making the call, 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 printo o ip que veio na request printa "127.0.0.1", I am invoking the service that is on a server with the ip 192.168.0.33, internal server only for testing same and my ip is 192.168.0.63, I make the request of my machine right in my entimento should print 192.168.0.62 that is my ip, Voui post the code of the client 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 hint as to why the IP printout is 127.0.01?
thanks buddy gave it right
– Cristian Urbainski