Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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?
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());
So, does this helps?
In this case, thanks to mark the topic as solved.
Kudos also accepted!
@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?
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());
thank You!
java.util.Map request = (java.util.Map)globalMap.get("restRequest");
this is was - what I not guess
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 🙂
Thanx, I will test it when I have the time and if successful I will mark it as resolved.