Announcement Announcement Module
Collapse
No announcement yet.
Session Scope Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Session Scope

    Wanted to know if any of you ran into problems maintaining a session within a mvc app using s2ap.

    Also setting up things in a approriate way, my session is not properly managed.

    Thanks in advance ..

  • #2
    Session Scope

    Hi Thorsten,

    I'm not aware of any particular issues related to session-scoped beans; however, if you are still experiencing issues, please create a JIRA to track this, and be sure to include which release of the Platform you're using as well as what type of web deployment artifact (e.g., Standard WAR, Shared Libraries WAR, Shared Services WAR, or Web Module). In addition, please let us know how you are creating the WebApplicationContext for your app.

    Thanks,

    Sam

    Comment


    • #3
      Session Scope

      let me go into some details before raising a jire:

      Environment:
      using s2ap rc1

      I setup a simple mvc driven app .. nothing really special


      I setup a simple controller which looks like:
      <bean
      id="loginController"
      class="foobar.LoginController"
      p:clientSession-ref="messagingSession"
      p:requireSession="false"
      p:synchronizeOnSession="true"/>

      my session-bean looks like:
      <bean
      id="messagingSession"
      class="foobar.MessagingSessionService"
      p:messagingService-ref="messagingService"
      scope="session" >

      <aop:scoped-proxy/>
      </bean>

      The referenced messagingService is a singleton.

      To allow to use one messagingSession per user, I referred to the fine docs at:

      http://www.memestorm.com/blog/session-scoped-beans-in-spring-20/

      To access the session-bean from within the controller-code, I followed the "guideline" and started with fetching the ApplicationContext using the following line of code:
      ApplicationContext ac = org.springframework.web.context.support.
      WebApplicationContextUtils.getRequiredWebApplicati onContext(
      request.getSession().getServletContext());

      This call already produces a NullPointerException ...

      Any clue ???

      Comment


      • #4
        Session Scope

        reading again through the springframework docs, I find a description for the usage of the session scope.
        http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-factory-scopes-session

        I have implemented it exactly the same way ..
        but the service scoped as session is instantiated over and over again (expected bahavior for a request scope)

        Comment


        • #5
          Session Scope

          > ApplicationContext ac = org.springframework.web.context.support.
          > WebApplicationContextUtils.getRequiredWebApplicati onContext(request.getSession().getServletContext() );
          >
          > This call already produces a NullPointerException ...

          What type of web application is this: Standard WAR, Shared Libraries WAR, Shared Services WAR, or Web Module?

          regards,

          Sam

          Comment


          • #6
            Session Scope

            i created and deployed it as a
            Web Module

            :O)

            Comment


            • #7
              Session Scope

              Hi Thorsten,

              Then it totally makes sense that you ran into a NullPointerException, since there is no "Root" WebApplicationContext involved with a web module (i.e., the call to WebApplicationContextUtils. getRequiredWebApplicationContext(ServletContext) fails). See the corresponding documentation in the Programmer Guide which describes how to access the WAC for a web module.

              http://static.springsource.com/projects/applicationplatform/1.0.x/programmer-guide/html/ch05s03.html

              Regards,

              Sam

              Comment


              • #8
                Session Scope

                shame on me ..

                sorry ...

                Comment


                • #9
                  Session Scope

                  now things are getting interesting:

                  ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContex t(
                  request.getSession().getServletContext(),"my.bundl e.symbolic.name-ApplicationContext");

                  I try to access my application context in this way.
                  The using "request.getSession()" in order to get a previously used or a newly created instance of the service.
                  Although the symbolic name is correct, the app still throws a NullPointer exception.

                  If I however dont use the "request.getSession()" to receive the servlet-context, but use directly:
                  ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContex t(
                  getServletContext(),"com.steademy.service.ms.api-ApplicationContext");

                  the applicationContext is properly identified and loaded.

                  That brings me back to my questions.

                  As I (hope correctly) have learned, in order to receive a session-scoped bean, I need to fetch the applicationContext using the request.getSession().
                  I have of course correctly set the aop-proxied in my bean:

                  <bean
                  id="messagingSession"
                  class="foobar.MessagingSessionService"
                  p:messagingService-ref="messagingService"
                  scope="session" >

                  <aop:scoped-proxy/>
                  </bean>

                  So .. how do I fetch a session-scoped bean from the application-context, if the aforementioned solution does not (or no longer) work ???

                  Comment


                  • #10
                    Session Scope

                    Hi Thorsten,

                    Two quick questions:

                    > but the service scoped as session is instantiated over and over again (expected bahavior for a request scope)

                    1) Are you sure that you are actually creating and maintaining a session across requests within your application?

                    2) Do you have CGLIB installed in the repository? If not, make sure that MessagingSessionService implements an interface and that LoginController has a dependency on the interface and not the implementation.

                    - Sam

                    Comment


                    • #11
                      Session Scope

                      2) yep, the cglib (com.springsource.net.sf.cglib-2.1.3.jar) is located in the right directory. I need it for hibernate in any case.

                      1) The session should be created from within spring mvc. My controller definitions do look like:

                      ...
                      p:requireSession="true"
                      p:synchronizeOnSession="true"/>
                      ...

                      Thus I assume that the application should be session-aware.

                      But if you dont have any idea about it, I might have to look somewhere else. I thought that it might a bug or a misconfiguration of the s2ap from my side.

                      Comment


                      • #12
                        Session Scope

                        Perhaps this one helps:

                        org.springframework.web.HttpSessionRequiredExcepti on: Pre-existing session required but none found

                        My controller extends the AbstractController and implements handleRequest(request, session, respone) ..

                        Comment


                        • #13
                          Session Scope

                          Hi Thorsten,

                          I think it would beneficial if you would create a JIRA to track the problems you're seeing (e.g., a summary of this thread) so that we can make sure there are no issues we need to address within the Platform. If you have a small example which runs fine as a standard WAR (e.g., on Tomcat) but fails when converted to a web module on the Platform, that would also be helpful.

                          Thanks,

                          Sam

                          Comment

                          Working...
                          X