API Quick Starts (Code Examples) > Invocation API Quick Starts > Quick Start: Invoking a long-lived process using the Invocation API

Quick Start: Invoking a long-lived process using the Invocation API
The following Java code example invokes a long-lived process named MortgageLoan - Prebuilt. Notice that this process is invoked asynchronously. This quick start contains a user-defined method named GetDataSource that creates XML data that is passed to the process. The XML data is created using a org.w3c.dom.Document instance. (See Invoking Human-Centric Long-Lived Processes.)
/*
 * This Java Quick Start uses the following JAR files
 * 1. adobe-jobmanager-client-sdk.jar
 * 2. adobe-livecycle-client.jar
 * 3. adobe-usermanager-client.jar
 * 4. adobe-utilities.jar
 * 5. jbossall-client.jar (use a different JAR file if LiveCycle ES is not deployed on JBoss)
 * 
 *  These JAR files are located in the following path:
 * <install directory>/Adobe/LiveCycle8/LiveCycle_ES_SDK/client-libs
 * 
 * For complete details about the location of these JAR files, 
 * see "Including LiveCycle ES library files" in 
 * Programming with LiveCycle ES
 */
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.idp.dsc.clientsdk.ServiceClient;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;
import com.adobe.idp.dsc.FaultResponse;
import com.adobe.idp.dsc.InvocationRequest;
import com.adobe.idp.dsc.InvocationResponse;
import java.util.Properties;
import java.util.Map;
import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
 
import org.w3c.dom.Element;
import com.adobe.idp.jobmanager.client.JobManager;
import com.adobe.idp.jobmanager.common.JobId;
import com.adobe.idp.jobmanager.common.JobStatus;
 
public class InvokeLongLived {
	public static void main(String[] args) {
		try{
			//Set connection properties required to invoke LiveCycle ES								
			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();
 
			//Create a Map object to store the parameter value
			Map params = new HashMap();
 
			//Populate the Map object with a parameter value 
			//required to invoke the MortgageLoan long-lived process
			//This process requires XML data
			org.w3c.dom.Document inXML = GetDataSource();
			params.put("xmlFormData", inXML); 
 
			//Create an InvocationRequest object
			InvocationRequest request =  myFactory.createInvocationRequest(
				"MortgageLoan - Prebuilt", //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 response = myServiceClient.invoke(request);
			String invocationId = response.getInvocationId();
 
			//Create a Job Manager object to check the 
			//results of an asynchronous request
			JobManager jobManager = new JobManager(myFactory);
			JobStatus jobStatus = null;
 
			//Create a JobID object that represents the status of the 
			//long-lived operation
			JobId myJobId = new JobId(invocationId); 
 
			//Wait and check the results of the long-lived operation
			for (int i=0;i<5;i++) {
				Thread.sleep(60000);
				jobStatus = jobManager.getStatus(myJobId);
				System.out.println("Job Status: " + jobStatus.getStatusCode());
				if (jobStatus.getStatusCode()== JobStatus.JOB_STATUS_COMPLETED || jobStatus.getStatusCode()==JobStatus.JOB_STATUS_FAILED) {
					break;
					}
				}//end of for loop
 
			if (jobStatus.getStatusCode()==JobStatus.JOB_STATUS_COMPLETED) {
				System.out.println("INVOCATION COMPLETED SUCCESSFULLY!");
				InvocationResponse jobResponse = jobManager.getResponse(myJobId);
				jobManager.disposeJob(myJobId);
 
			 } else if (jobStatus.getStatusCode()==JobStatus.JOB_STATUS_FAILED) {
				System.out.println("INVOCATION COMPLETED FAILED!");
				FaultResponse _fr = jobManager.getFaultResponse(new JobId(invocationId));
				System.out.println(_fr.getStackTrace());
				jobManager.disposeJob(myJobId);
 
			  } else {
				System.out.println("INVOCATION STATUS " + jobStatus.getStatusCode() + " NOT COMPLETE.");
			  }
 
	 }catch (Exception e) {
 
			e.printStackTrace();
		}
	}
	 //Create XML data to pass to the long-lived process
	 private static org.w3c.dom.Document GetDataSource()
	 {
			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("MortgageApp");
				document.appendChild(root);
				
				//Create Mortgage fields and append it to MortgageApp
				Element MortgageFields = (Element)document.createElement("MortgageFields");
				root.appendChild(MortgageFields);
				
				//Create ApplicantFields and append it to MortgageApp
				Element ApplicantFields = (Element)document.createElement("ApplicantFields");
				root.appendChild(ApplicantFields);
					
				//Create the PropertyPrice element - a child to Mortgage fields
				Element PropertyPrice = (Element)document.createElement("PropertyPrice");
				PropertyPrice.appendChild(document.createTextNode("700000"));
				MortgageFields.appendChild(PropertyPrice);
				
				//Create the DownPayment element - a child to Mortgage fields
				Element DownPayment =(Element)document.createElement("DownPayment");
				DownPayment.appendChild(document.createTextNode("100000"));
				MortgageFields.appendChild(DownPayment);
				
				//Create the DownPayment element - a child to Mortgage fields
				Element Mortgage =(Element)document.createElement("Mortgage");
				Mortgage.appendChild(document.createTextNode("600000"));
				MortgageFields.appendChild(Mortgage);
 
				//Create the Term element - a child to Mortgage fields
				Element Term = (Element)document.createElement("Term");
				Term.appendChild(document.createTextNode("20"));
				MortgageFields.appendChild(Term);
 
				//Create the InterestRate element - a child to Mortgage fields
				Element InterestRate = (Element)document.createElement("InterestRate");
				InterestRate.appendChild(document.createTextNode("6.0"));
				MortgageFields.appendChild(InterestRate);
 
				//Create the LastName element - a child to ApplicantFields fields
				Element LastName = (Element)document.createElement("LastName");
				LastName.appendChild(document.createTextNode("White"));
				ApplicantFields.appendChild(LastName);
 
				//Create the FirstName element - a child to ApplicantFields fields
				Element FirstName = (Element)document.createElement("FirstName");
				FirstName.appendChild(document.createTextNode("Sam"));
				ApplicantFields.appendChild(FirstName);
 
				//Create the PhoneNumber element - a child to ApplicantFields fields
				Element PhoneNumber = (Element)document.createElement("PhoneNumber");
				PhoneNumber.appendChild(document.createTextNode("555-5555"));
				ApplicantFields.appendChild(PhoneNumber);
 
				//Create the SNN element - a child to ApplicantFields fields
				Element SSN = (Element)document.createElement("SSN");
				SSN.appendChild(document.createTextNode("123-456-678"));
				ApplicantFields.appendChild(SSN);
								
			  }
		 catch (Exception e) {
				  System.out.println("The following exception occurred: "+e.getMessage());
			   }
		return document;
		 }
	 }

API Quick Starts (Code Examples) > Invocation API Quick Starts > Quick Start: Invoking a long-lived process using the Invocation API

Programming with LiveCycle ES (LiveDocs)
Adobe LiveCycle ES Update 1

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/000005.html