Quick Start (EJB mode): Passing documents to the Forms Service using the Java API

The following Java quick start retrieves the file Loan.xdp from Content Services (deprecated). This XDP file is located in the space /Company Home/Form Designs. The XDP file is returned in a com.adobe.idp.Document instance. The com.adobe.idp.Document instance is passed to the Forms service. The interactive form is written to a client web browser. (See Passing Documents to the Forms Service.)

/* 
    * This Java Quick Start uses the following JAR files 
    * 1. adobe-forms-client.jar 
    * 2. adobe-contentservices-client.jar 
    * 3. adobe-livecycle-client.jar 
    * 4. adobe-usermanager-client.jar 
    *  
    *  (Because Forms quick starts are implemented as Java servlets, it is  
    *  not necessary to include J2EE specific JAR files - the Java project 
    *  that contains this quick start is exported as a WAR file which 
    *  is deployed to the J2EE application server) 
    *   
    *  These JAR files are located in the following path: 
    * <install directory>/sdk/client-libs/common 
    *  
    * For complete details about the location of these JAR files,  
    * see "Including LiveCycle library files" in Programming with LiveCycle. 
    */ 
import java.io.IOException; 
import javax.servlet.Servlet; 
import javax.servlet.ServletException; 
import javax.servlet.ServletOutputStream; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import com.adobe.livecycle.contentservices.client.CRCResult; 
import com.adobe.livecycle.contentservices.client.impl.DocumentManagementServiceClientImpl; 
import com.adobe.livecycle.formsservice.client.*; 
 
import java.util.*; 
import java.io.InputStream; 
 
import com.adobe.idp.Document; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties; 
 
public class RenderFormsFromContentServices extends HttpServlet implements Servlet { 
 
    public void doGet(HttpServletRequest req, HttpServletResponse resp) 
        throws ServletException, IOException { 
            doPost(req,resp); 
    } 
     
    public void doPost(HttpServletRequest req, HttpServletResponse resp) 
        throws ServletException, IOException { 
        try{ 
            //Set connection properties required to invoke LiveCycle 
            Properties connectionProps = new Properties(); 
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT, "jnp://localhost:1099"); 
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_EJB_PROTOCOL);           
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss"); 
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator"); 
            connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password"); 
             
            //Create a ServiceClientFactory object 
            ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps); 
                 
            //Create a FormsServiceClient object 
            FormsServiceClient formsClient = new FormsServiceClient(myFactory);  
                         
            //Create an empty Document that represents form data 
            byte[]    cData = "".getBytes(); 
            Document oInputData = new Document(cData); 
             
            //Get the form design from Content Services (deprecated) 
            Document formDesign =  GetFormDesign(myFactory); 
                                     
            //Cache the PDF form 
            PDFFormRenderSpec pdfFormRenderSpec = new PDFFormRenderSpec(); 
            pdfFormRenderSpec.setCacheEnabled(new Boolean(true)); 
                     
            //Invoke the renderPDFForm2 and pass to the  
            //Document that contains the form design 
            FormsResult formOut = formsClient.renderPDFForm2( 
                    formDesign,               
                    oInputData,              
                    pdfFormRenderSpec,       
                    null,                 
                    null             
                    ); 
         
            //Create a Document object that stores form data 
            Document myData = formOut.getOutputContent(); 
         
            //Get the content type of the response and 
            //set the HttpServletResponse object?s content type 
            String contentType = myData.getContentType();  
            resp.setContentType(contentType); 
         
            //Create a ServletOutputStream object 
            ServletOutputStream oOutput = resp.getOutputStream(); 
         
            //Create an InputStream object 
            InputStream inputStream = myData.getInputStream(); 
         
            //Write the data stream to the web browser 
            byte[] data = new byte[4096]; 
            int bytesRead = 0; 
            while ((bytesRead = inputStream.read(data)) > 0) 
            { 
                oOutput.write(data, 0, bytesRead); 
            } 
         
            }catch (Exception e) { 
                 e.printStackTrace(); 
              } 
        } 
         
    //Retrieve the form design from Content Services (deprecated) 
    private Document GetFormDesign(ServiceClientFactory myFactory) 
    { 
        try{ 
             
        //Create a DocumentManagementServiceClientImpl object 
        DocumentManagementServiceClientImpl    docManager = new DocumentManagementServiceClientImpl(myFactory);  
             
        //Specify the name of the store and the content to retrieve 
           String storeName = "SpacesStore"; 
           String nodeName  = "/Company Home/Form Designs/Loan.xdp"; 
 
           //Retrieve /Company Home/Form Designs/Loan.xdp 
           CRCResult content = docManager.retrieveContent( 
                     storeName, 
                     nodeName, 
                     ""); 
     
           //Return the Document instance 
            Document doc =content.getDocument();  
            return  doc; 
         } 
             
        catch(Exception e) 
        { 
            e.printStackTrace(); 
        } 
        return null;  
    } 
     
}