Get the remote address when using knitwear with built-in grizzly

I was looking for a solution to this problem without success. The latest posts I found date back to 2010. I use jersey 1.12 with a built-in grizzly 2.2.1.

If I understand correctly, if I do not deploy my knitwear resources in the servlet container, I cannot enter HttpServletRequest into them. Is there a workaround?

+4
source share
2 answers

Use the following:

@Context org.glassfish.grizzly.http.server.Request req 

Usage example:

 @Path("/example") public class SomeResource { @POST @Consumes("application/x-www-form-urlencoded") public void someMethod(@Context Request req) { System.out.println(req.getRemoteAddr()); } } 
+1
source

In my case, we had a standalone Jersey cluster running after nginx as load balancer. So the workaround was to pass the remote address as the request header, which is also easily accessible from Jersey:

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
0
source

All Articles