You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Yohan Yudanara <yo...@gmail.com> on 2011/12/27 09:48:10 UTC

tapestry-resteasy: How to Get IP Address on Resource Class

Hi,

I want to ask a question about tapestry-resteasy library from tynamo (
www.tynamo.org)
Is it possible to get client IP Address on tapestry-resteasy resource class?
I need the IP address of incoming request for logging purpose.

Thanks in advance

Best regards,
Yohan Yudanara

Re: tapestry-resteasy: How to Get IP Address on Resource Class

Posted by Yohan Yudanara <yo...@gmail.com>.
Hi,

thank you very much for pointing me for using @Context.
It's work...

@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("doSomething")
public String doSomething(@QueryParam("actionId") Long customerId,
                                 @Context HttpServletRequest request) {
  String ipAddress = request.getRemoteAddr();
}

Best regards,
Yohan Yudanara


2011/12/28 Bård Magnus Kvalheim <ma...@kvalheim.eu>

> Hi Yohan,
>
> Havent tried but you should be able to get it from
> @Context HttpServletRequest request
>
> http://docs.jboss.org/resteasy/docs/2.3.0.GA/userguide/html_single/index.html#_Context
>
> Think context injection works on resource method as well as members.
>
> Then use request.getRemoteAddr()
>
> Guess you could also use tapestry inject for getting httpservletrequest.
>
> Tip
> With resteasy you can register providers that can intercept all resource
> method invocations. That way you can handle logging from a single place.
>
> http://docs.jboss.org/resteasy/docs/2.3.0.GA/userguide/html_single/index.html#Interceptors
>
>
>
> Hope it helps
>
> Cheers and merry christmas
> Magnus
>
> On Tue, Dec 27, 2011 at 9:48 AM, Yohan Yudanara <yohan.yudanara@gmail.com
> >wrote:
>
> > Hi,
> >
> > I want to ask a question about tapestry-resteasy library from tynamo (
> > www.tynamo.org)
> > Is it possible to get client IP Address on tapestry-resteasy resource
> > class?
> > I need the IP address of incoming request for logging purpose.
> >
> > Thanks in advance
> >
> > Best regards,
> > Yohan Yudanara
> >
>

Re: tapestry-resteasy: How to Get IP Address on Resource Class

Posted by Bård Magnus Kvalheim <ma...@kvalheim.eu>.
Hi Yohan,

Havent tried but you should be able to get it from
@Context HttpServletRequest request
http://docs.jboss.org/resteasy/docs/2.3.0.GA/userguide/html_single/index.html#_Context

Think context injection works on resource method as well as members.

Then use request.getRemoteAddr()

Guess you could also use tapestry inject for getting httpservletrequest.

Tip
With resteasy you can register providers that can intercept all resource
method invocations. That way you can handle logging from a single place.
http://docs.jboss.org/resteasy/docs/2.3.0.GA/userguide/html_single/index.html#Interceptors



Hope it helps

Cheers and merry christmas
Magnus

On Tue, Dec 27, 2011 at 9:48 AM, Yohan Yudanara <yo...@gmail.com>wrote:

> Hi,
>
> I want to ask a question about tapestry-resteasy library from tynamo (
> www.tynamo.org)
> Is it possible to get client IP Address on tapestry-resteasy resource
> class?
> I need the IP address of incoming request for logging purpose.
>
> Thanks in advance
>
> Best regards,
> Yohan Yudanara
>