Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone !
I would like to be able to do a simple thing : get the client ip address when requests ?
I searched for it but I didn't find relevant results...
Thanks !
Stupid mistake... I put the code in a tJava instead of a tJavaRow. It was logical...
The problem is solved. I put here a complete and simple example of the solution for those who also want to get the IP of the service caller
Thank you vapukov !
The code of the tJavaRow :
//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. //Display the IP Address System.out.println(messageContext.getHttpServletRequest().getRemoteAddr()); //Save the IP in the schema output_row.ipadr = messageContext.getHttpServletRequest().getRemoteAddr().toString();
Pictures :
Hi,
is this what you are looking for:
regards, Vlad
can't say anything without information
from studio:
Endpoint deployed at: http://127.0.0.1:8090/services/customers [statistics] connecting to socket on port 3768 [statistics] connected [WARN ]: org.eclipse.jetty.server.handler.AbstractHandler - No Server set for org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine$1@587d83f6 Client ip - 127.0.0.1
from runtime:
2/15/19 2:50 PM | INFO | 248 - Talend ESB :: Job :: Controller | Adding job DemoREST. | 2/15/19 2:50 PM | INFO | 248 - Talend ESB :: Job :: Controller | Starting job DemoREST | Client ip - 0:0:0:0:0:0:0:1
@Alpha549 wrote:
Could you send a screen of your test job using this tJava code please?
we are looking for errors in my code or in yours? 🙂
P.S.
I just copy past code and edit print message
Stupid mistake... I put the code in a tJava instead of a tJavaRow. It was logical...
The problem is solved. I put here a complete and simple example of the solution for those who also want to get the IP of the service caller
Thank you vapukov !
The code of the tJavaRow :
//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. //Display the IP Address System.out.println(messageContext.getHttpServletRequest().getRemoteAddr()); //Save the IP in the schema output_row.ipadr = messageContext.getHttpServletRequest().getRemoteAddr().toString();
Pictures :
great!
welcome onboard! 🙂
Hi,
Can anyone help to get ip address for a soap service.
The above one is for rest.