Quick Start (Java SWAref): Determining encryption type using the web service API

The following Java code example determines the type of encryption that is protecting a PDF document named EncryptLoan.pdf. (See Determining Encryption Type.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Encryption services  WSDL. You can use JAX-WS to create 
    * the proxy Java files.   
    *    
    * For information, see "Invoking LiveCycle using SwaRef" in Programming with LiveCycle.   
    */ 
import java.io.*; 
 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
 
import com.adobe.idp.services.*; 
 
public class GetEncryptionTypeSWAref { 
 
    public static void main(String[] args) { 
         
        try{ 
            // Setting configurations to retrieve the Web service 
            String url = "http://hiro-xp:8080/soap/services/EncryptionService?blob=swaRef"; 
            String username = "administrator"; 
            String password = "password"; 
             
            // Create the service Client objects needed 
            EncryptionServiceService encryptionService = new EncryptionServiceService(); 
            EncryptionService encryptionClient = encryptionService.getEncryptionService(); 
             
            // Retrieve the Web services from the LiveCycle Server. 
            ((BindingProvider) encryptionClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
            ((BindingProvider) encryptionClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
            ((BindingProvider) encryptionClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
             
            //Get the PDF document 
            String path1 = "C:\\Adobe\EncryptLoan.pdf"; 
            FileDataSource ds1 = new FileDataSource(path1);  
            DataHandler handler1 = new DataHandler(ds1); 
            BLOB inDoc = new BLOB(); 
            inDoc.setSwaRef(handler1); 
             
            //Determine the type of encryption of the PDF document 
            EncryptionTypeResult encryptTypeResult = encryptionClient.getPDFEncryption(inDoc); 
                         
            if (encryptTypeResult.getEncryptionType() == EncryptionType.PASSWORD) 
                System.out.println("The PDF document is protected with password-based encryption"); 
            else if (encryptTypeResult.getEncryptionType() == EncryptionType.POLICY_SERVER)     
                System.out.println("The PDF document is protected with policy"); 
            else if (encryptTypeResult.getEncryptionType() == EncryptionType.CERTIFICATE)     
                System.out.println("The PDF document is protected with certificate-based encryption"); 
            else if (encryptTypeResult.getEncryptionType() == EncryptionType.OTHER)     
                System.out.println("The PDF document is protected with another type of encryption");     
            else if (encryptTypeResult.getEncryptionType() == EncryptionType.NONE)     
                System.out.println("The PDF document is not protected.");         
        }catch (Exception e) { 
                e.printStackTrace(); 
        }     
    } 
}