5 Replies Latest reply on Sep 27, 2012 12:53 PM by alexmd

    Access to session in RPC methods

    alexmd

      Hi,
      currently, I'm evaluating Errai for one of our GWT-based web applications. I want to use RPC and need session management on server side. With Errai it is possible to get access to the session using the Message object in MessageCallbacks. My question is: How can I get access to the session in rpc methods? It seems there is no Message instance available to get the session from.
      BTW: Is there a Javadoc documentation for Errai's server API?

       

      Thanks for any help.
      Best regards,
      Alexander.

        • 1. Re: Access to session in RPC methods
          cbrock

          Yes.

           

          QueueSession session = Message.getResource(QueueSession.class, "Session");

          • 2. Re: Access to session in RPC methods
            alexmd

            Hello Christopher,

            thank you for your answer. Unfortunately, this doesn't work because the getResource() method can be invoked only for an instance of Message. It's not a static method (in Errai 1.1.0.M1 that I use). My problem is: I don't know how to get the (valid and corresponding) Message instance in an RPC method on the server side. In a service class that inherits MessageCallback I get a reference to the Message instance as parameter in the callback. But my RPC service is a standalone class that inherits nothing and implements my RPC interface  only. I searched for a solution in documentation and examples. Maybe I missed something...

            Best regards,

            Alexander.

            • 3. Re: Access to session in RPC methods
              cbrock

              Yeah, I answered your question a little bit too hastily there.  The truth is there's really no way to do it out of the box with RPC calls.  The only really reliable way to hack it, would be to use a modified DefautlBlockingServlet which holds a copy of the session in a ThreadLocal and use SimpleDispatcher implementations to prevent any off-thread processing. 

               

              But this is definitely something we should consider adding support for.

              • 4. Re: Access to session in RPC methods
                misqu23

                If you are using errai-cdi you can inject HttpSession object (maybe you do not need queuesession) into the rpc service.

                • 5. Re: Access to session in RPC methods
                  alexmd

                  For the sake of completeness: In Errai 2 there is the RpcContext class which provides access to the HttpSession and ServletRequest.