views:

280

answers:

3

How can i access client details like IP,Browser etc in a web service in java?

A: 

Information related to Browser would be available in the HTTP headers like : content type, version etc. If a web service were able to get the IP address of it clients, the security would have been heavily comprised. IP address can be never accessed until the client sends it as a param to your call.

Cshah
Why would the security be compromised? The server does always know the IP address of the client. Otherwise, it wouldn't know where to send the response to a request
janko
No, the server only knows the IP address to respond to, which may be the address of a proxy server or NAT device. This may not be an IP address of the client.
John Saunders
@janko, When you connect to a server in a internet, the server only knows the next hop address and not the ip address of the client. And if you are behind a proxy then at max the server can know the proxy ip but not the actual client ip which sits behind the proxy
Cshah
+1  A: 
String ip = request.getRemoteAddress();
String browser = request.getHeader("User-Agent");
ZZ Coder
this will do if iam using Jsp pages only.
Thomas Manalil
+1  A: 

if you are using axis or Jax Rpc, then you can this to get the IP Address and Browser, This has to be done on the server side stub.

HttpServletRequest httpReq = (HttpServletRequest) MessageContext.getCurrentContext().getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);

String ip = httpReq.getRemoteAddr();

String browser = httpReq.getHeader("User-Agent");
shivaspk