AppendToGatewayUrl

June 22nd, 2009 by Rob

If you’re using BlazeDS and seeing an error involving a callback called “AppendToGatewayUrl” this might help.

AppendToGatewayUrl modifies the gateway of a NetConnection object with the session id (in this case “jsessionid”) of the current session. If you reconnect with this value appended to the gateway URL, your session can be identified, even on clients that do not use cookies.

There are two ways to handle this:

  • set NetConnection.client to an object that implements the AppendToGatewayUrl function, or;
  • subclass NetConnection to implement it (since NetConnection.client points to the NetConnection instance by default, you can not reassign the client field if you want this method to work).

There’s one caveat to both approaches, though. It has been my experience that if you call NetConnection.connect while you are receiving a response to bundled remote methods, the data may be lost or a “Client.Data.UnderFlow” error thrown. This occurs because AppendToGatewayUrl gets called after the first result, and the immediate call to NetConnection.connect aborts the rest of the transfer.

Here’s a sample implementation of option A:

public class Sample{

  private var conn : NetConnection;

  public function Sample(){
    conn = new NetConnection();
    conn .client = this;
    conn .connect(‘http://localhost/gateway’);
  }

  public function AppendToGatewayUrl(extra:String):void{
    conn .connect(conn.uri + extra);
  }

  public function load():void{
    conn .call(’service.load’,new Responder(loadResult,error));
  }

  private function loadResult(value:*):void{
    trace(‘value’,value);
  }

  private function error(err:*):void{
    trace(‘error’,err.message);
  }

}

To get around the problem with bundled calls, you could save the session id in a field and reconnect before the next call.