您可以通过编程方式调用在Workbench中使用以下客户端应用程序创建的以人为中心的长期进程:
调用的长期进程名为 FirstAppSolution/PreLoanProcess. 您可以按照中指定的教程来创建此流程 创建您的第一个AEM Forms应用程序.
以人为中心的流程涉及用户可以使用工作区来响应的任务。 例如,使用Workbench,您可以创建一个流程,让银行经理批准或拒绝贷款申请。 下图显示了此过程 FirstAppSolution/PreLoanProcess.
此 FirstAppSolution/PreLoanProcess 进程接受名为的输入参数 formData 其数据类型是XML。 XML数据与名为的表单设计合并 PreLoanForm.xdp. 下图显示了一个表单,该表单表示分配给用户以批准或拒绝贷款申请的任务。 用户通过使用Workspace批准或拒绝应用程序。 Workspace用户可以通过单击下图中显示的“批准”按钮来批准贷款请求。 同样,用户可以通过单击拒绝按钮来拒绝贷款请求。
系统会异步调用长期进程,但无法同步调用该进程,原因如下:
在调用长期进程时,AEM Forms会在创建记录过程中创建一个调用标识符值。 该记录跟踪长期过程的状态,并存储在AEM Forms数据库中。 使用调用标识符值,您可以跟踪长生命周期进程的状态。 此外,可以使用进程调用标识符值执行Process Manager操作,如终止正在运行的进程实例。
在调用短期进程时,AEM Forms不会创建调用标识符值或记录。
此 FirstAppSolution/PreLoanProcess
当申请人提交以XML数据表示的申请时,将调用流程。 输入进程变量的名称为 formData
并且其数据类型为XML。 在本讨论中,假设使用以下XML数据作为 FirstAppSolution/PreLoanProcess
进程。
<?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数据必须与进程中使用的表单中的字段匹配。 否则,数据不会显示在表单中。 所有调用 FirstAppSolution/PreLoanProcess
进程必须传递此XML数据源。 在中创建的应用程序 调用以人为中心的长期进程 根据用户输入到Web客户端中的值动态创建XML数据源。
使用客户端应用程序,您可以发送 FirstAppSolution/PreLoanProcess 处理所需的XML数据。 长时间进程会返回调用标识符值作为其返回值。 下图显示了调用*FirstAppSolution/PreLoanProcess长期进程的客户端应用程序。 客户端应用程序发送XML数据,并获取代表调用标识符值的字符串值。
另请参阅
创建可调用以人为中心的长期进程的ASP.NET Web应用程序
创建使用Flex构建的客户端应用程序,该应用程序调用以人为中心的长期过程
您可以创建基于Web的应用程序,该应用程序使用Java servlet调用 FirstAppSolution/PreLoanProcess
进程。 要从Java servlet调用此进程,请使用Java servlet中的调用API。 (请参阅 使用Java API调用AEM Forms.)
下图显示了一个基于Web的客户端应用程序,该应用程序可发布姓名、电话(或电子邮件)和金额值。 当用户单击“提交应用程序”按钮时,这些值将发送到Java servlet。
Java servlet执行以下任务:
要创建基于Web的应用程序,请调用 FirstAppSolution/PreLoanProcess
,请执行以下步骤:
其中某些步骤取决于部署AEM Forms的J2EE应用程序。 例如,用于部署WAR文件的方法取决于您使用的J2EE应用程序服务器。 我们假定AEM Forms部署在JBoss®上。
创建Web应用程序的第一步是创建Web项目。 本文档所基于的Java IDE是Eclipse 3.3。使用Eclipse IDE创建一个Web项目,并将所需的JAR文件添加到您的项目中。 添加名为的HTML页面 index.html 和一个Java servlet添加到您的项目中。
以下列表指定要包含在Web项目中的JAR文件:
有关这些JAR文件的位置,请参见 包括AEM Forms Java库文件.
J2EE.jar文件定义Java servlet使用的数据类型。 您可以从部署AEM Forms的J2EE应用程序服务器获取此JAR文件。
创建Web项目
InvokePreLoanProcess
(以了解项目名称),然后单击 完成.将所需的JAR文件添加到项目中
InvokePreLoanProcess
项目并选择 属性.将Java servlet添加到您的项目
InvokePreLoanProcess
项目并选择 新 > 其他.SubmitXML
获取servlet的名称,然后单击 完成.将HTML页添加到您的项目
InvokePreLoanProcess
项目并选择 新 > 其他.index.html
文件名,然后单击 完成.有关创建调用SubmitXML Java Servlet的HTML内容的信息,请参见 为Web应用程序创建网页.
创建调用 FirstAppSolution/PreLoanProcess
从Java Servlet中进行处理。 以下代码显示了 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
}
通常,您不会将客户端代码放入Java servlet的 doGet
或 doPost
方法。 更好的编程做法是将此代码放在单独的类中。 然后,从 doPost
方法(或 doGet
方法),并调用适当的方法。 但是,为了代码简洁,代码示例将保持最小,并放在 doPost
方法。
要调用 FirstAppSolution/PreLoanProcess
使用调用API进行处理,执行以下任务:
在Java项目的类路径中包含客户端JAR文件,例如adobe-livecycle-client.jar。 有关这些文件位置的信息,请参见 包括AEM Forms Java库文件.
检索从“HTML”页面提交的姓名、电话和金额值。 使用这些值可动态创建发送到 FirstAppSolution/PreLoanProcess
进程。 您可以使用 org.w3c.dom
用于创建XML数据源的类(以下代码示例中显示了此应用程序逻辑)。
创建 ServiceClientFactory
包含连接属性的对象。 (请参阅 设置连接属性.)
创建 ServiceClient
对象,使用它的构造函数传递 ServiceClientFactory
对象。 A ServiceClient
对象允许您调用服务操作。 它处理查找、调度和路由调用请求等任务。
创建 java.util.HashMap
对象。
调用 java.util.HashMap
对象的 put
方法,用于将每个输入参数传递到长生命周期进程。 确保指定进程的输入参数的名称。 因为 FirstAppSolution/PreLoanProcess
进程需要一个类型为的输入参数 XML
(已命名 formData
),则只需调用 put
方法一次。
//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);
创建 InvocationRequest
对象 ServiceClientFactory
对象的 createInvocationRequest
方法,并传递以下值:
FirstAppSolution/PreLoanProcess
进程,指定 FirstAppSolution/PreLoanProcess
.invoke
.java.util.HashMap
包含服务操作所需的参数值的对象。false
,这将创建异步请求(此值适用于调用长生命周期进程)。通过将值true作为createInvocationRequest方法的第四个参数传递,可以调用短暂的进程。 传递值true会创建同步请求。
AEM Forms通过调用 ServiceClient
对象的 invoke
方法和传递 InvocationRequest
对象。 此 invoke
方法返回 InvocationReponse
对象。
长时间进程会返回表示调用标识值的字符串值。 通过调用 InvocationReponse
对象的 getInvocationId
方法。
//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();
将调用标识值写入客户端Web浏览器。 您可以使用 java.io.PrintWriter
实例以将此值写入客户端Web浏览器。
以下Java代码示例表示调用 FirstAppSolution/PreLoanProcess
进程。
/*
* 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 located 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 new 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;
}
}
此 index.html Web页提供了一个入口点,指向调用 FirstAppSolution/PreLoanProcess
进程。 此网页是一个基本HTML表单,其中包含HTML表单和提交按钮。 当用户单击提交按钮时,表单数据将发布到 SubmitXML
Java servlet。
Java Servlet通过使用以下Java代码捕获从HTML页发布的数据:
//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");
以下HTML代码表示在设置开发环境期间创建的index.html文件。 (请参阅 创建Web项目.)
<!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>
部署调用 FirstAppSolution/PreLoanProcess
进程,将您的Web应用程序打包到WAR文件。 确保组件的业务逻辑所依赖的外部JAR文件(如adobe-livecycle-client.jar和adobe-usermanager-client.jar)也包含在WAR文件中。
下图显示了Eclipse项目的内容,该内容已打包到WAR文件中。
在上图中,JPG文件可以由任何JPG图像文件替换。
将Web应用程序打包到WAR文件:
InvokePreLoanProcess
项目并选择 导出 > WAR文件.InvokePreLoanProcess
Java项目的名称。PreLoanProcess.war
对于文件名,指定WAR文件的位置,然后单击“完成”。将WAR文件部署到部署AEM Forms的J2EE应用程序服务器。 要将WAR文件部署到J2EE应用程序服务器,请将WAR文件从导出路径复制到 [AEM Forms Install]\Adobe\Adobe Experience Manager Forms\jboss\server\lc_turnkey\deploy
.
如果未在JBoss上部署AEM Forms,则必须按照托管AEM Forms的J2EE应用程序服务器来部署WAR文件。
部署Web应用程序后,可以使用Web浏览器对其进行测试。 假定您使用的计算机与托管AEM Forms的计算机相同,则可以指定以下URL:
http://localhost:8080/PreLoanProcess/index.html
在HTML表单字段中输入值,然后单击“提交申请”按钮。 如果出现问题,请参阅J2EE应用程序服务器的日志文件。
要确认Java应用程序调用了该进程,请启动Workspace并接受贷款。
ASP.NET您可以创建一个调用 FirstAppSolution/PreLoanProcess
进程。 要从ASP.NET应用程序调用此进程,请使用Web服务。 (请参阅 使用Web服务调用AEM Forms.)
下图显示了一个ASP.NET客户端应用程序,该应用程序从最终用户获取数据。 数据将放入XML数据源并发送到 FirstAppSolution/PreLoanProcess
在用户单击“提交申请”按钮时进行处理。
请注意,调用进程后,将显示调用标识符值。 调用标识符值是作为跟踪长生命周期进程状态的记录的一部分创建的。
ASP.NET应用程序执行以下任务:
要创建能够调用FirstAppSolution/PreLoanProcess进程的ASP.NET应用程序,请执行以下步骤:
创建Microsoft .NET C# ASP.NET Web应用程序。 下图显示了名为的ASP.NET项目的内容 InvokePreLoanProcess.
请注意,在“服务参考”下,有两个项目。 第一个项目名为* JobManager*。 此参考使ASP.NET应用程序能够调用作业管理器服务。 此服务返回有关长生命周期进程状态的信息。 例如,如果进程当前正在运行,则此服务将返回一个数字值,用于指定进程当前正在运行。 第二个引用名为PreLoanProcess. 此服务引用表示对* FirstAppSolution/PreLoanProcess *进程的引用。 创建服务引用后,与AEM Forms服务关联的数据类型便可在.NET项目中使用。
创建ASP.NET项目:
添加服务引用:
在“项目”菜单中,选择 添加服务引用.
在 地址 对话框,指定Job Manager服务的WSDL。
https://hiro-xp:8080/soap/services/JobManager?WSDL&lc_version=9.0.1
在“命名空间”字段中,键入 JobManager
.
单击 开始然后单击确定.
在 项目 菜单,选择 添加服务引用.
在 地址 对话框中,指定FirstAppSolution/PreLoanProcess进程的WSDL。
https://hiro-xp:8080/soap/services/FirstAppSolution/PreLoanProcess?WSDL&lc_version=9.0.1
在“命名空间”字段中,键入 PreLoanProcess
.
单击 开始然后单击确定.
Replace hiro-xp
,其中包含托管AEM Forms的J2EE应用程序服务器的IP地址。 此 lc_version
选项可确保AEM Forms功能(如MTOM)可用。 不指定 lc_version
选项,则无法使用MTOM调用AEM Forms。 (请参阅 使用MTOM调用AEM Forms.)
在ASP.NET项目中,添加一个Web窗体(一个ASPX文件),负责向贷款申请人显示HTML页。 Web窗体基于派生自的类 System.Web.UI.Page
. 调用的C#应用程序逻辑 FirstAppSolution/PreLoanProcess
位于 Button1_Click
方法(此按钮表示“提交申请”按钮)。
下图显示了ASP.NET应用程序
下表列出了属于此ASP.NET应用程序一部分的控件。
控件名称 |
描述 |
---|---|
TextBoxName |
指定客户的名字和姓氏。 |
TextBoxPhone |
指定客户的电话或电子邮件地址。 |
文本框金额 |
指定贷款金额。 |
Button1 |
表示“提交申请”按钮。 |
标签作业ID |
指定调用标识符值的值的标签控件。 |
标签状态 |
一个标签控件,它指定作业状态的值。 此值通过调用作业管理器服务进行检索。 |
属于ASP.NET应用程序一部分的应用程序逻辑必须动态创建一个XML数据源以传递到 FirstAppSolution/PreLoanProcess
进程。 申请人输入到HTML页中的值必须在XML数据源中指定。 在Workspace中查看表单时,这些数据值将合并到表单中。 位于 System.Xml
命名空间用于创建XML数据源。
在调用需要来自ASP.NET应用程序的XML数据的进程时,可以使用XML数据类型。 也就是说,不能传递 System.Xml.XmlDocument
实例到进程。 要传递给进程的此XML实例的完全限定名是 InvokePreLoanProcess.PreLoanProcess.XML
. 转换 System.Xml.XmlDocument
实例到 InvokePreLoanProcess.PreLoanProcess.XML
. 您可以使用以下代码执行此任务。
//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();
创建调用 FirstAppSolution/PreLoanProcess
流程,在 Button1_Click
方法:
创建 FirstAppSolution_PreLoanProcessClient
对象。
创建 FirstAppSolution_PreLoanProcessClient.Endpoint.Address
对象 System.ServiceModel.EndpointAddress
构造函数。 将指定WSDL的字符串值传递给AEM Forms服务和编码类型:
https://hiro-xp:8080/soap/services/FirstAppSolution/PreLoanProcess?blob=mtom
您无需使用 lc_version
属性。 创建服务引用时使用此属性。 但是,请确保您指定 ?blob=mtom
.
Replace hiro-xp
包含托管AEM Forms的J2EE应用程序服务器的IP地址。
创建 System.ServiceModel.BasicHttpBinding
对象,方法是获取 FirstAppSolution_PreLoanProcessClient.Endpoint.Binding
数据成员。 将返回值强制转换为 BasicHttpBinding
.
设置 System.ServiceModel.BasicHttpBinding
对象的 MessageEncoding
数据成员至 WSMessageEncoding.Mtom
. 此值可确保使用MTOM。
通过执行以下任务启用基本HTTP身份验证:
FirstAppSolution_PreLoanProcessClient.ClientCredentials.UserName.UserName
.FirstAppSolution_PreLoanProcessClient.ClientCredentials.UserName.Password
.HttpClientCredentialType.Basic
到数据成员 BasicHttpBindingSecurity.Transport.ClientCredentialType
.BasicHttpSecurityMode.TransportCredentialOnly
到数据成员 BasicHttpBindingSecurity.Security.Mode
.以下代码示例显示了这些任务。
//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;
检索用户在网页中输入的姓名、电话和金额值。 使用这些值可动态创建发送到 FirstAppSolution/PreLoanProcess
进程。 创建 System.Xml.XmlDocument
表示要传递给进程的XML数据源(以下代码示例中显示了此应用程序逻辑)。
转换 System.Xml.XmlDocument
实例到 InvokePreLoanProcess.PreLoanProcess.XML
(此应用程序逻辑如下面的代码示例所示)。
调用 FirstAppSolution/PreLoanProcess
通过调用 FirstAppSolution_PreLoanProcessClient
对象的 invoke_Async
方法。 此方法返回一个字符串值,表示长生命周期进程的调用标识符值。
创建 JobManagerClient
通过使用is构造函数。 (确保已设置作业管理器服务的服务引用。)
重复步骤1-5。 为步骤2指定以下URL: https://hiro-xp:8080/soap/services/JobManager?blob=mtom
.
创建 JobId
对象。
设置 JobId
对象的 id
返回值为的数据成员 FirstAppSolution_PreLoanProcessClient
对象的 invoke_Async
方法。
分配 value
对 JobId
对象的 persistent
数据成员。
创建 JobStatus
对象 JobManagerService
对象 getStatus
方法和传递 JobId
对象。
通过检索的值获取状态值 JobStatus
对象的 statusCode
数据成员。
将调用标识符值分配给 LabelJobID.Text
字段。
将状态值分配给 LabelStatus.Text
字段。
以下C#代码示例调用 FirstAppSolution/PreLoanProcess
进程。
???/**
* 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 "";
}
}
}
位于getJobDescription用户定义方法中的值对应于作业管理器服务返回的值。
编译和部署ASP.NET应用程序后,可以使用Web浏览器执行该应用程序。 假定ASP.NET项目的名称为 InvokePreLoanProcess,请在Web浏览器中指定以下URL:
*http://localhost:1629/InvokePreLoanProcess/*Default.aspx
其中,localhost是托管ASP.NET项目的Web服务器的名称,1629是端口号。 当您编译和构建ASP.NET应用程序Microsoft Visual Studio时,会自动部署该应用程序。
要确认ASP.NET应用程序调用了该进程,请启动Workspace并接受贷款。
您可以创建使用Flex构建的客户端应用程序,以调用 FirstAppSolution/PreLoanProcess 进程。 此应用程序使用远程处理调用 FirstAppSolution/PreLoanProcess 进程。 (请参阅 使用AEM Forms调用(已为AEM表单弃用) AEM Forms远程处理.)
下图显示了一个使用Flex构建的客户端应用程序,该应用程序从最终用户那里收集数据。 数据将放入XML数据源并发送到进程。
请注意,调用进程后,将显示调用标识符值。 调用标识符值是作为跟踪长生命周期进程状态的记录的一部分创建的。
使用Flex构建的客户端应用程序执行以下任务:
要创建使用Flex构建的能够调用FirstAppSolution/PreLoanProcess进程的客户端应用程序,请执行以下步骤:
启动新的Flex项目。
将adobe-remoting-provider.swc文件包含在项目的类路径中。 (请参阅 包含AEM Forms Flex库文件.)
创建 mx:RemoteObject
通过ActionScript或MXML实例。 (请参阅 创建mx:RemoteObject实例)
设置 ChannelSet
实例以与AEM Forms通信,并将其与 mx:RemoteObject
实例。 (请参阅 创建AEM Forms渠道.)
调用ChannelSet login
方法或服务的 setCredentials
用于指定用户标识符值和密码的方法。 (请参阅 使用单点登录.)
创建要传递给的XML数据源 FirstAppSolution/PreLoanProcess
通过创建XML实例来处理。 (此应用程序逻辑如下面的代码示例所示。)
使用对象的构造函数创建对象类型的对象。 通过指定进程的输入参数的名称将XML分配给对象,如以下代码所示:
//Get the XML data to pass to the AEM Forms process
var xml:XML = createXML();
var params:Object = new Object();
params["formData"]=xml;
调用 FirstAppSolution/PreLoanProcess
通过调用 mx:RemoteObject
实例的 invoke_Async
方法。 传递 Object
,其中包含输入参数。 (请参阅 传递输入值.)
检索从长期进程中返回的调用标识值,如以下代码所示:
// 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;
}
以下Flex代码示例调用 FirstAppSolution/PreLoanProcess
进程。
<?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>