IBM Infocenter URL for CommandContext is http://publib.boulder.ibm.com/infocenter/wchelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.commerce.api.doc%2Fcom%2Fibm%2Fcommerce%2Fcommand%2FCommandContext.html&resultof=%22CommandContext%22%20%22commandcontext%22
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.
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());