Obtain client ip address from web service

Posted on 2007-07-31
Medium Priority
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

petiex earned 2000 total points
ID: 19605988
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();


Expert Comment

ID: 19606986
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.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 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