Quick Start (Java SWAref): Validating DDX documents using the web service API

The following Java code example validates a DDX document based on a file named bookmarkDDX.xml. (See Validating DDX Documents.)

/** 
    * 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. 
    *  
    * This quick start validates the following DDX document: 
    *&<?xml version="1.0" encoding="UTF-8"?> 
    * <DDX xmlns="http://ns.adobe.com/DDX/1.0/"> 
    *    <PDF result="out.pdf"> 
    *        <PDF source="map.pdf" /> 
    *        <PDF source="directions.pdf" /> 
    *    </PDF> 
    * </DDX> 
    */ 
 
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 ValidateDDXSWAref { 
    public static void main(String[] args){ 
         
        try{ 
            //Create an AssemblerServiceService object 
            AssemblerServiceService assembler = new AssemblerServiceService(); 
            AssemblerService assembClient = assembler.getAssemblerService(); 
             
            //Set connection values required to invoke LiveCycle 
            String url = "http://hiro-xp:8080/soap/services/AssemblerService?blob=swaRef"; 
            String username = "administrator"; 
            String password = "password"; 
            ((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); 
             
            //Set an input file as a BLOB          
            String path1 = "C:\\bookmarkDDX.xml"; 
            FileDataSource ds1 = new FileDataSource(path1);  
            DataHandler handler1 = new DataHandler(ds1); 
            BLOB ddxDoc = new BLOB(); 
            ddxDoc.setSwaRef(handler1); 
                         
            // Create an AssemblerOptionsSpec object 
               AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); 
               assemblerSpec.setValidateOnly(true); 
               assemblerSpec.setLogLevel("FINE"); 
 
               //Validate the DDX document 
               AssemblerResult result = assembClient.invoke(ddxDoc, null, assemblerSpec); 
 
               //Write the PDF file to the local file system 
            File f = new File("C:\\logFile.xml"); 
            BLOB outBlob = result.getJobLog(); 
            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 e) 
        { 
            e.printStackTrace(); 
        } 
     
    } 
 
}