Search code examples
javaweb-servicessoapapache-axis

Obtain referer in Java SOAP webservice


I feel like this should be straight forward. We are implementing a Java webservice using SOAP in Eclipse. We want to know who is calling the webservice. I would have though I could get the referer from the header somehow but am at a loss as to how to do it. We are using Axis 2.


Solution

  • copied from TechNick you can leverage axis2 for this. The fact you're using Eclipse is largely irrelevant, the code below should work fine.

    //Import statement to import MessageContext class
    import org.apache.axis2.context.MessageContext;
    
    /*
    * This method gets the client IP address using axis2 MessageContext 
    *
    * @return Client IP : String
    */
    private String getClientIP () {
    
          return (String)(MessageContext.getCurrentMessageContext()).getProperty(MessageContext.REMOTE_ADDR);
    
    }