Saturday, April 12, 2014

Create command context in WebSphere Commerce

In classes where command context is not available or cannot be passed from the invoking command, the following code snippet can be used to create the command context.

com.ibm.commerce.foundation.server.services.businesscontext.ContextService bcs = com.ibm.commerce.foundation.server.services.businesscontext.ContextServiceFactory.getContextService();
com.ibm.commerce.command.CommandContext ctx = com.ibm.commerce.context.baseimpl.ContextHelper.createCommandContext(((com.ibm.commerce.component.contextserviceimpl.BusinessContextInternalService)bcs).getActivityToken());


And any command can be invoked

com.ibm.commerce.command.ControllerCommandcmd = (ControllerCommand)CommandFactory.createCommand(<<command name here>>,<<StoreId here>>);cmd.setCommandContext(ctx);
cmd.setRequestProperties(<<reqprops here >>);
cmd.execute();

2 comments:

  1. I tried this.. But the activity token is coming as null and not able to clone the commantcontext..

    ReplyDelete
    Replies
    1. I have the same issue too. The activityToken gets created when user logs in.. How to get it when we do through API and we want to create the Token for the new service.

      Delete