Quick Start: Invoking a service using Java proxy files and Base64 encoding

The following Java code example invokes a process named MyApplication/EncryptDocument using Java proxy files created using JAX-WS and Base64 encoding. (See Invoking LiveCycle using Base64 encoding.)

An unsecured PDF document based on a PDF file named Loan.pdf is passed to the AEM Forms process. The process returns a password-encrypted PDF document that is saved as a PDF file named EncryptedDocument.pdf .

/** 
    * Ensure that you create Java proxy files that consume 
    * the the LiveCycle service WSDL. You can use JAX-WS to create 
    * the Java proxy files.   
    *    
    * This Java quick start uses Base64 to invoke a short-lived process named 
    * EncryptDocument. For information, see  
    * "Invoking LiveCycle using Base64" in Programming with AEM forms.   
    */ 
 
import java.io.*; 
 
import javax.xml.ws.BindingProvider; 
import com.adobe.idp.services.*; 
 
public class InvokeEncryptDocumentBase64 { 
    public static void main(String[] args){ 
         
        try{ 
            //Create a MyApplicationEncryptDocument object 
            MyApplicationEncryptDocumentService encClient = new MyApplicationEncryptDocumentService(); 
            MyApplicationEncryptDocument encryptDocClient = encClient.getEncryptDocument(); 
             
            //Set connection values required to invoke LiveCycle 
            String url = "[server]:[port]/soap/services/MyApplication/EncryptDocument?blob=base64"; 
            String username = "administrator"; 
            String password = "password"; 
            ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
            ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
            ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
             
               // Get the input PDF document to send to the EncryptDocument process 
               BLOB inDoc = new BLOB(); 
             
            // Get the input DDX document and input PDF sources 
            File fileName = new File("C:\\Adobe\Loan.pdf"); 
            FileInputStream inFs = new FileInputStream(fileName);  
                         
            // Get the length of the file stream and create a byte array 
            int inLen = (int)fileName.length(); 
            byte[] inByteArray = new byte[inLen]; 
             
               // Populate the byte array with the content of the file stream 
            inFs.read(inByteArray, 0, inLen); 
                  
               // Populate the BLOB objects 
            inDoc.setBinaryData(inByteArray); 
             
               //invoke the short-lived process named MyApplication/EncryptDocument 
            BLOB outDoc = encryptDocClient.invoke(inDoc); 
             
            //Save the encrypted file as a PDF file 
            byte[] encryptedDocument = outDoc.getBinaryData(); 
             
            //Create a File object 
            File outFile = new File("C:\\Adobe\EncryptedDocument.pdf"); 
             
            //Create a FileOutputStream object. 
            FileOutputStream myFileW = new FileOutputStream(outFile); 
             
            //Call the FileOutputStream object's write method and pass the pdf data 
            myFileW.write(encryptedDocument); 
             
            //Close the FileOutputStream object 
            myFileW.close(); 
               System.out.println("The short-lived process named MyApplication/EncryptDocument was successfully invoked.");             
        } 
        catch(Exception e) 
        { 
            e.printStackTrace(); 
        } 
     
    } 
 
} 
 

// Ethnio survey code removed