Thursday, August 11, 2011

Application of Activity Token | Multiple ways to getActivityToken

Activity Token is the equivalent of sessionid and thought not advised but sometimes, it is required to use activityId for some custom implementations:
1. If you are implementing a custom XSRF, even though V6 Fix Pack 10 has this feature.
2. Custom WebService across devices that can't use cookies but need to maintain commerce session.

public ActivityToken getActivityToken(HttpServletRequest request)

{
// Check, is it available as a request attribute?
ActivityToken token = null;
token = (ActivityToken) request.getAttribute(ECAttributes.ATTR_EC_ACTIVITY_TOKEN);
// that's not true, try request handle
if (token == null) {
RequestHandle handle = (RequestHandle)request.getAttribute(ECAttributes.ATTR_EC_REQUEST_HANDLE);
token = (handle != null) ? handle.getActivityToken() : null;
}
// Try command context , if above 2 returne
if (token == null) {
CommandContext commandContext = (CommandContext) request.getAttribute("CommandContext");
token = (commandContext != null) ? commandContext.getActivityToken() : null;
}
return token;
}

This is my 50th post, if you guys like reading my blogs :), please drop a comment.

19 comments:

  1. Keep it up! Think this is the only Commerce blog, so I'm happy to at least have this.

    On the activity token, we have seen some instances where customers are migrated the wrong way so they see other peoples shopping lists etc. Very hard to recreate, so it must be some performance problem. Might there be some dynacache on activity tokens that could go wrong?

    ReplyDelete
  2. @Joffemannen I don't the activity token can be used as a cache key. Here is a list of known "cache identifiers" (request attributes) which can be used as cache keys: http://publib.boulder.ibm.com/infocenter/wchelp/v6r0m0/index.jsp?topic=/com.ibm.commerce.admin.doc/concepts/cdc_cacheident.htm

    How is the cache key defined for your shopping list in cachespec.xml?

    ReplyDelete
  3. @Joffemannen if the problem is during cart migration from guest user to registered user, you could use GuestUserOrderMigrationEventListener or extend that. From what you described if sessions are getting interchanged, seems like CTXMGMT\CTXDATA, context related tables could be corrupted.

    ReplyDelete
  4. I'm currently trying to get a WCToken to allow a CSR user to retrieve a customers cart using the existing carthandler REST service, by extending the LoginIdentityHandler. To do this in learning how commerce handles user security.

    Thanx for sharing this info!

    ReplyDelete
  5. Really Useful... Thanks so much.. Keep posting :)

    ReplyDelete
  6. I see the greatest contents on your blog and I extremely love reading them. Roblox APK Download Latest & Updated Version

    ReplyDelete
  7. I read that Post and got it fine and informative. Please share more like that... TubeMate APK iPhone Download

    ReplyDelete
  8. Well we really like to visit this site, many useful information we can get here. Tubidy APK 2020 Latest Update Download Free

    ReplyDelete
  9. Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. applicant tracking system

    ReplyDelete
  10. The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface. black satta king

    ReplyDelete
  11. You have a real talent for writing unique content. I like how you think and the way you express your views in this article. I am impressed by your writing style a lot. Thanks for making my experience more beautiful. black satta king

    ReplyDelete
  12. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. buy real marijuana online

    ReplyDelete
  13. I have been checking out a few of your stories and i can state pretty good stuff. I will definitely bookmark your blog thc oil cartridges shipped anywhere

    ReplyDelete
  14. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. pre filled vape cartridges

    ReplyDelete
  15. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. birra wide child

    ReplyDelete
  16. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. https://www.sergiofabbri.com/borse-sneakers-la-carrie

    ReplyDelete
  17. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. situs slot online

    ReplyDelete
  18. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. شحن من كندا لمصر

    ReplyDelete
  19. thank you for your interesting infomation. satta king

    ReplyDelete