Wednesday, July 21, 2010

Learn Variables Scope in LiveCycle Process Design

In the process design, we define variables for accessing a value within multiple operations. The value can be any data type (String, int, long, boolean, etc). Besides common datatypes, Adobe LiveCycle ES comes with several Service specific data types such as ReaderExtensionsOptionSpec, RenderOptionSpec, PDFOutputOptionSpec, etc.

A variable in LiveCycle process can be defined in two different purposes - a) Process Varibale b) Configuration Parameter.

We will discuss Process Variables in this tutorial. A variable can be input, output or required type to the process. What does it mean when you say INPUT or OUTPUT variable? If a variable is an input then that variable has to be passed to the process when it is invoked through LiveCycle workbench/web browser. And it is the same case with the OUTPUT variable type. The process would respond with a result of that output variable type.

Now, just like the process variables, we need to define variables for each operation within the process design. If we look at the figure renderPDFForm2 Operation, we need to specify input and and output parameters for this operation. These are different from the above image. LiveCycle beginners can get confused easily with the terms Input variables for process and operations.

The parameters for an operation can be passed in serveral ways like a Literal Value, Variable, X-Path Expression, and Templates. If you choose a variable type for either Input or Output parameter, you need to specify the process variable. In the same figure, formData and outTSPDFForm are two process variables and their parameter type is variable but for Input>>Form parameter the type is Literal Value and you can see the value is a String.

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!