cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve IP adress

scouil
Star Contributor
Star Contributor
Hello,

I first posted here https://forums.alfresco.com/en/viewtopic.php?f=14&t=22321 but I thought it's be better to create a topic to express my own needs.
I usually do javascript webservices but for one of them I need to discriminate the content depending on the IP of the client and it's not available in js.

I've mainly evaluated 2 possible solutions but couldn't get any of them to work:
1) Expose the java object encapsulating the remote address
2) Write a java webservice

I know it's possible to retrieve the remote address in a basic servlet and was told (cf previous link) that it should be possible with a java webservice but I went through all the methods and couldn't retrieve it.

Thanks for your help,
1 REPLY 1

scouil
Star Contributor
Star Contributor
I finally did it. You don't access it with a method but with a cast


if (req instanceof WebScriptServletRequest) {
   HttpServletRequest r = ((WebScriptServletRequest) req).getHttpServletRequest();
   String sourceIp = r.getRemoteAddr();
}