2 Replies Latest reply on Nov 21, 2009 9:50 PM by Leo van den berg

    Statefull RESTfull service ?

    Ilya Dyoshin Novice
      Good day, community!

      I need to implement some "remoting" if it could be called so, with url-based params (no post), no specific remoting methods... The client system enables only url-encoded strings... and that is the huge problem. But anyway I need to implement following:


      http://host/service/begin?stk=asdfasdfasdfasfd

      which returns the name of started conversation (only string data. no xhtml/html)

      than some calls to:

      http://host/service/add?data=qweasdfasdfasfqwerqafqwerqwreasfasdf&cid=returnedCid
      http://host/service/add?data=qweasdfasdfasfqwerqafqwerqwreasfasdf&cid=returnedCid
      http://host/service/add?data=qweasdfasdfasfqwerqafqwerqwreasfasdf&cid=returnedCid


      and than

      http://host/service/end?cid=returnedCid

      during last call the conversation is ended. And all collected data is flushed to the database.

      hope this could be solved with  combination of SEAM+Something.


      Cheers,
      Ilya Dyoshin
        • 1. Re: Statefull RESTfull service ?
          Christian Bauer Master

          This is not going to work out of the box with Seam 2.2.


          There is however only one piece missing: The Seam filter that detects the cid=123 parameter in your requests and from this identifier restores the current conversation from the session context. This shouldn't be too difficult to implement, in fact, I'm not even sure if the existing filter for regular request processing wouldn't work. I did not test it at all.


          When that works, you create an @Path annotated resource that is also an @Name Seam component. Then you annotate the method for the @Path("/begin") with @Begin which starts a long-running conversation. The method for @Path("/end") is annotated with @End. Don't forget to enable the session support for REST, it's turned off by default. This is documented in the Seam manual.

          • 2. Re: Statefull RESTfull service ?
            Leo van den berg Master

            Hi,


            I implemented this for a mobile phone application which needed to retrieve data in different steps. I used JBPM to do the trick. The only thing you need to track is the Actor-ID and some additional JBPM calls. I kind-of scrambled the actor-id by using a log-in sequence in combination with unique key generation, which is used for subsequent requests.


            Be aware that you must give the Rest bean a session scope which is very nicely managed by Seam It drops the session very fast, so you don't run ouf of threads; really a nice additional RestEasy feature with Seam. I use EJB which can be accessed by Rest directly, as long as you set the Transaction attributes properly.


            Leo