users@grizzly.java.net

How to get remote client IP with embedded Grizzly server

From: Hou, Chunxiao <chunxiao.hou_at_jpmorgan.com>
Date: Fri, 20 Sep 2013 17:20:43 +0000

Hi there,

I understand I can get client IP from HttpServletRequest but I am running an embedded grizzly server and have packagesResourceConfigs for it:

Grizzly http Server:
ResourceConfig rc = new PackagesResourceConfig(RESOURCE_DIR);
rc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, rc);

Resource:
public abstract class AbstractGetRiskResource {
                private static final Logger logger = LoggerFactory.getLogger(AbstractGetRiskResource.class);

                @GET
                public Response getMessage(@Context final UriInfo uriInfo, @Context HttpHeaders hh) {
                                String requestUri = uriInfo.getRequestUri().toString();
...
}

I've tried to add @Context HttpServletRequest to the Resource GET method parameter list, but it doesn't work.
Can someone please suggest how I can retrieve client IP info from the resource GET method? Many thanks!

Regards,
David


This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.