You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Luca Merolla <lu...@gmail.com> on 2012/09/19 12:43:40 UTC

Client IP address from Thread

Hi,

how can I get the client ip address from Thread in Tomcat?

In JBoss 7.1.1 I was using this piece of code

Thread.currentThread().getName();

and the generated output was:

jboss - http-localhost.localdomain-127.0.0.1-8080-1
tomee - http-bio-8080-exec-1

I want to get the IP address in the format of 127.0.0.1.

Thanks in advance,
Luca

Re: Client IP address from Thread

Posted by Luca Merolla <lu...@gmail.com>.
Yes, I have followed Romain advise and now I use the WebFilter
with getRemoteAddr() from HttpServletRequest and it should be
AS-independent.

On Wed, Sep 26, 2012 at 2:09 AM, zeeman <ha...@fastmail.us> wrote:

> That's not a good way to get IP, you're depending on app server. You should
> get the IP from HTTP request. Check out httpServletRequest java doc.
> HttpServletRequest request = //get from container
>  request.getRemoteAddr(); //ip string
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Client-IP-address-from-Thread-tp4657525p4657648.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Client IP address from Thread

Posted by zeeman <ha...@fastmail.us>.
That's not a good way to get IP, you're depending on app server. You should
get the IP from HTTP request. Check out httpServletRequest java doc.
HttpServletRequest request = //get from container
 request.getRemoteAddr(); //ip string



--
View this message in context: http://openejb.979440.n4.nabble.com/Client-IP-address-from-Thread-tp4657525p4657648.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Client IP address from Thread

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

for such a case i try to avoid to depend on any convention as much as
possible.

I'd personnaly use a web filter to store it from the request.

That's said you can probably configure tomcat executor service with a
custom name for each connector to get what you want

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/19 Luca Merolla <lu...@gmail.com>

> Hi,
>
> how can I get the client ip address from Thread in Tomcat?
>
> In JBoss 7.1.1 I was using this piece of code
>
> Thread.currentThread().getName();
>
> and the generated output was:
>
> jboss - http-localhost.localdomain-127.0.0.1-8080-1
> tomee - http-bio-8080-exec-1
>
> I want to get the IP address in the format of 127.0.0.1.
>
> Thanks in advance,
> Luca
>