Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the IP Address Of A client For a webservice

Tags:

I am using JAX-WS and I am having trouble retrieving the client information that is consuming a webservice. I've found out how to do it with JAX-RPC, and Apache Tomcat Axis, but not with JAX-WS. Does anyone have an idea about this?

like image 439
monksy Avatar asked Oct 29 '09 04:10

monksy


People also ask

How do I find the client IP address for a website?

The answer is to use $_SERVER variable. For example, $_SERVER["REMOTE_ADDR"] would return the client's IP address.

Can you get IP address from http request?

You can use RemoteAddr to get the remote client's IP address and port (the format is "IP:port"), which is the address of the original requestor or the last proxy (for example a load balancer which lives in front of your server). This is all you have for sure. This is because internally http. Header.

What is the IP address of the client?

Client IP addresses describe only the computer being used, not the user. If multiple users share the same computer, they will be indistinguishable. Many Internet service providers dynamically assign IP addresses to users when they log in.


1 Answers

What about this:

@WebService
public class MyService {

  @Resource
  WebServiceContext wsContext; 

  /**
   * Web service operation
   */ 
  @WebMethod 
  public String myMethod() { 

    MessageContext mc = wsContext.getMessageContext();
    HttpServletRequest req = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST); 
    System.out.println("Client IP = " + req.getRemoteAddr()); 

  }

} 
like image 130
Pascal Thivent Avatar answered Oct 13 '22 17:10

Pascal Thivent