1 Reply Latest reply on Dec 24, 2009 6:19 AM by theflexuser23

    Reconnecting to channel set after lost connection


      Hi there,


      I am beginner to flex and I have a problem with to login after the connection to the BlaseDS has been lost.



      • The flex client calls a HelloWorld Java service exposed using spring-flex.  This service is called when the user hit the Hello World button on the UI.  The channel set on which this service is exposed is secured and for now we will resort to programmatic authentication.  (The user does is not required to input his username and password, just to simplify it a bit).  
      • As a client framework Cairngrom is used and an appriopriate delegate is setup to handle the remote object call. 
      • Here is a snippet from the HelloWorld delegate class called after the user hits the Hello World button.  
                public function getHelloWorldMessage():void{
                      var token:AsyncToken = __service.channelSet.login("username", "password");
                      token.addResponder(new AsyncResponder(
                          function(event:ResultEvent, token:Object = null):void {
                              Alert.show("You are logged in", "Login");
                              // Send the amf request to the backend.
                              var token2:AsyncToken = __service.getHelloWorld();
                              // Add the responder. 
                          function(event:FaultEvent, token:Object = null):void {
                              Alert.show("You are NOT logged in", "Login");
                      // Send the http request.
                      var token2:AsyncToken = __service.getHelloWorld();
                      // Add the responder. 

      • The __service is the Hello World service has been defined as follows.


      <mx:RemoteObject id="helloWorldServiceRemoteObject" destination="helloWorldService" channelSet="{helloWorldChannels}"/>
      <mx:ChannelSet id="helloWorldChannels" >
              <mx:AMFChannel uri="http://localhost:8080/helloworldservice-war-1.0.0.SNAPSHOT/messagebroker/amf/" />        


      What happens:

      • User clicks on the Helloworld, the program hits the getHelloWorldMessage and the ChannelSet.login("username", "password") is called.   The channelset authentication flag is set to true, and the _authAgent present in the ChannelSet class which was previously null is set
      • The success handler is called and the secured spring function returns the "Hello World" message.   
      • I restart the BlaseDS server to simulate an intermittent connection. 
      • Now the user clicks on Hello World button again and recieves an error since the authentication flag is still set to true there is no attempt to login again. 
      • The following FaultEvent is caught


        • faultCode=Client.Authentication
        • faultString=An Authentication object was not found in the SecurityContext
      • The user reclicks the Hello World button this time however the ChannelSet.authenticated  is set to false and the client code attempts to reconnect however fails.  The snippet below is an extract from the ChannelSet.as, when the user reclicks, the second condition is met and the  IllegalOperationException with error message "ChannelSet is in the process of logging in or logging out."  is thrown.  The condition is met since the _authAgent is not null. 

      public function login(username:String, password:String, charset:String=null):AsyncToken
              if (authenticated)
                  throw new IllegalOperationError("ChannelSet is already authenticated.");
              if ((_authAgent != null) && (_authAgent.state != AuthenticationAgent.LOGGED_OUT_STATE))
                  throw new IllegalOperationError("ChannelSet is in the process of logging in or logging out.");
              if (charset != Base64Encoder.CHARSET_UTF_8);
                  charset = null; // Use legacy charset, ISO-Latin-1.




      Does someone have any ideas as to how to resolve this?