Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > HTTP address of user??

Reply
Thread Tools

HTTP address of user??

 
 
Tim Slattery
Guest
Posts: n/a
 
      08-18-2005
I've just read a proposal for a new J2EE web system - or maybe a
cut-down version of an existing one. Regardless, there are some new
requirements. One of those is to record the IP address of the user.

I'm using Struts, so my Action objects get passed an
HttpServletRequest object and an HttpServletResponse object. I can't
figure out how to get the IP address of the user from those things. I
can get HTTP headers, but it's not there. I can get an HttpSession
object, but it doesn't seem to be there. There's a ServletContext
object that can be obtained from the HttpSession, but that doesn't
seem to do it either.

To complicate matters, this J2EE system runs behind an IIS gateway. Is
there a simple way to do this, or does the gateway have to be modified
to pass the IP address as another bit of data?

--
Tim Slattery
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Juha Laiho
Guest
Posts: n/a
 
      08-18-2005
Tim Slattery <(E-Mail Removed)> said:
>I've just read a proposal for a new J2EE web system - or maybe a
>cut-down version of an existing one. Regardless, there are some new
>requirements. One of those is to record the IP address of the user.
>
>I'm using Struts, so my Action objects get passed an
>HttpServletRequest object and an HttpServletResponse object. I can't
>figure out how to get the IP address of the user from those things.


See http://java.sun.com/products/servlet...getRemoteAddr()

>To complicate matters, this J2EE system runs behind an IIS gateway. Is
>there a simple way to do this, or does the gateway have to be modified
>to pass the IP address as another bit of data?


Yep, in this case getRemoteAddr() will only show the address of your
reverse proxy. You'll have to get the proxy to report the end-client
address somehow -- and mostly this would be to have the proxy to add
a header to the incoming request, and make your application to parse
that header. If possible, you might try to extend your application
server so that you intercept the request before it reaches your
server, and move the IP information from the HTTP header to the
place where getRemoteAddr() can pick it. This way, your application
still only uses the getRemoteAddr().
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
 
Reply With Quote
 
 
 
 
Raymond DeCampo
Guest
Posts: n/a
 
      08-18-2005
Juha Laiho wrote:
> Tim Slattery <(E-Mail Removed)> said:
>
>>I've just read a proposal for a new J2EE web system - or maybe a
>>cut-down version of an existing one. Regardless, there are some new
>>requirements. One of those is to record the IP address of the user.
>>
>>I'm using Struts, so my Action objects get passed an
>>HttpServletRequest object and an HttpServletResponse object. I can't
>>figure out how to get the IP address of the user from those things.

>
>
> See http://java.sun.com/products/servlet...getRemoteAddr()
>
>
>>To complicate matters, this J2EE system runs behind an IIS gateway. Is
>>there a simple way to do this, or does the gateway have to be modified
>>to pass the IP address as another bit of data?

>
>
> Yep, in this case getRemoteAddr() will only show the address of your
> reverse proxy. You'll have to get the proxy to report the end-client
> address somehow -- and mostly this would be to have the proxy to add
> a header to the incoming request, and make your application to parse
> that header. If possible, you might try to extend your application
> server so that you intercept the request before it reaches your
> server, and move the IP information from the HTTP header to the
> place where getRemoteAddr() can pick it. This way, your application
> still only uses the getRemoteAddr().


Additionally you will have the clients themselves potentially living
behind a proxy, leaving you with whole swaths of clients with the same
IP address.

Ray

--
XML is the programmer's duct tape.
 
Reply With Quote
 
Alvin Ryder
Guest
Posts: n/a
 
      08-18-2005
Tim Slattery wrote:
> I've just read a proposal for a new J2EE web system - or maybe a
> cut-down version of an existing one. Regardless, there are some new
> requirements. One of those is to record the IP address of the user.
>
> I'm using Struts, so my Action objects get passed an
> HttpServletRequest object and an HttpServletResponse object. I can't
> figure out how to get the IP address of the user from those things. I
> can get HTTP headers, but it's not there. I can get an HttpSession
> object, but it doesn't seem to be there. There's a ServletContext
> object that can be obtained from the HttpSession, but that doesn't
> seem to do it either.
>


Hi,

HttpServletRequest request has getRemoteAddr() so its just
request.getRemoteAddr() but ...

You cannot rely on remote addresses or hostname, this is not because of
J2EE but because of HTTP/CGI and network infrastructure.

HTTP/CGI doesn't guarantee you'll get an address or if you do it's
often the address of a proxy or some network equipment, maybe on your
side, the client's side, something in between or all of the above.

For example all AOL users may appear to have the same address and
there's nothing you can do to overcome that. Addresses are often also
translated eg using NAT so you might get an address but it won't be the
real one ...

The simple upshot is, remote ip and remote host cannot be relied on.

> To complicate matters, this J2EE system runs behind an IIS gateway. Is
> there a simple way to do this, or does the gateway have to be modified
> to pass the IP address as another bit of data?
>
> --
> Tim Slattery
> (E-Mail Removed)


 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      08-18-2005
Raymond DeCampo wrote:
>
> Additionally you will have the clients themselves potentially living
> behind a proxy, leaving you with whole swaths of clients with the same
> IP address.


Or potentially one client with many IP addresses of a clustered proxy.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/822319ev1'. 'HTTP/1.1 500 Internal Server Error'. chanmm ASP .Net 2 09-07-2010 07:37 AM
Split Tunnel Blocks http through tunnel but passes http around tunnel a.nonny mouse Cisco 2 09-19-2004 12:10 AM
Getting "HTTP Error 403 - Forbidden" at http://localhost/quickstart/ASPPlus/ Scott MCSD 1 08-04-2004 05:28 PM
HttpModule -- how to intercept urls like http://localhost/abc/def or http://localhost/abc/def/ where abc, def are non virtual dir Jiong Feng ASP .Net 0 11-19-2003 05:29 AM



Advertisments