5 Replies Latest reply on Feb 11, 2010 5:31 AM by leftie friele

    passing information back via the header

      I need to pass some information back to my client using the header. I am using the Remote Object to make calls. I have an Id that I am passing from the client using a custom header but I am not sure what class to use in my custom adapter to add information so that it can be passed back in the amf3 header.

      Thanks Cameron
        • 1. Re: passing information back via the header
          mmissire

          Hi Cameron,

           

          I saw over on the JIRA site that you solved your problem. However, I wanted to ask you how you set the AMF header in the request (using RemoteObject) in the first place. I've been trying to do the same thing, but can't find a way.

           

          UPDATE: Nevermind. I see you extended Operation and did this:

           

                 mx_internal override function invoke(msg:IMessage, token:AsyncToken=null):AsyncToken {

                      msg.headers["TEST"] = "THIS IS A TEST"

                      return super.invoke(msg, token);
                  }

          • 2. Re: passing information back via the header
            jonas345

            mmissire,

             

            I am trying to do exactly this. I have tried to extend the Operation class but as soon as I do the call is never beeing sent. I have tried both to set an Operator on the RemoteObject and creating a separate Operator and passing in my remoteObject both ways have not worked for me.

             

            Do you mind to show an example of the RemoteObject setup you have to get this working?

             

            Regards,

            Jonas

            • 3. Re: passing information back via the header
              Marc Missire

              Here is more or less what we did:

               

               

              Extend Operation:

               

              package myproject.remoting
              {
                  import mx.core.mx_internal;
                  import mx.messaging.messages.IMessage;
                  import mx.rpc.AsyncToken;
                  import mx.rpc.remoting.RemoteObject;
                  import mx.rpc.remoting.mxml.Operation;

                  use namespace mx_internal;

                  public class MyOperation extends Operation
                  {
                      public function MyOperation(remoteObject:RemoteObject , name:String=null)
                      {
                          super(remoteObject, name);
                      }

                      mx_internal override function invoke(msg:IMessage, token:AsyncToken=null):AsyncToken
                      {
                          msg.headers["test"] = "test";

                          return super.invoke(msg, token);
                      }
                 

                  }
              }

               

              Extend RemoteObject:

               

              package myproject.remoting
              {
                  import mx.core.mx_internal;
                  import mx.rpc.AbstractOperation;
                  import mx.rpc.remoting.Operation;
                  import mx.rpc.remoting.mxml.RemoteObject;
                 
                  use namespace mx_internal;

               

                  public dynamic class MyRemoteObject extends RemoteObject
                  {
                      public function MyRemoteObject(destination:String=null)
                      {
                          super(destination);
                      }

               

                      override public function getOperation(name:String):AbstractOperation
                      {
                          var o:Operation = operations[name];
                          var op:AbstractOperation = (o is AbstractOperation) ? AbstractOperation(o) : null;
                          if (op == null)
                          {
                              op=new MyOperation(this, name);
                              operations[name]=op;
                              op.asyncRequest=asyncRequest;
                          }
                          return op;
                      }
                 
                  }
              }

               

              The rest of your application must use MyRemoteObject, instead of RemoteObject.

               


              • 4. Re: passing information back via the header
                jonas345 Level 1

                Marc,

                 

                Thanks for your reply. I ended up rewriting our security to not rely on

                header information but this will come handy for future iterations.

                 

                Regards,

                Jonas

                • 5. Re: passing information back via the header
                  leftie friele Level 1

                  I am trying to add AMF headers to all my RemoteObject calls,  however my solution does only seem to work the first time I call the method. After that my cusomt AMF headers are gone.

                  I have tried to add them to the AsynchToken's message property which has a headers array on it. I have also tried to listen for the InvokeEvent on RemoteObject in order to add the headers there, but they aren't added the second time I call the method...

                  I am not able to figure out what the problem is...

                   

                  I've tried to use the code in this thread, but it does not compile on SDK 3.5