Announcement Announcement Module
Collapse
No announcement yet.
HttpSession - swf 2.x Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HttpSession - swf 2.x

    Hi,

    How do I retrieve the HttpSession?
    Also how do i retrieve the HttpRequest...

    These objects have more than just attributes, so not sure why only the attribute/paramter map is exposed.

    For instance, I need the JSession ID.

    Browsing thru the forums, this code no longer works

    Code:
            ServletExternalContext servletCtx = (ServletExternalContext)externalContext;
            
            HttpSession session = (HttpSession)servletCtx.getRequest().getSession();

  • #2
    These objects have more than just attributes, so not sure why only the attribute/paramter map is exposed.
    Because WebFlow is completly unaware of the underlying transport mechanism. The fact that you use Http isn't interesting for webflow. You could also build it on top of another protocol (JMS or something), just write some converters for the RequestContext and presto.

    Regarding your question I would say read the javadocs and look at the API.

    Code:
    ServletExternalContext servletCtx = (ServletExternalContext)externalContext;
    HttpServletRequest request = (HttpServletRequest) servletCtx.getNativeRequest();
    HttpSession session = request.getSession();

    Comment


    • #3
      Thanks for your answer, though surely this must be confusing?

      Code:
      ServletExternalContext servletCtx = (ServletExternalContext)externalContext;
      HttpServletRequest request = (HttpServletRequest) servletCtx.getNativeRequest();
      If I'm casting it to a ServletExternalContext, please explain why it would have anything to do with JMS? I didnt cast it do a JMSExternalContext ? Come on...

      As far as reading the javadoc and API, I have the book right in front of me, page 328 of "Working with Spring Web Flow"...any other books you can recommend?

      Thanks,
      Josh

      Comment


      • #4
        Again check the javadocs. ServletExternalContext is an implementation of ExternalContext which is the interface defining the getNativeRequest method. The cast isn't needed here.

        The book you have there is for webflow 1 NOT webflow 2. There are some considerable changes between the 2 versions. I would recommend the reference guide, the samples and the javadocs.

        Comment


        • #5
          Not too drag it on further...though you just demonstrated my point...

          This was your solution...

          Code:
          ServletExternalContext servletCtx = (ServletExternalContext)externalContext;
          HttpServletRequest request = (HttpServletRequest) servletCtx.getNativeRequest();
          HttpSession session = request.getSession();
          Then you go on to say
          "Again check the javadocs. ServletExternalContext is an implementation of ExternalContext which is the interface defining the getNativeRequest method. The cast isn't needed here."


          The bottom line...it's confusing to use for me, even for you. What can I do to help make it better? Can I file a JIRA issue to mark these confusion points? Because I will be using this framework for at least the time being, I just want it to be as convenient as it can, and it troubles me that even your answer was not spot on...

          Comment


          • #6
            Your initial question

            Originally posted by joshjdevl
            How do I retrieve the HttpSession?
            Also how do i retrieve the HttpRequest...

            These objects have more than just attributes, so not sure why only the attribute/paramter map is exposed.
            I responded that that was due to the fact that WebFlow doesn't care about the transport protocol. If you do something with JMS/HTTP/Jabber/your-own-protocol-here WebFlow still can work where HTTP does have a jsessionId, Jabber doesn't have. If we would always expose it or depend on it we would be in trouble.

            Regarding the sample, it was a cut/paste based on your code. I just made it work, for what I know you might still need to ServletExternalContext somewhere further down your code. If I would have taken it out you would have hold that against me...

            But if you must, here is your oneliner to obtain the session.

            Code:
            HttpSession session = (HttpSession) ((HttpServletRequest) requestContext.getExternalContext().getNativeRequest()).getSession();
            So it isn't confusing, you are ripping parts out of its context...

            Comment

            Working...
            X