home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Darbas / kidoz_v1.air / kidoz.swf / scripts / mx / rpc / soap / WebService.as < prev   
Encoding:
Text File  |  2009-05-06  |  7.5 KB  |  233 lines

  1. package mx.rpc.soap
  2. {
  3.    import mx.core.mx_internal;
  4.    import mx.logging.ILogger;
  5.    import mx.logging.Log;
  6.    import mx.resources.IResourceManager;
  7.    import mx.resources.ResourceManager;
  8.    import mx.rpc.AbstractOperation;
  9.    import mx.rpc.Fault;
  10.    import mx.rpc.events.FaultEvent;
  11.    import mx.rpc.events.WSDLLoadEvent;
  12.    import mx.rpc.http.HTTPService;
  13.    import mx.rpc.wsdl.WSDL;
  14.    import mx.rpc.wsdl.WSDLLoader;
  15.    import mx.rpc.wsdl.WSDLOperation;
  16.    import mx.rpc.wsdl.WSDLPort;
  17.    import mx.utils.URLUtil;
  18.    
  19.    use namespace mx_internal;
  20.    
  21.    public dynamic class WebService extends AbstractWebService
  22.    {
  23.       public static const DEFAULT_DESTINATION_HTTP:String = "DefaultHTTP";
  24.       
  25.       public static const DEFAULT_DESTINATION_HTTPS:String = "DefaultHTTPS";
  26.       
  27.       private var _wsdlFault:Boolean;
  28.       
  29.       private var _wsdl:WSDL;
  30.       
  31.       private var _wsdlURL:String;
  32.       
  33.       private var _log:ILogger;
  34.       
  35.       private var _wsdlLoader:WSDLLoader;
  36.       
  37.       private var resourceManager:IResourceManager = ResourceManager.getInstance();
  38.       
  39.       public function WebService(param1:String = null, param2:String = null)
  40.       {
  41.          super(param1,param2);
  42.          _ready = false;
  43.          _log = Log.getLogger("mx.rpc.soap.WebService");
  44.       }
  45.       
  46.       public function get wsdl() : String
  47.       {
  48.          return _wsdlURL;
  49.       }
  50.       
  51.       mx_internal function get wsdlFault() : Boolean
  52.       {
  53.          return _wsdlFault;
  54.       }
  55.       
  56.       mx_internal function wsdlHandler(param1:WSDLLoadEvent) : void
  57.       {
  58.          var wsdlPort:WSDLPort = null;
  59.          var op:Operation = null;
  60.          var loadEvent:LoadEvent = null;
  61.          var faultEvent:FaultEvent = null;
  62.          var errorMessage:String = null;
  63.          var message:String = null;
  64.          var fault:Fault = null;
  65.          var faultEvent2:FaultEvent = null;
  66.          var event:WSDLLoadEvent = param1;
  67.          _log.debug("WSDL loaded");
  68.          _wsdl = event.wsdl;
  69.          try
  70.          {
  71.             wsdlPort = _wsdl.getPort(service,port);
  72.             _endpointURI = wsdlPort.endpointURI;
  73.             if(!URLUtil.isHttpURL(_endpointURI) && event.location != null)
  74.             {
  75.                _endpointURI = URLUtil.getFullURL(event.location,_endpointURI);
  76.             }
  77.             _service = wsdlPort.service.name;
  78.             _port = wsdlPort.name;
  79.             for each(op in mx_internal::_operations)
  80.             {
  81.                initializeOperation(op);
  82.             }
  83.             _ready = true;
  84.             loadEvent = LoadEvent.createEvent(event.wsdl,event.location);
  85.             dispatchEvent(loadEvent);
  86.             unEnqueueCalls();
  87.          }
  88.          catch(fault:Fault)
  89.          {
  90.             faultEvent = FaultEvent.createEvent(fault);
  91.             dispatchEvent(faultEvent);
  92.             super.unEnqueueCalls(fault);
  93.             return;
  94.          }
  95.          catch(error:Error)
  96.          {
  97.             errorMessage = !!error.message ? error.message : "";
  98.             message = resourceManager.getString("rpc","unexpectedException",[errorMessage]);
  99.             fault = new Fault("WSDLError",message);
  100.             fault.rootCause = error;
  101.             faultEvent2 = FaultEvent.createEvent(fault);
  102.             dispatchEvent(faultEvent2);
  103.             super.unEnqueueCalls(fault);
  104.             return;
  105.          }
  106.       }
  107.       
  108.       public function set wsdl(param1:String) : void
  109.       {
  110.          _wsdlURL = param1;
  111.       }
  112.       
  113.       public function loadWSDL(param1:String = null) : void
  114.       {
  115.          var _loc2_:String = null;
  116.          var _loc3_:Fault = null;
  117.          var _loc4_:Fault = null;
  118.          if(param1 != null)
  119.          {
  120.             wsdl = param1;
  121.          }
  122.          if(!wsdl)
  123.          {
  124.             if(!useProxy)
  125.             {
  126.                _loc2_ = resourceManager.getString("rpc","mustSpecifyWSDLLocation");
  127.                _loc3_ = new Fault("Client.WSDL",_loc2_);
  128.                dispatchEvent(FaultEvent.createEvent(_loc3_));
  129.                return;
  130.             }
  131.             if(destination == null || !destinationSet || destination == DEFAULT_DESTINATION_HTTP || destination == DEFAULT_DESTINATION_HTTPS)
  132.             {
  133.                _loc2_ = resourceManager.getString("rpc","destinationOrWSDLNotSpecified");
  134.                _loc4_ = new Fault("Client.WSDL",_loc2_);
  135.                dispatchEvent(FaultEvent.createEvent(_loc4_));
  136.                return;
  137.             }
  138.          }
  139.          if(!destinationSet && URLUtil.isHttpsURL(wsdl))
  140.          {
  141.             mx_internal::asyncRequest.destination = DEFAULT_DESTINATION_HTTPS;
  142.             destinationSet = true;
  143.          }
  144.          _wsdlLoader = new WSDLLoader(mx_internal::deriveHTTPService());
  145.          _wsdlLoader.addEventListener(WSDLLoadEvent.LOAD,mx_internal::wsdlHandler);
  146.          _wsdlLoader.addEventListener(FaultEvent.FAULT,mx_internal::wsdlFaultHandler);
  147.          _wsdlFault = false;
  148.          _wsdlLoader.load(wsdl);
  149.       }
  150.       
  151.       mx_internal function wsdlFaultHandler(param1:FaultEvent) : void
  152.       {
  153.          _wsdlFault = true;
  154.          dispatchEvent(param1);
  155.          unEnqueueCalls(param1.fault);
  156.       }
  157.       
  158.       mx_internal function deriveHTTPService() : HTTPService
  159.       {
  160.          var _loc1_:HTTPService = new HTTPService();
  161.          _loc1_.mx_internal::asyncRequest = mx_internal::asyncRequest;
  162.          if(destination)
  163.          {
  164.             _loc1_.destination = destination;
  165.          }
  166.          _loc1_.useProxy = useProxy;
  167.          _loc1_.resultFormat = HTTPService.RESULT_FORMAT_XML;
  168.          _loc1_.rootURL = rootURL;
  169.          _loc1_.headers = httpHeaders;
  170.          return _loc1_;
  171.       }
  172.       
  173.       private function dispatchFault(param1:String, param2:String, param3:String = null) : void
  174.       {
  175.          var _loc4_:Fault = new Fault(param1,param2,param3);
  176.          var _loc5_:FaultEvent = FaultEvent.createEvent(_loc4_);
  177.          dispatchEvent(_loc5_);
  178.       }
  179.       
  180.       override public function getOperation(param1:String) : AbstractOperation
  181.       {
  182.          var _loc2_:AbstractOperation = super.getOperation(param1);
  183.          if(_loc2_ == null)
  184.          {
  185.             _loc2_ = new Operation(this,param1);
  186.             mx_internal::_operations[param1] = _loc2_;
  187.             _loc2_.mx_internal::asyncRequest = mx_internal::asyncRequest;
  188.             initializeOperation(_loc2_ as Operation);
  189.          }
  190.          return _loc2_;
  191.       }
  192.       
  193.       protected function initializeOperation(param1:Operation) : void
  194.       {
  195.          var _loc2_:WSDLOperation = null;
  196.          if(_wsdl != null)
  197.          {
  198.             _loc2_ = _wsdl.getOperation(param1.name,service,port);
  199.             if(param1.endpointURI == null)
  200.             {
  201.                param1.endpointURI = endpointURI;
  202.             }
  203.             param1.mx_internal::wsdlOperation = _loc2_;
  204.          }
  205.       }
  206.       
  207.       public function canLoadWSDL() : Boolean
  208.       {
  209.          if(wsdl)
  210.          {
  211.             return true;
  212.          }
  213.          if(destination != DEFAULT_DESTINATION_HTTP && destination != DEFAULT_DESTINATION_HTTPS)
  214.          {
  215.             return true;
  216.          }
  217.          return false;
  218.       }
  219.       
  220.       public function toString() : String
  221.       {
  222.          var _loc1_:String = "[WebService ";
  223.          _loc1_ += " destination=\"" + destination + "\"";
  224.          if(wsdl)
  225.          {
  226.             _loc1_ += " wsdl=\"" + wsdl + "\"";
  227.          }
  228.          return _loc1_ + (" channelSet=\"" + channelSet + "\"]");
  229.       }
  230.    }
  231. }
  232.  
  233.