3 Replies Latest reply on Feb 5, 2007 11:36 AM by mugwump

    Remoting-Calls to SSB are not stateful

    mugwump

      I have some troubles with my very naive approach to use a Stateful Session Bean together with Seam.Remoting:

      The Scenario:
      User loads Page with a Multiple-Choice-Test. All questions are fetched from the server, each question is setup via javascript on the client. Each answer is sent to the server. At the end of the test, we redirect to a page to display the test-results.

      We try to implement this using:
      - Seam.Remoting to make up the Connection
      - Javascript to setup the questions
      - A stateful session Bean to hold the test and the results.
      - A conversation to demarcate start and end of the test.

      Alas, this does not work out-of-the-box: The problem is, that the remoting does not reconnect to the SSB, but instead starts new SSB's. Here is a rough sketch of the code:

      the SSB:

      @Stateful
      @Name ("examManager")
      @Scope(ScopeType.SESSION)
      public class ExamManagerBean implements ExamManager {
      
       @Begin
       public Test startTest(int testId) {
       ....
       }
      
      
       public void sendAnswer(int questionId, int answerId){
       ....
       }
      
       @End
       public String getResults(){
       ...;
       }
      
      }
      


      with all three Methods exposed in the ExamManager via @WebRemote.


      The javascript:

      var remoteManager = Seam.Component.getInstance("examManager");
      remoteManager.startTest(id, testLoaded)
      
      function testLoaded(test){
       setupNextQuestion(test);
       ....
      }
      
      function evaluateAnswer(){
       remoteManager.sendAnswer(test.questions[questionIdx].id, answerId, answerCallback);
       ....
      }
      
      



      The Test is fetched correctly and the first two calls to remoteManager.sendAnswer go to the same SSB with which the Test was started, the third call goes to another SSB and fails there, becaus the startTest() was never called and therefore the test not initialized.

      I checked via Seam.Remoting.getContext().getConversationId() that every Remoting-Call happens within the same context, so I'm puzzled and can't figure out, why the SSB-references are not stable in between the remoting calls... Is there something fundamentally wrong with this approach or am I simply missing a switch here somehwhere??!

      Thx for any hint&help
      Stefan





        • 1. Re: Remoting-Calls to SSB are not stateful
          shane.bryzak

          It looks like you're doing everything right. If you like, you could post an issue to jira with a minimal working test case that reproduces your issue and I'll take a look at it for you.

          • 2. Re: Remoting-Calls to SSB are not stateful
            mugwump

            ouch, I had hoped, that it was me who is doing something wrong. I wil upgrade to 1.1.5GA, hope that this bug magically vanishes and will post a testcase to jira, if it does not.

            • 3. Re: Remoting-Calls to SSB are not stateful
              mugwump

              ok, it looks like I have found a workaround for this: It looks like if you wrap the call into a batch:

              Seam.Remoting.startBatch();
              remoteManager.sendAnswer(..,...);
              Seam.Remoting.executeBatch();
              


              the conversation is propagated and the SSB is retrieved. So, until this issue is fixed, wrapping calls into a batch, even if you only have one call to make, does the trick.