home *** CD-ROM | disk | FTP | other *** search
- package mx.rpc.soap
- {
- import mx.core.mx_internal;
- import mx.logging.ILogger;
- import mx.logging.Log;
- import mx.resources.IResourceManager;
- import mx.resources.ResourceManager;
- import mx.rpc.AbstractOperation;
- import mx.rpc.Fault;
- import mx.rpc.events.FaultEvent;
- import mx.rpc.events.WSDLLoadEvent;
- import mx.rpc.http.HTTPService;
- import mx.rpc.wsdl.WSDL;
- import mx.rpc.wsdl.WSDLLoader;
- import mx.rpc.wsdl.WSDLOperation;
- import mx.rpc.wsdl.WSDLPort;
- import mx.utils.URLUtil;
-
- use namespace mx_internal;
-
- public dynamic class WebService extends AbstractWebService
- {
- public static const DEFAULT_DESTINATION_HTTP:String = "DefaultHTTP";
-
- public static const DEFAULT_DESTINATION_HTTPS:String = "DefaultHTTPS";
-
- private var _wsdlFault:Boolean;
-
- private var _wsdl:WSDL;
-
- private var _wsdlURL:String;
-
- private var _log:ILogger;
-
- private var _wsdlLoader:WSDLLoader;
-
- private var resourceManager:IResourceManager = ResourceManager.getInstance();
-
- public function WebService(param1:String = null, param2:String = null)
- {
- super(param1,param2);
- _ready = false;
- _log = Log.getLogger("mx.rpc.soap.WebService");
- }
-
- public function get wsdl() : String
- {
- return _wsdlURL;
- }
-
- mx_internal function get wsdlFault() : Boolean
- {
- return _wsdlFault;
- }
-
- mx_internal function wsdlHandler(param1:WSDLLoadEvent) : void
- {
- var wsdlPort:WSDLPort = null;
- var op:Operation = null;
- var loadEvent:LoadEvent = null;
- var faultEvent:FaultEvent = null;
- var errorMessage:String = null;
- var message:String = null;
- var fault:Fault = null;
- var faultEvent2:FaultEvent = null;
- var event:WSDLLoadEvent = param1;
- _log.debug("WSDL loaded");
- _wsdl = event.wsdl;
- try
- {
- wsdlPort = _wsdl.getPort(service,port);
- _endpointURI = wsdlPort.endpointURI;
- if(!URLUtil.isHttpURL(_endpointURI) && event.location != null)
- {
- _endpointURI = URLUtil.getFullURL(event.location,_endpointURI);
- }
- _service = wsdlPort.service.name;
- _port = wsdlPort.name;
- for each(op in mx_internal::_operations)
- {
- initializeOperation(op);
- }
- _ready = true;
- loadEvent = LoadEvent.createEvent(event.wsdl,event.location);
- dispatchEvent(loadEvent);
- unEnqueueCalls();
- }
- catch(fault:Fault)
- {
- faultEvent = FaultEvent.createEvent(fault);
- dispatchEvent(faultEvent);
- super.unEnqueueCalls(fault);
- return;
- }
- catch(error:Error)
- {
- errorMessage = !!error.message ? error.message : "";
- message = resourceManager.getString("rpc","unexpectedException",[errorMessage]);
- fault = new Fault("WSDLError",message);
- fault.rootCause = error;
- faultEvent2 = FaultEvent.createEvent(fault);
- dispatchEvent(faultEvent2);
- super.unEnqueueCalls(fault);
- return;
- }
- }
-
- public function set wsdl(param1:String) : void
- {
- _wsdlURL = param1;
- }
-
- public function loadWSDL(param1:String = null) : void
- {
- var _loc2_:String = null;
- var _loc3_:Fault = null;
- var _loc4_:Fault = null;
- if(param1 != null)
- {
- wsdl = param1;
- }
- if(!wsdl)
- {
- if(!useProxy)
- {
- _loc2_ = resourceManager.getString("rpc","mustSpecifyWSDLLocation");
- _loc3_ = new Fault("Client.WSDL",_loc2_);
- dispatchEvent(FaultEvent.createEvent(_loc3_));
- return;
- }
- if(destination == null || !destinationSet || destination == DEFAULT_DESTINATION_HTTP || destination == DEFAULT_DESTINATION_HTTPS)
- {
- _loc2_ = resourceManager.getString("rpc","destinationOrWSDLNotSpecified");
- _loc4_ = new Fault("Client.WSDL",_loc2_);
- dispatchEvent(FaultEvent.createEvent(_loc4_));
- return;
- }
- }
- if(!destinationSet && URLUtil.isHttpsURL(wsdl))
- {
- mx_internal::asyncRequest.destination = DEFAULT_DESTINATION_HTTPS;
- destinationSet = true;
- }
- _wsdlLoader = new WSDLLoader(mx_internal::deriveHTTPService());
- _wsdlLoader.addEventListener(WSDLLoadEvent.LOAD,mx_internal::wsdlHandler);
- _wsdlLoader.addEventListener(FaultEvent.FAULT,mx_internal::wsdlFaultHandler);
- _wsdlFault = false;
- _wsdlLoader.load(wsdl);
- }
-
- mx_internal function wsdlFaultHandler(param1:FaultEvent) : void
- {
- _wsdlFault = true;
- dispatchEvent(param1);
- unEnqueueCalls(param1.fault);
- }
-
- mx_internal function deriveHTTPService() : HTTPService
- {
- var _loc1_:HTTPService = new HTTPService();
- _loc1_.mx_internal::asyncRequest = mx_internal::asyncRequest;
- if(destination)
- {
- _loc1_.destination = destination;
- }
- _loc1_.useProxy = useProxy;
- _loc1_.resultFormat = HTTPService.RESULT_FORMAT_XML;
- _loc1_.rootURL = rootURL;
- _loc1_.headers = httpHeaders;
- return _loc1_;
- }
-
- private function dispatchFault(param1:String, param2:String, param3:String = null) : void
- {
- var _loc4_:Fault = new Fault(param1,param2,param3);
- var _loc5_:FaultEvent = FaultEvent.createEvent(_loc4_);
- dispatchEvent(_loc5_);
- }
-
- override public function getOperation(param1:String) : AbstractOperation
- {
- var _loc2_:AbstractOperation = super.getOperation(param1);
- if(_loc2_ == null)
- {
- _loc2_ = new Operation(this,param1);
- mx_internal::_operations[param1] = _loc2_;
- _loc2_.mx_internal::asyncRequest = mx_internal::asyncRequest;
- initializeOperation(_loc2_ as Operation);
- }
- return _loc2_;
- }
-
- protected function initializeOperation(param1:Operation) : void
- {
- var _loc2_:WSDLOperation = null;
- if(_wsdl != null)
- {
- _loc2_ = _wsdl.getOperation(param1.name,service,port);
- if(param1.endpointURI == null)
- {
- param1.endpointURI = endpointURI;
- }
- param1.mx_internal::wsdlOperation = _loc2_;
- }
- }
-
- public function canLoadWSDL() : Boolean
- {
- if(wsdl)
- {
- return true;
- }
- if(destination != DEFAULT_DESTINATION_HTTP && destination != DEFAULT_DESTINATION_HTTPS)
- {
- return true;
- }
- return false;
- }
-
- public function toString() : String
- {
- var _loc1_:String = "[WebService ";
- _loc1_ += " destination=\"" + destination + "\"";
- if(wsdl)
- {
- _loc1_ += " wsdl=\"" + wsdl + "\"";
- }
- return _loc1_ + (" channelSet=\"" + channelSet + "\"]");
- }
- }
- }
-
-