Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to get an IP from the service caller

I created a service in Talend job and I wonder is it possible to retrive the caller's(the one who is calling the service) IP from inside the service?

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I was intrigued by this, so followed the link supplied by @TRF and tried it out. It works. Here is the code I used in a tJava to return the IP address using a System.out call....

 

//You need to retrieve the restRequest Map from the globalMap
java.util.Map request = (java.util.Map)globalMap.get("restRequest");

//The acquire the MessageContext from that Map
org.apache.cxf.jaxrs.ext.MessageContext messageContext = (org.apache.cxf.jaxrs.ext.MessageContext)request.get("MESSAGE_CONTEXT");

//The acquire the the HttpServletRequest object and call the getRemoteAddr method from that.
System.out.println(messageContext.getHttpServletRequest().getRemoteAddr());

View solution in original post

7 Replies
TRF
Champion II
Champion II

So, does this helps?

In this case, thanks to mark the topic as solved.

Kudos also accepted!

vapukov
Master II
Master II


@TRF wrote:

Does this helps?

https://stackoverflow.com/questions/3825084/rest-how-get-ip-address-of-caller


thanks for idea, but - are You try to do this?

Anonymous
Not applicable
Author

I was intrigued by this, so followed the link supplied by @TRF and tried it out. It works. Here is the code I used in a tJava to return the IP address using a System.out call....

 

//You need to retrieve the restRequest Map from the globalMap
java.util.Map request = (java.util.Map)globalMap.get("restRequest");

//The acquire the MessageContext from that Map
org.apache.cxf.jaxrs.ext.MessageContext messageContext = (org.apache.cxf.jaxrs.ext.MessageContext)request.get("MESSAGE_CONTEXT");

//The acquire the the HttpServletRequest object and call the getRemoteAddr method from that.
System.out.println(messageContext.getHttpServletRequest().getRemoteAddr());
vapukov
Master II
Master II

thank You!

 

java.util.Map request = (java.util.Map)globalMap.get("restRequest");

this is was - what I not guess

Anonymous
Not applicable
Author

I had to trawl through the code in the code tab for a while to find it. Most things can be found in the globalMap though 🙂

Anonymous
Not applicable
Author

Thanx, I will test it when I have the time and if successful I will mark it as resolved.