IBM Infocenter URL for CommandContext is Infocenter CommandContext API


When you review the methods you will see lot of deprecated methods which mention use of other context objects to access the information.

For this article we will review the CommandContext.getRemoteAddr() method which will give the IP address of the user accessing the site.


Infocenter mentions:

getRemoteAddr()
Deprecated. The TransportData object should be retrieved from the AuditContext of the request. The remote address is retrieved by calling TransportData.getRemoteAddress()

We need to use the AuditContext, but the first question is how we get instance of AuditContext.

CommandContext.getContext(strContextName) is the method we need to use.

Below sample code explains how to get IP address using the AuditContext

AuditContext auditCtx = (AuditContext) getCommandContext().getContext(AuditContext.NAME);
System.out.println("IP Address "+auditCtx.getTransportData().getRemoteAddress());
We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.