Quick Start: Invoking a long-lived process using the Invocation API

The following Java code example represents the Java servlet that invokes the FirstAppSolution/PreLoanProcess process.

/* 
    * This Java Quick Start uses the following JAR files 
    * 1. adobe-livecycle-client.jar 
    * 2. adobe-usermanager-client.jar 
    *  
    *  (Because this  quick start is implemented as a Java servlet, 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.ByteArrayOutputStream; 
import java.io.File; 
import java.io.IOException; 
import java.io.PrintWriter; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import java.util.*; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties; 
import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 
import javax.xml.transform.Transformer; 
import javax.xml.transform.TransformerFactory; 
import javax.xml.transform.dom.DOMSource; 
import javax.xml.transform.stream.StreamResult; 
 
import com.adobe.idp.dsc.InvocationRequest; 
import com.adobe.idp.dsc.InvocationResponse; 
import com.adobe.idp.dsc.clientsdk.ServiceClient; 
import org.w3c.dom.Element; 
 
    public class SubmitXML extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { 
      static final long serialVersionUID = 1L; 
     
       public SubmitXML() { 
        super(); 
    }        
     
     
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
        // TODO Auto-generated method stub 
        doPost(request,response); 
    }       
     
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
                 
        try{ 
            //Set connection properties required to invoke LiveCycle ES3                                 
            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 ServiceClient object 
            ServiceClient myServiceClient = myFactory.getServiceClient(); 
             
            //Get the values that are passed from the Loan HTML page 
            String name = (String)request.getParameter("name"); 
            String phone = (String)request.getParameter("phone"); 
            String amount = (String)request.getParameter("amount"); 
                 
            //Create XML to pass to the FirstAppSolution/PreLoanProcess process 
            org.w3c.dom.Document inXML = GetDataSource(name,phone,amount); 
                                 
            //Create a Map object to store the XML input parameter value 
            Map params = new HashMap(); 
            params.put("formData", inXML);  
             
            //Create an InvocationRequest object 
            InvocationRequest lcRequest =  myFactory.createInvocationRequest( 
                "FirstAppSolution/PreLoanProcess", //Specify the long-lived process name 
                    "invoke",           //Specify the operation name     
                    params,               //Specify input values 
                    false);               //Create an asynchronous request  
             
            //Send the invocation request to the long-lived process and  
            //get back an invocation response object 
            InvocationResponse lcResponse = myServiceClient.invoke(lcRequest); 
            String invocationId = lcResponse.getInvocationId(); 
 
            //Create a PrintWriter instance 
            PrintWriter pp = response.getWriter();      
             
            //Write the invocation identifier value back to the client web browser 
            pp.println("The job status identifier value is: " +invocationId); 
             
        }catch (Exception e) { 
             System.out.println("The following exception occurred: "+e.getMessage()); 
      } 
    } 
     
     
     //Create XML data to pass to the long-lived process 
     private static org.w3c.dom.Document GetDataSource(String name, String phone, String amount) 
     { 
            org.w3c.dom.Document document = null; 
             
            try 
            { 
                //Create DocumentBuilderFactory and DocumentBuilder objects 
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
                DocumentBuilder builder = factory.newDocumentBuilder(); 
 
                //Create a new Document object 
                document = builder.newDocument();  
 
                //Create MortgageApp - the root element in the XML  
                Element root = (Element)document.createElement("LoanApp"); 
                document.appendChild(root); 
                                             
                //Create an XML element for Name 
                Element nameElement = (Element)document.createElement("Name"); 
                nameElement.appendChild(document.createTextNode(name)); 
                root.appendChild(nameElement); 
                 
                //Create an XML element for Phone 
                Element phoneElement = (Element)document.createElement("PhoneOrEmail"); 
                phoneElement.appendChild(document.createTextNode(phone)); 
                root.appendChild(phoneElement); 
                 
                //Create an XML element for amount 
                Element loanElement = (Element)document.createElement("LoanAmount"); 
                loanElement.appendChild(document.createTextNode(amount)); 
                root.appendChild(loanElement); 
 
                //Create an XML element for ApprovalStatus 
                Element approveElement = (Element)document.createElement("ApprovalStatus"); 
                approveElement.appendChild(document.createTextNode("PENDING APPROVAL")); 
                root.appendChild(approveElement); 
                                 
              } 
         catch (Exception e) { 
                  System.out.println("The following exception occurred: "+e.getMessage()); 
               } 
        return document; 
         } 
        }

// Ethnio survey code removed