Announcement Announcement Module
Collapse
No announcement yet.
SWF + Servlet(Filter) for confirm hashkey Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SWF + Servlet(Filter) for confirm hashkey

    Hey,

    I developed a webapp which allows a user to register him/herself. One needs to enter an email addy and gets a confirm email to confirm, big surprise there

    I didn't create a webflow for the confirm part, as I thought it would be a lot easier to just create a servlet that listens to /confirm/** and then forward to my normal flow.

    That works as far as the forwarding and flow goes, but for data and the hashkey it's not going as I expected. I'll clarify.

    In order to get the hashkey in my controller bean, in webflow context I used a ThreadLocal. I put the hashkey from the servlet in the threadlocal, and I fetch it from the ThreadLocal in the controller SWF bean. This works well on my local Tomcat server so I went into staging after that on a Websphere server. Only to notice that there it didn't work. I implemented some logging and created a ServletFilter to log all incoming requests, only to see that:
    Thread A is used in the servlet and servletfilter. But from the moment that I get into a SWF context a DIFFERENT thread is used (let's say B). Of course this means that the SWF layer is unable to fetch the data from the ThreadLocal object.

    I'm rather new to SWF so I had no idea. If anyone knows of a good way to solve this, I'll gladly hear it. I do realize that I might have to create a whole new flow for the confirm. But if I can avoid that I'd prefer it like that.

    Thanks!
    W

  • #2
    That is strange. AFAIK webflow doesn't create or use new Threads on incoming requests (at least not 2.2), since this would mean, that all other ThreadLocal Spring variables like RequestContext etc. would stop working.
    And creating Threads isn't an easy thing to do correctly in an JEE application server like Websphere without using propietary APIs.

    So either it's a new request, because of an internal or external redirect (!), or you should check again for the Thread IDs.

    Comment


    • #3
      Originally posted by chbeutenmueller View Post
      That is strange. AFAIK webflow doesn't create or use new Threads on incoming requests (at least not 2.2), since this would mean, that all other ThreadLocal Spring variables like RequestContext etc. would stop working.
      And creating Threads isn't an easy thing to do correctly in an JEE application server like Websphere without using propietary APIs.

      So either it's a new request, because of an internal or external redirect (!), or you should check again for the Thread IDs.
      I realized that a few minutes after posting this thread. I also know why a new thread gets created.

      The confirm servlet does a forward, so no new request. However it fowards to the apps index page and this page does a "meta refresh" to the webflow context. That does indeed do a redirect, which of course is a new request and thread...

      But now that this thread is made I can ask about ThreadLocals right? :-)

      Am I using the right tool for connecting my servlet to SWF (ie the ThreadLocal) or should I try something else?

      Thanks for the quick reply
      W

      Comment


      • #4
        The best place to save the data across requests would be the HttpSession or a Cookie, you could than use a context listener or filter to put the persisted data into your ThreadLocal.

        Comment

        Working...
        X