Guest User

Untitled

a guest
Aug 10th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Set properties
  2.             public var baseURL:String = new String();
  3.             private var sessionID:String;
  4.            
  5.             /******************************************
  6.              *
  7.              *  Method for processing HTTP Requests
  8.              *  to the docSTAR server.
  9.              *
  10.              * ***************************************/
  11.             private function processRequest(targetURL:String, targetMethod:String,
  12.                                             successListner:Function, failListner:Function = null):void
  13.             {
  14.                 //Create a new HTTP service to connect to the docSTAR server.
  15.                 var currentHS:mx.rpc.http.HTTPService= new mx.rpc.http.mxml.HTTPService;
  16.                
  17.                 //Set the properties of the service
  18.                 currentHS.url = targetURL;
  19.                 currentHS.method = targetMethod;
  20.                
  21.                 //Set the cursor to busy
  22.                 cursorManager.setBusyCursor();
  23.                
  24.                 //Send the service and then listen for completion
  25.                 currentHS.send();
  26.                 currentHS.addEventListener("result", successListner);
  27.                
  28.                 //If a failListner was passed attach it to the http service
  29.                 //If one was not passed, ignor this.
  30.                 if(failListner != null)
  31.                     currentHS.addEventListener("fault", failListner);
  32.             }
  33.            
  34.             /******************************************
  35.              *
  36.              *  Method for general HTTP Request
  37.              * failures.
  38.              *
  39.              * ***************************************/
  40.             private function generalHTTPFailure():void
  41.             {
  42.                 //A general error message to the user.
  43.                 Alert.show("There was an error in your request");
  44.             }
  45.            
  46.             /******************************************
  47.              *
  48.              *  Method for retrieving a session ID.
  49.              *  A session ID is used by almost all
  50.              *  other methods.
  51.              *
  52.              * ***************************************/
  53.             private function retrieveSessionID():void
  54.             {
  55.                 //Create and generate  a string containing
  56.                 //a url of the location of the docSTAR server's
  57.                 //REST endpoint for connecting.
  58.                 var targetURL:String = baseURL + 'systemservice.svc/rest/connect';
  59.                
  60.                 //Call the process request method and pass it the target URl and function cointaining
  61.                 //instructions on what to do with the resulting XML from docSTAR
  62.                 processRequest(targetURL,"GET",function(passedEvent:ResultEvent):void
  63.                 {
  64.                     //Process the returned XML file and set the seesionID accordingly
  65.                     sessionID = passedEvent.result.ConnectResponse.ConnectResult;
  66.                     sessionIDLB.text = sessionID;
  67.                    
  68.                     //Set cursor back to normal
  69.                     cursorManager.removeBusyCursor();
  70.                 },generalHTTPFailure);
  71.             }
Add Comment
Please, Sign In to add comment