Obtain client ip address from web service

Posted on 2007-07-31
Last Modified: 2013-11-21
I have developed a webservice in java.

I have a single application which needs to be concurrently accessed by multiple clients. Therefore I need to know which client has made each request. Is there a way to obtain the client ip address from the soap response?

Question by:eadam-uk
    LVL 11

    Accepted Solution

    Inject a WebServiceContext instance into your WebService class, and use it in each WebMethod to get the current request's MessageContext Map. Get the SERVLET_REQUEST item from that, cast as an HttpServletRequest. From that HttpServletRequest, you can invoke getRemoteAddr() to get the client's IP.

    public class MyService{

    WebServiceContext wsCtxt;

    public void myWebMethod(){

    MessageContext msgCtxt = wsCtxt.getMessageContext();
    HttpServletRequest req = (HttpServletRequest)msgCtxt.get(MessageContext.SERVLET_REQUEST);
    String clientIP = req.getRemoteAddr();

    LVL 2

    Expert Comment

    The answer from petiex above assume some things about the SOAP library you are using and that you are using HTTP as the transport. Let me first ask that: what SOAP library are you using and what is the transport?

    The answer is essentially correct though: you need to get access to you transport protocol (usually HTTP) and get it from there.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    AWS New EC2 Instance and EBS Storage 2 46
    stringclean challenge 26 43
    java set up 1 35
    Java Message handling in Service Layer 3 19
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to count occurrences of each item in an array.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now