flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [5/5] git commit: [flex-asjs] [refs/heads/feature/amf] - refactor RemoteObject and Operation to use AMFNetConnection
Date Fri, 01 Sep 2017 18:19:00 GMT
refactor RemoteObject and Operation to use AMFNetConnection


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/0a7f3df5
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/0a7f3df5
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/0a7f3df5

Branch: refs/heads/feature/amf
Commit: 0a7f3df5f8a5b12a97c766f9efee3a40b634e56f
Parents: 09c90ba
Author: Alex Harui <aharui@apache.org>
Authored: Fri Sep 1 11:18:12 2017 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Sep 1 11:18:12 2017 -0700

----------------------------------------------------------------------
 .../flex/org/apache/flex/net/RemoteObject.as    | 168 ++-----------------
 .../org/apache/flex/net/remoting/Operation.as   |  75 ++-------
 2 files changed, 31 insertions(+), 212 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/0a7f3df5/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as
b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as
index ee8ef28..7ba349f 100755
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/RemoteObject.as
@@ -18,17 +18,6 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.net
 {
-    COMPILE::SWF
-    {
-        import flash.events.AsyncErrorEvent;
-        import flash.events.IOErrorEvent;
-        import flash.events.NetStatusEvent;
-        import flash.events.SecurityErrorEvent;
-        import flash.net.NetConnection;
-        import flash.net.Responder;
-        import flash.net.ObjectEncoding;
-    }
-        
     
     import org.apache.flex.core.IBead;
     import org.apache.flex.core.IStrand;
@@ -36,6 +25,7 @@ package org.apache.flex.net
     import org.apache.flex.net.events.FaultEvent;
     import org.apache.flex.net.events.ResultEvent;
     import org.apache.flex.net.remoting.Operation;
+    import org.apache.flex.net.remoting.amf.AMFNetConnection;
     import org.apache.flex.reflection.getClassByAlias;
     import org.apache.flex.reflection.registerClassAlias;
 
@@ -46,6 +36,12 @@ package org.apache.flex.net
 		private var _endPoint:String;
 		private var _destination:String;
 		private var _source:String;
+        
+        /**
+         *  @private
+         *  The connection to the server 
+         */
+        public var nc:AMFNetConnection = new AMFNetConnection();
 		
 		/** 
 		 * 
@@ -55,12 +51,6 @@ package org.apache.flex.net
 		 */ 
 		public function RemoteObject()
 		{
-            COMPILE::SWF
-            {
-                nc = new NetConnection();
-                nc.objectEncoding = ObjectEncoding.AMF3;
-                nc.client = this;
-            }
 		}
 		
         private var _strand:IStrand;
@@ -70,9 +60,6 @@ package org.apache.flex.net
             _strand = value;	
         }
         
-        COMPILE::SWF
-        public var nc:NetConnection;
-        
 		public function set endPoint(value:String):void
 		{
 			_endPoint = value;	
@@ -102,147 +89,20 @@ package org.apache.flex.net
 		
 		public function send(operation:String, params:Array):void
 		{
-            COMPILE::SWF
-            {
-                nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
-                nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
-                nc.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
-                nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
-                nc.connect(endPoint);
-                
-                var op:Operation = new Operation(operation, this, params);
-                op.send();
-            }
-			COMPILE::JS
-			{				
-				var amfClient:Object = new ((window as Object).amf).Client(_destination, _endPoint);
-				var amfReq:Object = amfClient.invoke(_source, operation, params[0]);
-				amfReq.then(resultHandler , faultHandler);
-			}
+            nc.connect(endPoint);
+            
+            var op:Operation = new Operation(operation, this, params);
+            op.send();
 		}
 		
-        COMPILE::SWF
-        private function statusHandler(event:NetStatusEvent):void
-        {
-            trace("statusHandler", event.info.code);
-        }
-        
-        COMPILE::SWF
-        private function securityErrorHandler(event:SecurityErrorEvent):void
-        {
-            trace("securityErrorHandler", event);
-        }
-        
-        COMPILE::SWF
-        private function ioErrorHandler(event:IOErrorEvent):void
-        {
-            trace("ioErrorHandler", event);
-        }
-        
-        COMPILE::SWF
-        private function asyncErrorHandler(event:AsyncErrorEvent):void
-        {
-            trace("asyncErrorHandler", event);
-        }
-        
 		public function resultHandler(param:Object):void
 		{
-            COMPILE::JS
-            {
-    			if(param is Object && param.hasOwnProperty("_explicitType"))
-    			{
-    				param = typeUntypedObject(param);
-    			}
-    			else if (param is Array && param.length > 0)
-    			{
-    				for(var i:uint ; i < param.length ; i++)
-    				{
-    					var typedObj:Object = typeUntypedObject(param[i]);
-    					param[i] = typedObj;
-    				}
-    			}
-                dispatchEvent(new ResultEvent(ResultEvent.RESULT,param));
-            }
-            COMPILE::SWF
-            {
-    			dispatchEvent(new ResultEvent(ResultEvent.RESULT,param.body));
-            }
+    		dispatchEvent(new ResultEvent(ResultEvent.RESULT, param.body));
 		}
 		
 		public function faultHandler(param:Object):void
 		{
-			dispatchEvent(new FaultEvent(FaultEvent.FAULT,param));
-		}
-		
-        COMPILE::JS
-		private function typeUntypedObject(unTypeObject:Object):Object
-		{
-			registerClassAlias(unTypeObject['_explicitType'],getClassByAlias(unTypeObject['_explicitType']));
-			
-			var classToInstantiate:Class = getClassByAlias(unTypeObject['_explicitType']); 
-			
-			var typedInstance:Object = new classToInstantiate(); 
-			
-			for (var field:String in unTypeObject) 
-			{ 
-				if (field == "_explicitType") continue; //Do nothing incase of "_explicitType"
-				
-				typedInstance[field] = unTypeObject[field]; 
-			}
-
-			return  typedInstance;
-		}
-                
-        /**
-         *  @private
-         *  Special handler for legacy AMF packet level header "AppendToGatewayUrl".
-         *  When we receive this header we assume the server detected that a session was
-         *  created but it believed the client could not accept its session cookie, so we
-         *  need to decorate the channel endpoint with the session id.
-         *
-         *  We do not modify the underlying endpoint property, however, as this session
-         *  is transient and should not apply if the channel is disconnected and re-connected
-         *  at some point in the future.
-         */
-        COMPILE::SWF
-        public function AppendToGatewayUrl(value:String):void
-        {
-            if (value != null && value != "")
-            {
-                nc.removeEventListener(NetStatusEvent.NET_STATUS, statusHandler);
-                trace("disconnecting because AppendToGatewayUrl called");
-                nc.close();
-                trace("disconnecting returned from close()");
-                var url:String = endPoint;
-                // WSRP support - append any extra stuff on the wsrp-url, not the actual
url.
-                
-                // Do we have a wsrp-url?
-                var i:int = url.indexOf("wsrp-url=");
-                if (i != -1)
-                {
-                    // Extract the wsrp-url in to a string which will get the
-                    // extra info appended to it
-                    var temp:String = url.substr(i + 9, url.length);
-                    var j:int = temp.indexOf("&");
-                    if (j != -1)
-                    {
-                        temp = temp.substr(0, j);
-                    }
-                    
-                    // Replace the wsrp-url with a version that has the extra stuff
-                    url = url.replace(temp, temp + value);
-                }
-                else
-                {
-                    // If we didn't find a wsrp-url, just append the info
-                    url += value;
-                }
-                nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
-                trace("reconnecting with " + url);
-                nc.connect(url);
-                trace("reconnecting returned from connect()");
-            }
-        }
-
+			dispatchEvent(new FaultEvent(FaultEvent.FAULT, param));
+		}		
 	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/0a7f3df5/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as
