Invoking Human-Centric Long-Lived Processes invoking-human-centric-long-lived-processes
You can programmatically invoke human-centric long-lived processes that were created in Workbench using these client applications:
- A Java web-based client application that uses the Invocation API. (See Invoking AEM Forms using the Java API(https://experienceleague.adobe.com/docs/experience-manager-65-lts/content/forms/developer-reference/programming-aem-forms-jee/invoking-aem-forms-jee-apis/invoking-aem-forms-using-java.html?lang=en#invoking-aem-forms-using-the-java-api).)
- An ASP.NET application that uses web services. (See Invoking AEM Forms Using Web Services.)
- A client application built with Flex that uses Remoting. (See Invoking AEM Forms using (Deprecated for AEM forms) AEM Forms Remoting.)
The long-lived process that is invoked is named FirstAppSolution/PreLoanProcess. You can create this process by following the tutorial specified in Creating Your First AEM Forms Application.
A human-centric process involves a task that a user can respond to by using Workspace. For example, using Workbench, you can create a process that lets a bank manager approve or deny a loan application. The following illustration shows the process FirstAppSolution/PreLoanProcess.
The FirstAppSolution/PreLoanProcess process accepts an input parameter named formData whose data type is XML. The XML data is merged with a form design named PreLoanForm.xdp. The following illustration shows a form that represents a task assigned to a user to approve or deny a loan application. The user approves or denies the application by using Workspace. The Workspace user can approve the loan request by clicking the Approve button shown in the following illustration. Likewise, the user can deny the loan request by clicking the deny button.
A long-lived process is invoked asynchronously and cannot be invoked synchronously due to the following factors:
- A process can span a significant amount of time.
- A process can span organizational boundaries.
- A process needs external input in order for it to finish. For example, consider a situation where a form is sent to a manager, who is out of the office. In this situation, the process is not complete until the manager returns and fills out the form.
When a long-lived process is invoked, AEM Forms creates an invocation identifier value as part of creating a record. The record tracks the status of the long-lived process and is stored in the AEM Forms database. Using the invocation identifier value, you can track the status of the long-lived process. In addition, you can use the process invocation identifier value to perform Process Manager operations such as terminating a running process instance.
The FirstAppSolution/PreLoanProcess process is invoked when an applicant submits an application, which is represented as XML data. The name of the input process variable is formData and its data type is XML. For the purposes of this discussion, assume that the following XML data is used as input to the FirstAppSolution/PreLoanProcess process.
<?xml version="1.0" encoding="UTF-8"?>
<LoanApp>
<Name>Sam White</Name>
<LoanAmount>250000</LoanAmount>
<PhoneOrEmail>(555)555-5555</PhoneOrEmail>
<ApprovalStatus>PENDING APPROVAL</ApprovalStatus>
</LoanApp>
XML data passed to a process must match the fields in the form used in the process. Otherwise, data is not displayed within the form. All applications that invoke the FirstAppSolution/PreLoanProcess process must pass this XML data source. The applications created in Invoking Human-Centric Long-Lived Processes dynamically create the XML data source from values that a user entered into a web client.
Using a client application, you can send the FirstAppSolution/PreLoanProcess process the required XML data. A long-lived process returns an invocation identifier value as its return value. The following illustration shows client applications invoking the*FirstAppSolution/PreLoanProcess long-lived process. The client applications send XML data and get back a string value that represents the invocation identifier value.
See also
Creating a Java web application that invokes a human-centric long-lived process
Creating an ASP.NET web application that invokes a human-centric long-lived process
Creating a client application built with Flex that invokes a human-centric long-lived process
Creating a Java web application that invokes a human-centric long-lived process creating-a-java-web-application-that-invokes-a-human-centric-long-lived-process
You can create a web-based application that uses a Java servlet to invoke the FirstAppSolution/PreLoanProcess process. To invoke this process from a Java servlet, use the Invocation API within the Java servlet. (See Invoking AEM Forms using the Java API.)
The following illustration shows a web-based client application that posts name, phone (or email), and amount values. These values are sent to the Java servlet when the user clicks the Submit Application button.
The Java servlet performs the following tasks:
- Retrieves the values posted from the HTML page to the Java servlet.
- Dynamically creates an XML data source to pass to the FirstAppSolution/PreLoanProcess process. The name, phone (or email), and amount values are specified in the XML data source.
- Invokes the FirstAppSolution/PreLoanProcess process by using the AEM Forms Invocation API.
- Returns the invocation identifier value to the client web browser.
Summary of steps summary-of-steps
To create a Java web-based application that invokes the FirstAppSolution/PreLoanProcess process, perform the following steps:
Create a web project create-a-web-project
The first step to create a web application is to create a web project. The Java IDE that this document is based on is Eclipse 3.3. Using the Eclipse IDE, create a web project and add the required JAR files to your project. Add an HTML page named index.html and a Java servlet to your project.
The following list specifies the JAR files to include in your web project:
- adobe-livecycle-client.jar
- adobe-usermanager-client.jar
- J2EE.jar
For the location of these JAR files, see Including AEM Forms Java library files.
Create a web project
- Start Eclipse and click File > New Project.
- In the New Project dialog box, select Web > Dynamic Web Project.
- Type
InvokePreLoanProcessfor the name of your project and then click Finish.
Add required JAR files to your project
- From the Project Explorer window, right-click the
InvokePreLoanProcessproject and select Properties. - Click Java build path and then click the Libraries tab.
- Click the Add External JARs button and browse to the JAR files to include.
Add a Java servlet to your project
- From the Project Explorer window, right-click the
InvokePreLoanProcessproject and select New > Other. - Expand the Web folder, select Servlet, and then click Next.
- In the Create Servlet dialog box, type
SubmitXMLfor the name of the servlet and then click Finish.
Add an HTML page to your project
- From the Project Explorer window, right-click the
InvokePreLoanProcessproject and select New > Other. - Expand the Web folder, select HTML, and click Next.
- In the New HTML dialog box, type
index.htmlfor the filename and then click Finish.
Create Java application logic for the servlet create-java-application-logic-for-the-servlet
Create Java application logic that invokes the FirstAppSolution/PreLoanProcess process from within the Java servlet. The following code shows the syntax of the SubmitXML Java Servlet:
public class SubmitXML extends HttpServlet implements Servlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp
throws ServletException, IOException {
doPost(req,resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp
throws ServletException, IOException {
//Add code here to invoke the FirstAppSolution/PreLoanProcess process
}
Normally, you would not place client code within a Java servlet’s doGet or doPost method. A better programming practice is to place this code within a separate class. Then instantiate the class from within the doPost method (or doGet method), and call the appropriate methods. However, for code brevity, code examples are kept to a minimum and are placed in the doPost method.
To invoke the FirstAppSolution/PreLoanProcess process using the Invocation API, perform the following tasks:
-
Include client JAR files, such as adobe-livecycle-client.jar, in your Java project’s class path. For information about the location of these files, see Including AEM Forms Java library files.
-
Retrieve the name, phone, and amount values that is submitted from the HTML page. Use these values to dynamically create an XML data source that is sent to the
FirstAppSolution/PreLoanProcessprocess. You can useorg.w3c.domclasses to create the XML data source (this application logic is shown in the following code example). -
Create a
ServiceClientFactoryobject that contains connection properties. (See Setting connection properties.) -
Create a
ServiceClientobject by using its constructor and passing theServiceClientFactoryobject. AServiceClientobject lets you invoke a service operation. It handles tasks such as locating, dispatching, and routing invocation requests. -
Create a
java.util.HashMapobject by using its constructor. -
Invoke the
java.util.HashMapobject’sputmethod for each input parameter to pass to the long-lived process. Ensure that you specify the name of the process’s input parameters. Because theFirstAppSolution/PreLoanProcessprocess requires one input parameter of typeXML(namedformData), you only have to invoke theputmethod once.code language-java //Get the XML to pass to the FirstAppSolution/PreLoanProcess process org.w3c.dom.Document inXML = GetDataSource(name,phone,amount); //Create a Map object to store the parameter value Map params = new HashMap(); params.put("formData", inXML); -
Create an
InvocationRequestobject by invoking theServiceClientFactoryobject’screateInvocationRequestmethod and passing the following values:- A string value that specifies the name of the long-lived process to invoke. To invoke the
FirstAppSolution/PreLoanProcessprocess, specifyFirstAppSolution/PreLoanProcess. - A string value that represents the process operation name. The name of the long-lived process operation is
invoke. - The
java.util.HashMapobject that contains the parameter values that the service operation requires. - A Boolean value that specifies
false, which creates an asynchronous request (this value is applicable to invoke a long-lived process).
note note NOTE A short-lived process can be invoked by passing the value true as the fourth parameter of the createInvocationRequest method. Passing the value true creates a synchronous request. - A string value that specifies the name of the long-lived process to invoke. To invoke the
-
Send the invocation request to AEM Forms by invoking the
ServiceClientobject’sinvokemethod and passing theInvocationRequestobject. Theinvokemethod returns anInvocationReponseobject. -
A long-lived process returns a string value that represents an invocation identification value. Retrieve this value by invoking the
InvocationReponseobject’sgetInvocationIdmethod.code language-java //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(); -
Write the invocation identification value to the client web browser. You can use a
java.io.PrintWriterinstance to write this value to the client web browser.
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 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 in the following path:
* <install directory>/sdk/client-libs/common
*
* For complete details about the location of these JAR files,
* see "Including AEM Forms library files" in Programming with AEM forms
* */
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 AEM Forms
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 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;
}
}
Create the web page for the web application create-the-web-page-for-the-web-application
The index.html web page provides an entry point to the Java servlet that invokes the FirstAppSolution/PreLoanProcess process. This web page is a basic HTML form that contains an HTML form and a submit button. When the user clicks the submit button, form data is posted to the SubmitXML Java servlet.
The Java servlet captures the data that is posted from the HTML page by using the following Java code:
//Get the values that are passed from the Loan HTML page
String name = request.getParameter("name");
String phone = request.getParameter("phone");
String amount = request.getParameter("amount");
The following HTML code represents the index.html file that was created during setup of the development environment. (See Create a web project.)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table>
<TBODY>
<TR>
<td><img src="financeCorpLogo.jpg" width="172" height="62"></TD>
<td><FONT size="+2"><strong>Java Loan Application Page</strong></FONT></TD>
<td> </TD>
<td> </TD>
</TR>
</TBODY>
</TABLE>
<FORM action="https://hiro-xp:8080/PreLoanProcess/SubmitXML" method="post">
<table>
<TBODY>
<TR>
<td><LABEL for="name">Name: </LABEL></TD>
<td><INPUT type="text" name="name"></TD>
<td><input type="submit" value="Submit Application"></TD>
</TR>
<TR>
<td> <LABEL for="phone">Phone/Email: </LABEL></TD>
<td><INPUT type="text" name="phone"></TD>
<td></TD>
</TR>
<TR>
<td><LABEL for="amount">Amount: </LABEL></TD>
<td><INPUT type="text" name="amount"></TD>
<td></TD>
</TR>
</TBODY>
</TABLE>
</FORM>
</body>
</html>
Package the web application to a WAR file package-the-web-application-to-a-war-file
To deploy the Java servlet that invokes the FirstAppSolution/PreLoanProcess process, package your web application to a WAR file. Ensure that external JAR files that the component’s business logic depends on, such as adobe-livecycle-client.jar and adobe-usermanager-client.jar, are also included in the WAR file.
The following illustration shows the Eclipse project’s content, which is packaged to a WAR file.
Package a web application to a WAR file:
- From the Project Explorer window, right-click the
InvokePreLoanProcessproject and select Export > WAR file. - In the Web module text box, type
InvokePreLoanProcessfor the name of the Java project. - In the Destination text box, type
PreLoanProcess.warfor the filename, specify the location for your WAR file, and then click Finish.
Deploy the WAR file to the J2EE application server hosting AEM Forms deploy-the-war-file-to-the-j2ee-application-server-hosting-aem-forms
Deploy the WAR file to the J2EE application server on which AEM Forms is deployed. To deploy the WAR file to the J2EE application server, copy the WAR file from the export path to [AEM Forms Install]\Adobe\Adobe Experience Manager Forms\jboss\server\lc_turnkey\deploy.
Test your web application test-your-web-application
After you deploy the web application, you can test it by using a web browser. Assuming that you are using the same computer that is hosting AEM Forms, you can specify the following URL:
-
http://localhost:8080/PreLoanProcess/index.html
Enter values into the HTML form fields and click the Submit Application button. If problems occur, see the J2EE application server’s log file.
Creating an ASP.NET web application that invokes a human-centric long-lived process creating-an-asp-net-web-application-that-invokes-a-human-centric-long-lived-process
You can create an ASP.NET application that invokes the FirstAppSolution/PreLoanProcess process. To invoke this process from an ASP.NET application, use web services. (See Invoking AEM Forms using Web Services.)
The following illustration shows an ASP.NET client application obtaining data from an end user. The data is placed into an XML data source and sent to the FirstAppSolution/PreLoanProcess process when the user clicks the Submit Application button.
Notice after the process is invoked, an invocation identifier value is displayed. An invocation identifier value is created as part of a record that tracks the status of the long-lived process.
The ASP.NET application performs the following tasks:
- Retrieves the values that the user entered into the web page.
- Dynamically creates an XML data source that is passed to the* FirstAppSolution/PreLoanProcess *process. The three values are specified in the XML data source.
- Invokes the* FirstAppSolution/PreLoanProcess *process by using the web services.
- Returns the invocation identifier value and the status of the long-lived operation to the client web browser.
Summary of steps summary_of_steps-1
To create an ASP.NET application that is able to invoke the FirstAppSolution/PreLoanProcess process, perform the following steps:
Create an ASP.NET web application create-an-asp-net-web-application
Create a Microsoft .NET C# ASP.NET Web application. The following illustration shows the contents of the ASP.NET project named InvokePreLoanProcess.
Notice under Service References, there are two items. The first item is named* JobManager*. This reference enables the ASP.NET application to invoke the Job Manager service. This service returns information about the status of a long-lived process. For example, if the process is currently running, then this service returns a numeric value that specifies the process is currently running. The second reference is named PreLoanProcess. This service reference represents the reference to the* FirstAppSolution/PreLoanProcess *process. After you create a Service Reference, data types associated with the AEM Forms service are available for use within your .NET project.
Create a ASP.NET project:
- Start Microsoft Visual Studio 2008.
- From the File menu, select New, Web Site.
- In the Templates list, select ASP.NET Web Site.
- In the Location box, select a location for your project. Name your project InvokePreLoanProcess.
- In the Language box, select Visual C#
- Click OK.
Add service references:
-
In the Project menu, select Add Service Reference.
-
In the Address dialog box, specify the WSDL to the Job Manager service.
code language-java https://hiro-xp:8080/soap/services/JobManager?WSDL&lc_version=9.0.1 -
In the Namespace field, type
JobManager. -
Click Go and then click OK.
-
In the Project menu, select Add Service Reference.
-
In the Address dialog box, specify the WSDL to the FirstAppSolution/PreLoanProcess process.
code language-java https://hiro-xp:8080/soap/services/FirstAppSolution/PreLoanProcess?WSDL&lc_version=9.0.1 -
In the Namespace field, type
PreLoanProcess. -
Click Go and then click OK.
hiro-xp with the IP address of the J2EE application server hosting AEM Forms. The lc_version option ensures that AEM Forms functionality, such as MTOM, is available. Without specifying the lc_versionoption, you cannot invoke AEM Forms using MTOM. (See Invoking AEM Forms using MTOM.)Create an ASP page that invokes FirstAppSolution/PreLoanProcess create-an-asp-page-that-invokes-firstappsolution-preloanprocess
Within the ASP.NET project, add a web form (an ASPX file) that is responsible for displaying an HTML page to the loan applicant. The web form is based on a class that is derived from System.Web.UI.Page. The C# application logic that invokes FirstAppSolution/PreLoanProcess is in the Button1_Click method (this button represents the Submit Application button).
The following illustration shows the ASP.NET application
The following table lists the controls that are part of this ASP.NET application.
The application logic that is part of the ASP.NET application must dynamically create an XML data source to pass to the FirstAppSolution/PreLoanProcess process. The values that the applicant entered into the HTML page must be specified within the XML data source. These data values are merged into the form when the form is viewed in Workspace. The classes in the System.Xml namespace are used to create the XML data source.
When invoking a process that requires XML data from an ASP.NET application, an XML data type is available for you to use. That is, you cannot pass a System.Xml.XmlDocument instance to the process. The fully qualified name of this XML instance to pass to the process is InvokePreLoanProcess.PreLoanProcess.XML. Convert the System.Xml.XmlDocument instance to InvokePreLoanProcess.PreLoanProcess.XML. You can perform this task by using the following code.
//Create the XML to pass to the FirstAppSolution/PreLoanProcess process
XmlDocument myXML = CreateXML(userName, phone, amount);
//Convert the XML to a InvokePreLoanProcess.PreLoanProcess.XML instance
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
myXML.WriteTo(xw);
InvokePreLoanProcess.PreLoanProcess.XML inXML = new XML();
inXML.document = sw.ToString();
To create an ASP page that invokes the FirstAppSolution/PreLoanProcess process, perform the following tasks in the Button1_Click method:
-
Create a
FirstAppSolution_PreLoanProcessClientobject by using its default constructor. -
Create a
FirstAppSolution_PreLoanProcessClient.Endpoint.Addressobject by using theSystem.ServiceModel.EndpointAddressconstructor. Pass a string value that specifies the WSDL to the AEM Forms service and the encoding type:code language-java https://hiro-xp:8080/soap/services/FirstAppSolution/PreLoanProcess?blob=mtomYou do not need to use the
lc_versionattribute. This attribute is used when you create a service reference. However, ensure that you specify?blob=mtom.note note NOTE Replace hiro-xp* with the IP address of the J2EE application server hosting AEM Forms. * -
Create a
System.ServiceModel.BasicHttpBindingobject by getting the value of theFirstAppSolution_PreLoanProcessClient.Endpoint.Bindingdata member. Cast the return value toBasicHttpBinding. -
Set the
System.ServiceModel.BasicHttpBindingobject’sMessageEncodingdata member toWSMessageEncoding.Mtom. This value ensures that MTOM is used. -
Enable basic HTTP authentication by performing the following tasks:
- Assign the AEM forms user name to the data member
FirstAppSolution_PreLoanProcessClient.ClientCredentials.UserName.UserName. - Assign the corresponding password value to the data member
FirstAppSolution_PreLoanProcessClient.ClientCredentials.UserName.Password. - Assign the constant value
HttpClientCredentialType.Basicto the data memberBasicHttpBindingSecurity.Transport.ClientCredentialType. - Assign the constant value
BasicHttpSecurityMode.TransportCredentialOnlyto the data memberBasicHttpBindingSecurity.Security.Mode.
The following code example shows these tasks.
code language-as3 //Enable BASIC HTTP authentication BasicHttpBinding b = (BasicHttpBinding)mortgageClient.Endpoint.Binding; b.MessageEncoding = WSMessageEncoding.Mtom; mortgageClient.ClientCredentials.UserName.UserName = "administrator"; mortgageClient.ClientCredentials.UserName.Password = "password"; b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; b.MaxReceivedMessageSize = 2000000; b.MaxBufferSize = 2000000; b.ReaderQuotas.MaxArrayLength = 2000000; - Assign the AEM forms user name to the data member
-
Retrieve the name, phone, and amount values that the user entered into the web page. Use these values to dynamically create an XML data source that is sent to the
FirstAppSolution/PreLoanProcessprocess. Create aSystem.Xml.XmlDocumentthat represents the XML data source to pass to the process (this application logic is shown in the following code example). -
Convert the
System.Xml.XmlDocumentinstance toInvokePreLoanProcess.PreLoanProcess.XML(this application logic is shown in the following code example). -
Invoke the
FirstAppSolution/PreLoanProcessprocess by invoking theFirstAppSolution_PreLoanProcessClientobject’sinvoke_Asyncmethod. This method returns a string value that represents the invocation identifier value of the long-lived process. -
Create a
JobManagerClientby using is constructor. (Ensure that you have set a service reference to the Job Manager service.) -
Repeat steps 1-5. Specify the following URL for step 2:
https://hiro-xp:8080/soap/services/JobManager?blob=mtom. -
Create a
JobIdobject by using its constructor. -
Set the
JobIdobject’siddata member with the return value of theFirstAppSolution_PreLoanProcessClientobject’sinvoke_Asyncmethod. -
Assign the
valuetrue to theJobIdobject’spersistentdata member. -
Create a
JobStatusobject by invoking theJobManagerServiceobject 'sgetStatusmethod and passing theJobIdobject. -
Get the status value by retrieving the value of the
JobStatusobject’sstatusCodedata member. -
Assign the invocation identifier value to the
LabelJobID.Textfield. -
Assign the status value to the
LabelStatus.Textfield.
Quick Start: Invoking a long-lived process using the web service API quick-start-invoking-a-long-lived-process-using-the-web-service-api
The following C# code example invokes the FirstAppSolution/PreLoanProcessprocess.
???/**
* Ensure that you create a .NET project that uses
* MS Visual Studio 2008 and version 3.5 of the .NET
* framework. This is required to invoke a
* AEM Forms service using MTOM.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.IO;
//A reference to FirstAppSolution/PreLoanProcess
using InvokePreLoanProcess.PreLoanProcess;
//A reference to JobManager service
using InvokePreLoanProcess.JobManager;
namespace InvokePreLoanProcess
{
public partial class _Default : System.Web.UI.Page
{
//This method is called when the Submit Application button is
//Clicked
protected void Button1_Click(object sender, EventArgs e)
{
//Create a FirstAppSolution_PreLoanProcessClient object
FirstAppSolution_PreLoanProcessClient mortgageClient = new FirstAppSolution_PreLoanProcessClient();
mortgageClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://hiro-xp:8080/soap/services/FirstAppSolution/PreLoanProcess?blob=mtom");
//Enable BASIC HTTP authentication
BasicHttpBinding b = (BasicHttpBinding)mortgageClient.Endpoint.Binding;
b.MessageEncoding = WSMessageEncoding.Mtom;
mortgageClient.ClientCredentials.UserName.UserName = "administrator";
mortgageClient.ClientCredentials.UserName.Password = "password";
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
b.MaxReceivedMessageSize = 2000000;
b.MaxBufferSize = 2000000;
b.ReaderQuotas.MaxArrayLength = 2000000;
//Retrieve values that user entered into the web page
String userName = TextBoxName.Text;
String phone = TextBoxPhone.Text;
String amount = TextBoxAmount.Text;
//Create the XML to pass to the FirstAppSolution/PreLoanProcess process
XmlDocument myXML = CreateXML(userName, phone, amount);
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
myXML.WriteTo(xw);
InvokePreLoanProcess.PreLoanProcess.XML inXML = new XML();
inXML.document = sw.ToString();
//INvoke the FirstAppSolution/PreLoanProcess process
String invocationID = mortgageClient.invoke_Async(inXML);
//Create a JobManagerClient object to obtain the status of the long-lived operation
JobManagerClient jobManager = new JobManagerClient();
jobManager.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://hiro-xp:8080/soap/services/JobManager?blob=mtom");
//Enable BASIC HTTP authentication
BasicHttpBinding b1 = (BasicHttpBinding)jobManager.Endpoint.Binding;
b1.MessageEncoding = WSMessageEncoding.Mtom;
jobManager.ClientCredentials.UserName.UserName = "administrator";
jobManager.ClientCredentials.UserName.Password = "password";
b1.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
b1.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
b1.MaxReceivedMessageSize = 2000000;
b1.MaxBufferSize = 2000000;
b1.ReaderQuotas.MaxArrayLength = 2000000;
//Create a JobID object that represents the status of the
//long-lived operation
JobId jobId = new JobId();
jobId.id = invocationID;
jobId.persistent = true;
JobStatus jobStatus = jobManager.getStatus(jobId);
System.Int16 val2 = jobStatus.statusCode;
LabelJobID.Text = "The job status identifier value is " + invocationID;
LabelStatus.Text = "The status of the long-lived operation is " + getJobDescription(val2);
}
private static XmlDocument CreateXML(String name, String phone, String amount)
{
//This method dynamically creates a DDX document
//to pass to the FirstAppSolution/PreLoanProcess process
XmlDocument xmlDoc = new XmlDocument();
//Create the root element and append it to the XML DOM
System.Xml.XmlElement root = xmlDoc.CreateElement("LoanApp");
xmlDoc.AppendChild(root);
//Create the Name element
XmlElement nameElement = xmlDoc.CreateElement("Name");
nameElement.AppendChild(xmlDoc.CreateTextNode(name));
root.AppendChild(nameElement);
//Create the LoanAmount element
XmlElement LoanAmount = xmlDoc.CreateElement("LoanAmount");
LoanAmount.AppendChild(xmlDoc.CreateTextNode(amount));
root.AppendChild(LoanAmount);
//Create the PhoneOrEmail element
XmlElement PhoneOrEmail = xmlDoc.CreateElement("PhoneOrEmail");
PhoneOrEmail.AppendChild(xmlDoc.CreateTextNode(phone));
root.AppendChild(PhoneOrEmail);
//Create the ApprovalStatus element
XmlElement ApprovalStatus = xmlDoc.CreateElement("ApprovalStatus");
ApprovalStatus.AppendChild(xmlDoc.CreateTextNode("PENDING APPROVAL"));
root.AppendChild(ApprovalStatus);
//Return the XmlElement instance
return xmlDoc;
}
//Returns the String value of the Job Manager status code
private String getJobDescription(int val)
{
switch(val)
{
case 0:
return "JOB_STATUS_UNKNOWN";
case 1:
return "JOB_STATUS_QUEUED";
case 2:
return "JOB_STATUS_RUNNING";
case 3:
return "JOB_STATUS_COMPLETED";
case 4:
return "JOB_STATUS_FAILED";
case 5:
return "JOB_STATUS_COMPLETED";
case 6:
return "JOB_STATUS_SUSPENDED";
case 7:
return "JOB_STATUS_COMPLETE_REQUESTED";
case 8:
return "JOB_STATUS_TERMINATE_REQUESTED";
case 9:
return "JOB_STATUS_SUSPEND_REQUESTED";
case 10:
return "JOB_STATUS_RESUME_REQUESTED";
}
return "";
}
}
}
Run the ASP.NET application run-the-asp-net-application
After you compile and deploy your ASP.NET application, you can execute it using a web browser. Assuming the name of the ASP.NET project is InvokePreLoanProcess, specify the following URL within a web browser:
*http://localhost:1629/InvokePreLoanProcess/*Default.aspx
where localhost is the name of the web server hosting the ASP.NET project and 1629 is the port number. When you compile and build your ASP.NET application, Microsoft Visual Studio, automatically deploys it.
Creating a client application built with Flex that invokes a human-centric long-lived process creating-a-client-application-built-with-flex-that-invokes-a-human-centric-long-lived-process
You can create a client application built with Flex to invoke the FirstAppSolution/PreLoanProcess process. This application uses Remoting to invoke the FirstAppSolution/PreLoanProcess process. (See Invoking AEM Forms using (Deprecated for AEM forms) AEM Forms Remoting.)
The following illustration shows a client application built with Flex collecting data from an end user. The data is placed into an XML data source and sent to the process.
Notice after the process is invoked, an invocation identifier value is displayed. An invocation identifier value is created as part of a record that tracks the status of the long-lived process.
The client application built with Flex performs the following tasks:
- Retrieves the values that the user entered into the web page.
- Dynamically creates an XML data source that is passed to the FirstAppSolution/PreLoanProcess process. The three values are specified in the XML data source.
- Invokes the FirstAppSolution/PreLoanProcess process by using Remoting.
- Returns the invocation identifier value of the long-lived process.
Summary of steps summary_of_steps-2
To create a client application built with Flex that is able to invoke the FirstAppSolution/PreLoanProcess process, perform the following steps:
-
Start a new Flex project.
-
Include the adobe-remoting-provider.swc file in your project’s class path. (See Including the AEM Forms Flex library file.)
-
Create a
mx:RemoteObjectinstance through either ActionScript or MXML. (See Creating a mx:RemoteObject instance) -
Set up a
ChannelSetinstance to communicate with AEM Forms, and associate it with themx:RemoteObjectinstance. (See Create a Channel to AEM Forms.) -
Call the ChannelSet’s
loginmethod or the service’ssetCredentialsmethod to specify the user identifier value and password. (See Using single sign-on.) -
Create the XML data source to pass to the
FirstAppSolution/PreLoanProcessprocess by creating an XML instance. (This application logic is shown in the following code example.) -
Create an object of type Object by using its constructor. Assign the XML to the object by specifying the name of the process’s input parameter, as shown in the following code:
code language-csharp //Get the XML data to pass to the AEM Forms process var xml:XML = createXML(); var params:Object = new Object(); params["formData"]=xml; -
Invoke the
FirstAppSolution/PreLoanProcessprocess by calling themx:RemoteObjectinstance’sinvoke_Asyncmethod. Pass theObjectthat contains the input parameter. (See Passing input values.) -
Retrieve the invocation identification value that is returned from a long-lived process, as shown in the following code:
code language-csharp // Handles async call that invokes the long-lived process private function resultHandler(event:ResultEvent):void { ji = event.result as JobId; jobStatusDisplay.text = "Job Status ID: " + ji.jobId as String; }
Invoking a long-lived process using Remoting invoking-a-long-lived-process-using-remoting
The following Flex code example invokes the FirstAppSolution/PreLoanProcess process.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns="*" backgroundColor="#FFFFFF"
creationComplete="initializeChannelSet();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import flash.net.navigateToURL;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.collections.ArrayCollection;
import mx.rpc.livecycle.JobId;
import mx.rpc.livecycle.JobStatus;
import mx.rpc.livecycle.DocumentReference;
import mx.formatters.NumberFormatter;
// Holds the job ID returned by LC.JobManager
private var ji:JobId;
private function initializeChannelSet():void
{
var cs:ChannelSet= new ChannelSet();
cs.addChannel(new AMFChannel("remoting-amf", "https://hiro-xp:8080/remoting/messagebroker/amf"));
LC_MortgageApp.setCredentials("tblue", "password");
LC_MortgageApp.channelSet = cs;
}
private function submitApplication():void
{
//Get the XML data to pass to the AEM Forms process
var xml:XML = createXML();
var params:Object = new Object();
params["formData"]=xml;
LC_MortgageApp.invoke_Async(params);
}
// Handles async call that invokes the long-lived process
private function resultHandler(event:ResultEvent):void
{
ji = event.result as JobId;
jobStatusDisplay.text = "Job Status ID: " + ji.jobId as String;
}
private function createXML():XML
{
//Calculate the Mortgage value to place in the XML data
var propertyPrice:String = txtAmount.text ;
var name:String = txtName.text ;
var phone:String = txtPhone.text ;;
var model:XML =
<LoanApp>
<Name>{name}</Name>
<LoanAmount>{propertyPrice}</LoanAmount>
<PhoneOrEmail>{phone}</PhoneOrEmail>
<ApprovalStatus>PENDING APPROVAL</ApprovalStatus>
</LoanApp>
return model;
}
]]>
</mx:Script>
<!-- Declare the RemoteObject and set its destination to the mortgage-app remoting endpoint defined in AEM Forms. -->
<mx:RemoteObject id="LC_MortgageApp" destination="FirstAppSolution/PreLoanProcess" result="resultHandler(event);">
<mx:method name="invoke_Async" result="resultHandler(event)"/>
</mx:RemoteObject>
<mx:Grid x="229" y="186">
<mx:GridRow width="100%" height="100%">
<mx:GridItem width="100%" height="100%">
<mx:Image>
<mx:source>file:///D|/LiveCycle_9/FirstApp/financeCorpLogo.jpg</mx:source>
</mx:Image>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:Label text="Flex Loan Application Page" fontSize="20"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%" height="100%">
<mx:GridItem width="100%" height="100%">
<mx:Label text="Name:" fontSize="12" fontWeight="bold"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:TextInput id="txtName"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:Button label="Submit Application" click="submitApplication()"/>
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%" height="100%">
<mx:GridItem width="100%" height="100%">
<mx:Label text="Phone/Email:" fontSize="12" fontWeight="bold"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:TextInput id="txtPhone"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%" height="100%">
<mx:GridItem width="100%" height="100%">
<mx:Label text="Amount:" fontSize="12" fontWeight="bold"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:TextInput id="txtAmount"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%" height="100%">
<mx:GridItem width="100%" height="100%">
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
<mx:Label text="Label" id="jobStatusDisplay" enabled="true" fontSize="12" fontWeight="bold"/>
</mx:GridItem>
<mx:GridItem width="100%" height="100%">
</mx:GridItem>
</mx:GridRow>
</mx:Grid>
</mx:Application>