You can invoke a short-lived process using the Java Invocation
API. When you invoke a short-lived process using the Invocation
API, you pass required parameter values by using a java.util.HashMap object.
For each parameter to pass to a service, invoke the java.util.HashMap object’s put method and
specify the name-value pair that is required by the service in order
to perform the specified operation. Specify the exact name of the
parameters that belong to the short-lived process.
The discussion here is about using Invocation API to invoke the
following LiveCycle short-lived process named MyApplication/EncryptDocument.
Note: This process is not based on an existing LiveCycle
process. To follow along with the code example, create a process
named MyApplication/EncryptDocument using Workbench.
(See Using Workbench.)
When this process is invoked, it performs the following actions:
Obtains the unsecured PDF document that is passed to
the process. This action is based on the SetValue operation.
The input parameter for this process is a document process
variable named inDoc.
Encrypts the PDF document with a password. This action is
based on the PasswordEncryptPDF operation. The
password encrypted PDF document is returned in a process variable
named outDoc.
Invoke the MyApplication/EncryptDocument short-lived process using the Java invocation APIInvoke the MyApplication/EncryptDocument short-lived
process using the Java invocation API:
Include client JAR files, such as the adobe-livecycle-client.jar,
in your Java project’s class path. (See Including LiveCycle Java library files.)
Create a ServiceClientFactory object that
contains connection properties. (See Setting connection properties.)
Create a ServiceClient object by using its
constructor and passing the ServiceClientFactory object.
A ServiceClient object lets you invoke a service
operation. It handles tasks such as locating, dispatching, and routing
invocation requests.
Create a java.util.HashMap object by using
its constructor.
Invoke the java.util.HashMap object’s put method
for each input parameter to pass to the long-lived process. Because
the MyApplication/EncryptDocument short-lived process
requires one input parameter of type Document,
you only have to invoke the put method once, as
shown in the following example.
//Create a Map object to store the parameter value for inDoc
Map params = new HashMap();
InputStream inFile = new FileInputStream("C:\\Adobe\Loan.pdf");
Document inDoc = new Document(inFile);
params.put("inDoc", inDoc);
Create an InvocationRequest object by invoking
the ServiceClientFactory object’s createInvocationRequest method
and passing the following values:
A string value that
specifies the name of the long-lived process to invoke. To invoke
the MyApplication/EncryptDocument process, specify MyApplication/EncryptDocument.
A string value that represents the process operation name.
Typically the name of a short-lived process operation is invoke.
The java.util.HashMap object that contains
the parameter values that the service operation requires.
A Boolean value that specifies true, which
creates a synchronous request (this value is applicable to invoke
a short-lived process).
Send the invocation request to the service by invoking the ServiceClient object’s invoke method
and passing the InvocationRequest object. The invoke method
returns an InvocationReponse object.
Note: A long-lived process can be invoked by passing
the value false as the fourth parameter of the createInvocationRequest method.
Passing the value false creates an asynchronous request.
Retrieve the process’s return value by invoking the InvocationReponse object’s getOutputParameter method
and passing a string value that specifies the name of the output
parameter. In this situation, specify outDoc (outDoc is
the name of the output parameter for the MyApplication/EncryptDocument process).
Cast the return value to Document, as shown in
the following example.
InvocationResponse response = myServiceClient.invoke(request);
Document encryptDoc = (Document) response.getOutputParameter("outDoc");
Create a java.io.File object and ensure
that the file extension is .pdf.
Invoke the com.adobe.idp.Document object’s copyToFile method
to copy the contents of the com.adobe.idp.Document object
to the file. Ensure that you use the com.adobe.idp.Document object
that was returned by the getOutputParameter method.
|
|
|