Quick Start: Invoking a short-lived process by passing a secure document using Remoting

The following code example invokes the MyApplication/EncryptDocument.A user must login to click the Select File button that is used to upload a PDF file and invoke the process. That is, once the user is authenticated, the Select File button is enabled. The following illustration shows the Flex client application after a user is authenticated. Notice that the Authenticated CheckBox is enabled.

if LiveCycle is configured to only allow secure documents to be uploaded and the user not have the Document Upload Application User role, then an exception is thrown. If the user does have this role, then the file is uploaded and the process is invoked.

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"  
     import mx.rpc.livecycle.DocumentReference; 
     import flash.net.FileReference; 
     import flash.net.URLRequest; 
     import flash.events.Event; 
     import flash.events.DataEvent; 
     import mx.messaging.ChannelSet; 
     import mx.messaging.channels.AMFChannel;   
     import mx.rpc.events.ResultEvent; 
     import mx.collections.ArrayCollection; 
     import mx.rpc.AsyncToken; 
     import mx.controls.Alert; 
     import mx.rpc.events.FaultEvent; 
     import mx.rpc.AsyncResponder; 
     // Classes used in file retrieval   
     private var fileRef:FileReference = new FileReference(); 
     private var docRef:DocumentReference = new DocumentReference(); 
     private var parentResourcePath:String = "/"; 
     private var now1:Date;    
     private var serverPort:String = "hiro-xp:8080"; 
     // Define a ChannelSet object. 
     public var cs:ChannelSet;  
     // Define an AsyncToken object. 
     public var token:AsyncToken; 
      // Holds information returned from LiveCycle  
     public var progressList:ArrayCollection = new ArrayCollection(); 
     // Handles a successful login 
    private function LoginResultEvent(event:ResultEvent, 
        token:Object=null):void  { 
            switch(event.result) { 
                case "success": 
                    authenticatedCB.selected = true; 
                    btnFile.enabled = true; 
                    btnLogout.enabled = true; 
                    btnLogin.enabled = false; 
// Handle login failure. 
private function LoginFaultEvent(event:FaultEvent, 
    token:Object=null):void { 
    switch(event.fault.faultCode) { 
                case "Client.Authentication": 
                        authenticatedCB.selected = false; 
                        Alert.show("Login failure: " + event.fault.faultString); 
     // Set up channel set to invoke LiveCycle  
     private function initializeChannelSet():void { 
       cs = new ChannelSet();  
       cs.addChannel(new AMFChannel("remoting-amf", "http://" + serverPort + "/remoting/messagebroker/amf"));  
       EncryptDocument2.channelSet = cs; 
    // Call this method to upload the file. 
     // This creates a file picker and lets the user select a PDF file to pass to the EncryptDocument process. 
     private function uploadFile():void { 
       fileRef.addEventListener(Event.SELECT, selectHandler); 
     // Gets called for selected file. Does the actual upload via the file upload servlet. 
     private function selectHandler(event:Event):void { 
             var authTokenService:RemoteObject = new RemoteObject("LC.FileUploadAuthenticator"); 
        authTokenService.addEventListener("result", authTokenReceived); 
        authTokenService.channelSet = cs; 
    private function authTokenReceived(event:ResultEvent):void 
    var token:String = event.result as String; 
    var request:URLRequest = DocumentReference.constructRequestForUpload("http://hiro-xp:8080", token); 
    catch (error:Error) 
        trace("Unable to upload file."); 
     // Called once the file is completely uploaded. 
     private function completeHandler(event:DataEvent):void {                     
       // Set the docRef's url and referenceType parameters 
       docRef.url = event.data as String;       
    //This method invokes the EncryptDocument process 
     public function executeInvokeProcess():void { 
        //Create an Object to store the input value for the EncryptDocument process 
          now1 = new Date(); 
        var params:Object = new Object(); 
        // Invoke the EncryptDocument process 
        var token:AsyncToken;             
        token = EncryptDocument2.invoke(params); 
        token.name = name; 
     // LiveCycle  login method 
     private function ROLogin():void { 
        // Make sure that the user is not already logged in. 
        //Get the User and Password 
        var userName:String = txtUser.text; 
        var pass:String = txtPassword.text; 
       if (cs.authenticated == false) { 
            token = cs.login(userName, pass); 
        // Add result and fault handlers. 
        token.addResponder(new AsyncResponder(LoginResultEvent,    LoginFaultEvent)); 
     // This method handles a successful process invocation 
     public function handleResult(event:ResultEvent):void 
           //Retrieve information returned from the service invocation 
         var token:AsyncToken = event.token;         
         var res:Object = event.result; 
         var dr:DocumentReference = res["outDoc"] as DocumentReference; 
         var now2:Date = new Date(); 
          // These fields map to columns in the DataGrid 
         var progObject:Object = new Object(); 
         progObject.filename = token.name; 
         progObject.timing = (now2.time - now1.time).toString(); 
         progObject.state = "Success"; 
         progObject.link = "<a href='" + dr.url + "'> open </a>"; 
     // Prompt user to login on a fault.          
      private function faultHandler(event:FaultEvent):void 
                    event.fault.faultString + "\n" + 
                    event.fault.faultCode + "\n" + 
                    "Please login to continue."); 
      // LiveCycle  logout method 
    private function ROLogout():void { 
        // Add result and fault handlers. 
        token = cs.logout(); 
        token.addResponder(new AsyncResponder(LogoutResultEvent,LogoutFaultEvent)); 
    // Handle successful logout. 
    private function LogoutResultEvent(event:ResultEvent, 
        token:Object=null):void { 
        switch (event.result) { 
        case "success": 
                authenticatedCB.selected = false; 
                btnFile.enabled = false; 
                btnLogout.enabled = false; 
                btnLogin.enabled = true; 
    // Handle logout failure. 
    private function LogoutFaultEvent(event:FaultEvent, 
            token:Object=null):void { 
            Alert.show("Logout failure: " + event.fault.faultString); 
         private function resultHandler(event:ResultEvent):void { 
         // Do anything else here. 
     <mx:RemoteObject id="EncryptDocument" destination="MyApplication/EncryptDocument" result="resultHandler(event);"> 
         <mx:method name="invoke" result="handleResult(event)"/> 
      <!--//This consists of what is displayed on the webpage--> 
     <mx:Panel id="lcPanel" title="EncryptDocument  (Deprecated for AEM forms) LiveCycle Remoting Example"  
          height="25%" width="25%" paddingTop="10" paddingLeft="10" paddingRight="10"  
        <mx:Label width="100%" color="blue" 
               text="Select a PDF file to pass to the EncryptDocument process"/>  
       <mx:DataGrid x="10" y="0" width="500" id="idProgress" editable="false"  
          dataProvider="{progressList}" height="231" selectable="false" > 
           <mx:DataGridColumn headerText="Filename" width="200" dataField="filename" editable="false"/> 
           <mx:DataGridColumn headerText="State" width="75" dataField="state" editable="false"/> 
           <mx:DataGridColumn headerText="Timing" width="75" dataField="timing" editable="false"/> 
           <mx:DataGridColumn headerText="Click to Open" dataField="link" editable="false" > 
                  <mx:Text x="0" y="0" width="100%" htmlText="{data.link}"/> 
       <mx:Button label="Select File" click="uploadFile()"  id="btnFile" enabled="false"/> 
       <mx:Button label="Login" click="ROLogin();" id="btnLogin"/> 
       <mx:Button label="LogOut" click="ROLogout();" enabled="false" id="btnLogout"/> 
        <mx:Label text="User:"/> 
        <mx:TextInput id="txtUser" text=""/> 
        <mx:Label text="Password:"/> 
        <mx:TextInput id="txtPassword" text="" displayAsPassword="true"/> 
        <mx:CheckBox id="authenticatedCB"  

// Ethnio survey code removed