Accessing Java Method getRemoteAddress() in Groovy for Identity Gateway"

Thanks for your response.Am using groovy how would I get this method called getRemoteAddress() in groovy? Pls advice.

I tried with the below snipped in groovy but it didn’t work.
import org.forgerock.services.context.ClientContext
logger.info ‘getRemoteAddress**:’+ClientContext.getRemoteAddress() //Offcousre i had logger defined.

Yeramsh,

In order to get the ClientContext you can use the context.asContext(...) call.
See Available Objects > context

Hi Gery,
I tried with the below code in the groovy file I get the below exception.Pls advice.
String remoteHost = context.asContext(ClientContext.class).getRemoteHost();
logger.info ‘remoteHost=:’+remoteHost

Error
Caused by: groovy.lang.MissingMethodException: No signature of method: org.forgerock.services.context.ClientContext.getRemoteHost() is applicable for argument types: () values:
Possible solutions: getRemotePort(), getRemoteUser()

Yeramsh,

There is no getRemoteHost function, as per the error message.
I think the function you are looking for is getRemoteAddress. Check the Javadoc for more options:
https://backstage.forgerock.com/docs/ig/6.5/apidocs/index.html?org/forgerock/services/context/ClientContext.html

1 Like

Thanks, Gery for the response. I saw the java dock but how would I retrieve this java method getRemoteAddress in a groovy file? Since am using this in IG.
I tried with the below but it doesn’t work.Did you get a chance to try out this pls? thanks
String remoteHost = context.asContext(ClientContext.class).getRemoteHost();

Yeramsh,

The Object will be available in the same way in Groovy and Java.
You may have to add the import.
import org.forgerock.services.context.ClientContext;
Let us know how it goes.

Hi Gery,
After the import, below is the error am getting.
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.forgerock.services.context.ClientContext.getRemoteHost() is applicable for argument types: () values:
Possible solutions: getRemotePort(), getRemoteUser()

Yeramsh,

This error shows that you are trying to use a method that does not exist.
You are using the object ClientContext in your script and therefore you must use one of the methods described in the Javadoc (link below). This had already been mentioned on December 13th, but here is the link again for convenience:
https://backstage.forgerock.com/docs/ig/6.5/apidocs/index.html?org/forgerock/services/context/ClientContext.html

1 Like