Quick Start (Java SWAref): Determining whether a document is PDF/A compliant using the web service API

The following Java code example determines whether the input PDF document is PDF/A compliant. The input PDF document that is passed to the Assembler service is named Loan.pdf. The name of the DDX document is shell_PDFA.xml. The XML document that is returned from the Assembler service and specifies whether the input PDF document is PDF/A compliant is saved as an XML file named result.xml. (See Determining Whether Documents Are PDF/A- Compliant.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Assembler 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 java.io.InputStream; 
import java.util.Iterator; 
import java.util.List; 
 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
 
import org.apache.xml.xml_soap.MapItem; 
 
import com.adobe.idp.services.*; 
 
public class DeterminePDFASWAref { 
 
    public static void main(String[] args){ 
         
        try{ 
            // Setting configurations to retrieve the Web service 
            String url = "http://hiro-xp:8080/soap/services/AssemblerService?blob=swaRef"; 
            String username = "administrator"; 
            String password = "password"; 
         
            // Create the service Client objects needed 
            AssemblerServiceService assembler = new AssemblerServiceService(); 
            AssemblerService assembClient = assembler.getAssemblerService(); 
         
            // Retrieve the Web services from the LiveCycle Server. 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
            ((BindingProvider) assembClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
             
               // Create BLOB objects that represents the input DDX file and input PDF document 
            String path = "C:\\shell_PDFA.xml"; 
            FileDataSource ds = new FileDataSource(path);  
            DataHandler handler = new DataHandler(ds); 
            BLOB ddxDoc = new BLOB(); 
            ddxDoc.setSwaRef(handler); 
             
            String path2 = "C:\\Adobe\Loan.pdf"; 
            FileDataSource ds2 = new FileDataSource(path2);  
            DataHandler handler2 = new DataHandler(ds2); 
            BLOB pdfDoc = new BLOB(); 
            pdfDoc.setSwaRef(handler2); 
             
            // Create the map containing the PDF source documents 
            MyMapOfXsdStringToXsdAnyType inputMap = new MyMapOfXsdStringToXsdAnyType(); 
            List<MyMapOfXsdStringToXsdAnyTypeItem> inputMapItemList = inputMap.getItem(); 
            MyMapOfXsdStringToXsdAnyTypeItem loanItem = new MyMapOfXsdStringToXsdAnyTypeItem(); 
            loanItem.setKey("Loan.pdf"); 
            loanItem.setValue(pdfDoc); 
            inputMapItemList.add(loanItem); 
 
               // Create an AssemblerOptionsSpec object 
               AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); 
               assemblerSpec.setFailOnError(false); 
 
               // Send the request to the Assembler Service 
               AssemblerResult result = assembClient.invoke(ddxDoc, inputMap, assemblerSpec); 
 
               //Extract the XML document that specifies whether 
               //the input PDF is PDF/A compliant 
               BLOB outDoc = null; 
            List<MapItem> mapResult = result.getDocuments().getItem(); 
            Iterator<MapItem> rit = mapResult.iterator(); 
            while(rit.hasNext()) 
               { 
                MapItem resultItem = rit.next(); 
                   String myKey = (String)(resultItem.getKey()); 
 
                   if (myKey.equals("Loan_result.xml")) 
                   { 
                       outDoc = (BLOB)(resultItem.getValue()); 
                   } 
               } 
 
            File f = new File("C:\\result.xml"); 
            BLOB outBlob = outDoc; 
            DataHandler handler3 = outBlob.getSwaRef(); 
             
            //Get an InputStream from DataHandler and 
            //write to a file 
            InputStream inputStream = handler3.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 e) 
        { 
            e.printStackTrace(); 
        } 
     
    } 
 
}