Accessing Websphere Commerce 7.x Context Objects

1 1 1 1 1 1 1 1 1 1 Rating 0.00 (0 Votes)

IBM Infocenter URL for CommandContext is

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:

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());

Joomla SEO by MijoSEF