b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as
index 1110a46..989db30 100755
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/remoting/Operation.as
@@ -18,18 +18,10 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.net.remoting
 {
-    COMPILE::SWF
-    {
-        import flash.events.AsyncErrorEvent;
-        import flash.events.IOErrorEvent;
-        import flash.events.NetStatusEvent;
-        import flash.events.SecurityErrorEvent;
-        import flash.net.Responder;
-    }
-        
-        
     import org.apache.flex.events.EventDispatcher;
     import org.apache.flex.net.RemoteObject;
+    import org.apache.flex.net.Responder;
+    import org.apache.flex.net.remoting.messages.AcknowledgeMessage;
     import org.apache.flex.net.remoting.messages.CommandMessage;
     import org.apache.flex.net.remoting.messages.RemotingMessage;
     import org.apache.flex.net.events.FaultEvent;
@@ -53,58 +45,25 @@ package org.apache.flex.net.remoting
 		
 		public function send():void
 		{
-            COMPILE::SWF
-            {
-                _ro.nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
-                _ro.nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
-                _ro.nc.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
-                _ro.nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
-                var connectMessage:CommandMessage = new CommandMessage();
-                connectMessage.destination = _ro.destination;
-                connectMessage.operation = CommandMessage.TRIGGER_CONNECT_OPERATION;
-                _ro.nc.call(null, new Responder(destinationResultHandler, destinationFaultHandler),
connectMessage);
-            }
-			COMPILE::JS
-			{				
-				var amfClient:Object = new ((window as Object).amf).Client(_destination, _endPoint);
-				var amfReq:Object = amfClient.invoke(_source, operation, params[0]);
-				amfReq.then(resultHandler , faultHandler);
-			}
+            var connectMessage:CommandMessage = new CommandMessage();
+            connectMessage.destination = _ro.destination;
+            connectMessage.operation = CommandMessage.TRIGGER_CONNECT_OPERATION;
+            _ro.nc.call(null, new Responder(destinationResultHandler, destinationFaultHandler),
connectMessage);
 		}
 		
-        COMPILE::SWF
-        private function statusHandler(event:NetStatusEvent):void
-        {
-            trace("statusHandler", event);
-        }
-        
-        COMPILE::SWF
-        private function securityErrorHandler(event:SecurityErrorEvent):void
-        {
-            trace("securityErrorHandler", event);
-        }
-        
-        COMPILE::SWF
-        private function ioErrorHandler(event:IOErrorEvent):void
-        {
-            trace("ioErrorHandler", event);
-        }
-        
-        COMPILE::SWF
-        private function asyncErrorHandler(event:AsyncErrorEvent):void
-        {
-            trace("asyncErrorHandler", event);
-        }
-        
         private function destinationResultHandler(param:Object):void
         {
-            var message:RemotingMessage = new RemotingMessage();
-            message.operation = _name;
-            message.body = _args;
-            message.source = _ro.source;
-            message.destination = _ro.destination;
-            _ro.nc.call(null, new Responder(_ro.resultHandler, _ro.faultHandler), message);
-
+            if (param is AcknowledgeMessage) // this force links AcknowledgeMessage so it
deserializes correctly in JS
+            {
+                var message:RemotingMessage = new RemotingMessage();
+                message.operation = _name;
+                message.body = _args;
+                message.source = _ro.source;
+                message.destination = _ro.destination;
+                _ro.nc.call(null, new Responder(_ro.resultHandler, _ro.faultHandler), message);
+            }
+            else
+                trace("destination result handler", param);            
         }
             
         private function destinationFaultHandler(param:Object):void


Mime
View raw message