Monday, July 19, 2010

Invoking an Orchestration Process through a Servlet

In this tutorial, we will be primarily focusing on invoking a Short-Lived or Orchestration LiveCycle process through a servlet. To be able to understand the tutorial, one should be familiar with J2EE and LiveCycle Processes. This tutorial gives you the step-by-step procedure that one should follow in order to invoke a short lived process. It starts with the Software/Tools, Orchestration Process Design, introduction of Adobe's proprietary Application Programming Interface, LiveCycle Integration Types, and Invocation steps.

Software/Tools: For the purpose of this tutorial, I used Netbeans, Glassfish 3.0 server, LiveCycle ES2, JBoss server hosting LiveCycle, JDK 1.6, etc.

Orchestration Process Design: Orchestration process is also referred to as Short-lived process. As the name suggests, the purpose of orchestration process is to orchestrate a business process. Generally, it is used to render PDF forms or deliver data to the PDF Form upon user interaction. For extreme simplicity, we will design a process that will take two input strings and returns an out string. Click here to know more about this orchestration process design.

Adobe's Application Programming Interface: Adobe provides API to program with LiveCycle ES2 services. The API is categorized into two types -- a) Java Client Library b) Java Invocation API.
  1. Java Client Library serves the purpose to invoke LiveCycle ES2 Services such as Assembler Service API for assembling multiple PDF documents into one file, Forms Service API to render interactive/dynamic/static PDF documents, etc.
  2. Java Invocation API would be used to invoke Short-Lived or Human-Centric processes.
LiveCycle Integration Types: Invoking a LiveCycle from a web application can be done in several ways (Remoting for Flex, Java API for J2EE, and WebService API for .net applications).
In this tutorial, we will discuss about Java API Invocation API.

Invocation Steps: We will be using SOAP connection mode.
  1. Create a web project and include the following jar files (adobe-livecycle-client, adobe-usermanager-client, adobe-utilities, activation, axis, commons-codec-1.3, commons-discovery, commons-logging, dom3-xml-apis-2.5.0, jaxen-1.1, jaxrpc, log4j, mail, wsdl4j, xalan, xbean, xercesImpl)
  2. Create a servlet in your project. In the servlet, define ServiceClientFactory to hold connection properties; create ServiceClient object to establish a connection with LiveCycle server; Create an InvocationRequest object to send an invocation request to livecycle process and retrieving invocation response;
Copy the following code into your servlet and be sure to change the connection properties appropriate to your server settings.


package com.r3tek;

import com.adobe.idp.dsc.DSCException;
import com.adobe.idp.dsc.InvocationRequest;
import com.adobe.idp.dsc.InvocationResponse;
import com.adobe.idp.dsc.clientsdk.ServiceClient;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JavaServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Properties connectionProps = new Properties();
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "http://192.168.1.37:8080");
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL, ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, ServiceClientFactoryProperties.DSC_JBOSS_SERVER_TYPE);
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator");
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password");
Map params = new HashMap();

params.put("lname", "vanam");
params.put("fname", "Naveen");

ServiceClientFactory factory = ServiceClientFactory.createInstance(connectionProps);
ServiceClient myServiceClient = factory.getServiceClient();
InvocationRequest requestInv = factory.createInvocationRequest(
"TimeSheets/getEmployeeID",
"invoke",
params,
true);
InvocationResponse responseInv = myServiceClient.invoke(requestInv);
String outPut = (String) responseInv.getOutputParameter("employeeID");

out.println("");
out.println("");
out.println("Servlet TestServlet");
out.println("");
out.println("");
out.println("

The Output value " + outPut + "

");

out.println("");
out.println("");

} catch (DSCException ex) {
Logger.getLogger(JavaServlet.class.getName()).log(Level.SEVERE, null, ex);
} finally {
out.close();
}
}
}

In the next tutorial, we will see how to invoke Human-Centric Process. Good Luck!

No comments:

Post a Comment