Quick Start (SwaRef): Certifying a PDF document using the web service API

The following Java web service code example certifies a PDF document that is based on a PDF file named LoanSig.pdf. The alias that is specified for the security credential is secure, and revocation checking is not performed. The certified document is saved as a PDF file named LoanCertified.pdf. (See Certifying PDF Documents.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Signature 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.File; 
import java.io.FileOutputStream; 
import java.io.InputStream; 
import java.io.OutputStream; 
 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
 
import com.adobe.idp.services.*; 
 
public class CertifyDocumentSWAref { 
 
    public static void main(String[] args) { 
    try 
    { 
      // Setting configurations to retrieve the Web service 
      String url = "http://hiro-xp:8080/soap/services/signatureservice?blob=swaRef"; 
      String username = "administrator"; 
      String password = "password"; 
             
      // Create the service Client objects needed 
      SignatureServiceService signatureService = new SignatureServiceService(); 
      SignatureService signatureClient =  signatureService.getSignatureservice(); 
 
         // Retrieve the Web services from the LiveCycle server. 
         ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
         ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
      ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
             
      //Set an input file as a BLOB         
        String path1 = "C:\\Adobe\LoanSig.pdf"; 
        FileDataSource ds1 = new FileDataSource(path1);  
        DataHandler handler1 = new DataHandler(ds1); 
        BLOB inDoc = new BLOB(); 
        inDoc.setSwaRef(handler1); 
     
      //Specify the name of the signature field 
      String fieldName = "SignatureField1"; 
 
      //Create a Credential object 
      Credential myCred = new Credential(); 
      myCred.setAlias("secure"); 
     
      //Specify the reason to sign the document 
      String reason = "The document was reviewed"; 
 
      //Specify the location of the signer 
      String location  = "My company";  
     
      //Specify contact information 
          String contactInfo = "New York, New York"; 
 
      //Create a PDFSignatureAppearanceOptions object and show date information 
      PDFSignatureAppearanceOptionSpec appear = new  PDFSignatureAppearanceOptionSpec();  
      appear.setShowDate(true); 
 
      //Set revocation checking to false 
           java.lang.Boolean revCheck = new Boolean(false); 
     
           //Set locking to false 
           java.lang.Boolean lockField = new Boolean(false); 
     
           //Specify a legalAttestation value 
           String msg = "Any change to this document will invalidate the certificate";     
     
           //Create objects to pass to the certify method 
           OCSPOptionSpec ocspSpec = new OCSPOptionSpec(); 
           CRLOptionSpec crlSpec = new CRLOptionSpec(); 
           TSPOptionSpec tspSpec = new TSPOptionSpec(); 
          
           //Certify the PDF document 
           BLOB signedDoc = signatureClient.certify( 
              inDoc, 
              fieldName, 
              myCred, 
              HashAlgorithm.SHA_1, 
              reason, 
              location, 
              contactInfo, 
              MDPPermissions.NO_CHANGES, 
              msg, 
              appear, 
              revCheck, 
              lockField, 
             ocspSpec, 
             crlSpec, 
             tspSpec); 
 
              //Create a new file containing the returned PDF document 
        File f = new File("C:\\Adobe\LoanCertified.pdf"); 
        BLOB outBlob = signedDoc; 
        DataHandler handler2 = outBlob.getSwaRef(); 
         
        //Get an InputStream from DataHandler and 
        //write to a file 
        InputStream inputStream = handler2.getInputStream(); 
        OutputStream out = new FileOutputStream(f); 
         
        //Iterate through the buffer 
        byte buf[] = new byte[1024]; 
        int len; 
        while ((len = inputStream.read(buf)) > 0) 
            out.write(buf, 0, len); 
        out.close(); 
        inputStream.close(); 
        } 
     
    catch (Exception ee) 
        { 
        ee.printStackTrace(); 
        } 
    } 
}

// Ethnio survey code removed