aharui commented on a change in pull request #317: Service classes emulated
URL: https://github.com/apache/royale-asjs/pull/317#discussion_r225711154
 
 

 ##########
 File path: 
frameworks/projects/MXRoyale/src/main/royale/mx/messaging/channels/DirectHTTPChannel.as
 ##########
 @@ -0,0 +1,675 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package mx.messaging.channels
+{
+       COMPILE::SWF
+       {
+               import flash.events.Event;
+               import flash.events.IOErrorEvent;
+               import flash.events.SecurityErrorEvent;
+               import flash.events.ErrorEvent;
+               import flash.events.TimerEvent;
+               import flash.net.URLLoader;
+               import flash.net.URLRequest;
+               import flash.net.URLRequestHeader;
+               import flash.net.URLVariables;
+               import flash.events.HTTPStatusEvent;
+       }
+       
+       COMPILE::JS
+       {
+               import org.apache.royale.events.Event;
+               import mx.events.IOErrorEvent;
+               import mx.events.ErrorEvent;
+               import mx.events.SecurityErrorEvent;
+               import org.apache.royale.events.EventDispatcher;
+               import org.apache.royale.net.URLLoader;
+               import org.apache.royale.net.URLRequest;
+               import org.apache.royale.net.URLRequestHeader;
+               import mx.events.HTTPStatusEvent;       
+       }
+       
+       import mx.core.mx_internal;
+       import mx.messaging.Channel;
+       import mx.messaging.MessageAgent;
+       import mx.messaging.MessageResponder;
+       import mx.messaging.errors.ChannelError;
+       import mx.messaging.errors.InvalidChannelError;
+       import mx.messaging.errors.MessageSerializationError;
+       import mx.messaging.messages.AcknowledgeMessage;
+       import mx.messaging.messages.ErrorMessage;
+       import mx.messaging.messages.HTTPRequestMessage;
+       import mx.messaging.messages.IMessage;
+       import mx.messaging.config.LoaderConfig;
+       import mx.netmon.NetworkMonitor;
+       import mx.resources.IResourceManager;
+       import mx.resources.ResourceManager;
+       
+       use namespace mx_internal;
+       
+       [ResourceBundle("messaging")]
+       
+       [ExcludeClass]
+       
+       /**
+        *  @private
+        *  The DirectHTTPChannel class is used to turn an HTTPRequestMessage 
object into an
+        *  HTTP request.
+        *  This Channel does not connect to a Flex endpoint.
+        */
+       public class DirectHTTPChannel extends Channel
+       {
+               /**
+                *  Constructs an instance of a DirectHTTPChannel.
+                *  The parameters are not used.
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 9
+                *  @playerversion AIR 1.1
+                *  @productversion BlazeDS 4
+                *  @productversion LCDS 3 
+                */
+               public function DirectHTTPChannel(id:String, uri:String="")
+               {
+                       super(id, uri);
+                       if (uri.length > 0)
+                       {
+                               var message:String = resourceManager.getString(
+                                       "messaging", "noURIAllowed");
+                               throw new InvalidChannelError(message);
+                       }
+                       clientId = ("DirectHTTPChannel" + clientCounter++);
+               }
+               
+               /**
+                * @private
+                * Used by DirectHTTPMessageResponder to specify a dummy 
clientId for AcknowledgeMessages.
+                * Each instance of this channel gets a new clientId.
+                */ 
+               mx_internal var clientId:String;
+               
+               /**
+                *  @private
+                */
+               private var resourceManager:IResourceManager =
+                       ResourceManager.getInstance();
+               
+               /**
+                *  Indicates if this channel is connected.
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 9
+                *  @playerversion AIR 1.1
+                *  @productversion BlazeDS 4
+                *  @productversion LCDS 3 
+                */
+               override public function get connected():Boolean
+               {
+                       return true;
+               }
+               
+               /**
+                *  Indicates the protocol used by this channel.
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 9
+                *  @playerversion AIR 1.1
+                *  @productversion BlazeDS 4
+                *  @productversion LCDS 3 
+                */
+               override public function get protocol():String
+               {
+                       return "http";     
+               }
+               
+               //----------------------------------
+               //  realtime
+               //----------------------------------
+               
+               /**
+                *  @private
+                *  Returns true if the channel supports realtime behavior via 
server push or client poll.
+                */
+               override mx_internal function get realtime():Boolean
+               {
+                       return false;
+               }    
+               
+               /**
+                *  @private
+                *  Because this channel is always "connected", we ignore any 
connect timeout
+                *  that is reported.
+                */
+               /*COMPILE::SWF
+               override protected function 
connectTimeoutHandler(event:TimerEvent):void
+               {
+                       // Ignore.
+               }
+               
+               COMPILE::JS
+               override protected function 
connectTimeoutHandler(event:EventDispatcher):void
+               {
+                       // Ignore.
+               }*/
+
+               /**
+                *  Returns the appropriate MessageResponder for the Channel.
+                *
+                *  @param agent The MessageAgent sending the message.
+                * 
+                *  @param message The IMessage to send.
+                * 
+                *  @return The MessageResponder to handle the send result or 
fault.
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 9
+                *  @playerversion AIR 1.1
+                *  @productversion BlazeDS 4
+                *  @productversion LCDS 3 
+                */
+               COMPILE::SWF
+               override protected function 
getMessageResponder(agent:MessageAgent, 
+                                                                               
                                message:IMessage):MessageResponder
+               {
+                       return new DirectHTTPMessageResponder(agent, message, 
this, new flash.net.URLLoader());
 
 Review comment:
   I think this can be:
   
   return new DirectHTTPMessageResponder(agent, message, this, new URLLoader());
   
   And then you don't need a separate version for COMPILE::JS

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to