高级自定义 > Windchill ESI 自定义 > ERP Connector 自定义 > 示例 I*E 任务:将 ESI 响应传送至 JMS 队列
示例 I*E 任务:将 ESI 响应传送至 JMS 队列
以下任务可用于将 ESI 响应传送至 JMS 队列。其工作方式与 ExportTo.xml<XXX> 中默认任务的工作方式类似。
<?xml version="1.0" standalone="yes"?>
<%@page import="com.infoengine.object.IeCollection"%>
<%@page import="com.ptc.windchill.esi.lite.util.XSLTransformer"%>
<%@page import="com.ptc.windchill.esi.tgt.ESITargetUtility"%>
<%@page import="com.ptc.windchill.esi.tgt.ESITarget"%>
<%@page import="com.ptc.windchill.esi.txn.ESITransaction"%>
<%@page import="com.ptc.windchill.esi.utl.ESIProperties"%>
<%@page import="com.ptc.windchill.esi.utl.ESIMessages"%>
<%@page import="com.ptc.windchill.esi.utl.ESIPropertyRequest"%>
<%@page import="com.ptc.windchill.esi.utl.ESILogger"%>
<%@page import="wt.fc.Persistable"%>
<%@page import="wt.federation.FederationUtilities"%>
<%@page import="wt.inf.container.WTContained"%>
<%@taglib uri="http://www.ptc.com/infoengine/taglib/core" prefix="ie"%>
<PROCESS NAME="ExportToJMS">
<DESCRIPTION>
<![CDATA[
任务的必需参数:
username - 调用任务的用户的名称。这将用于验证结果。
transaction - 表示将数据传送至输入分布目标的 ESITransaction 对象。
target - 表示对象发布到的分布目标的 ESITarget 对象。
objectId - 正在发布的主要业务对象的 UFID。
supporting-adapter - Windchill 适配器实例的名称。
type - 与正在发布的主要业务对象对应的 SOAP RPC 虚拟类名称。
]]>
</DESCRIPTION>
<%!
IeCollection response; boolean successful = true; String msg = "";
String transactionID = "-1"; String responseFilePrefix = null; ESITarget target = null;
String cls = ""; String objectID = "";
String username = "";
String content = "", transformedContent = ""; Persistable primaryBusinessObject = null;
String xslURL, xslUser, xslPassword, xslParams, queueName, priority; String CLASSNAME = "Info*Engine task in ExportToJMS.xml";
%>
ESILogger.enter(CLASSNAME); try {
<%
objectID = (String)getParam("objectId"); username = (String)getParam("username");
primaryBusinessObject = FederationUtilities.getObjectByUfid(objectID); cls = (String)getParam("type");
msg = ESIMessages.getSuccessfulPublication(primaryBusinessObject.getIdentity()); if(primaryBusinessObject != null) {
responseFilePrefix = ESIProperties.getProperty(ESIPropertyRequest.RESPONSE_FILE_PREFIX,(WTContained)primaryBusinessObject).t rim();
}else {
ESILogger.debug(CLASSNAME, "Using preference \"ESI Response File Prefix\" from Site as primaryBusinessObject is null.");
responseFilePrefix = ESIProperties.getProperty(ESIPropertyRequest.RESPONSE_FILE_PREFIX).trim();
}
ESITransaction txn = (ESITransaction)getParam("transaction"); transactionID = String.valueOf(txn.getIdNumber());
target = (ESITarget)getParam("target");
queueName = target.getSoftAttribute("queueName"); addParam("QUEUE", queueName);
priority = target.getSoftAttribute("priority"); addParam("PRIORITY", Integer.parseInt(priority));
xslURL = target.getSoftAttribute("XSL_URL"); xslUser = target.getSoftAttribute("XSL_DBUser");
xslPassword = target.getSoftAttribute("XSL_Password"); xslParams = target.getSoftAttribute("XSL_Parameters");
response = getVdb();
content = response.toXML();
if(xslURL != null && xslURL.trim().length() > 0) { if(xslParams != null && xslParams.trim().length() > 0) {
transformedContent = XSLTransformer.applyXSL(content, xslURL, xslUser, xslPassword, xslParams);
}else {
transformedContent = XSLTransformer.applyXSL(content, xslURL, xslUser, xslPassword);
}
}else {
transformedContent = content;
}
}
catch(Exception exp) { ESILogger.stackTrace(CLASSNAME, exp); exp.printStackTrace();
msg = exp.getLocalizedMessage(); successful = false;
}
if(response == null || response.getStatus() != 0) { successful = false;
ESILogger.error(CLASSNAME, "Error fetching the response collection.");
}
if(successful)
{
try {
/* If the preference "Enable Response Cache" is set to "Yes", this method would create a copy of the response at the location specified by the preference "ESI Response Cache Location" */
ESITargetUtility.cacheResponse(response, (WTContained)primaryBusinessObject, transactionID); addParam("CONTENT", transformedContent);
ESILogger.debug(CLASSNAME, "Invoking the Create-Object webject.");
%>
<ie:webject name="Create-Object" type="MSG">
<ie:param name="QUEUE" data="${@FORM[]QUEUE[]}" default="queue.sample"/>
<ie:param name="PRIORITY" data="${@FORM[]PRIORITY[]}"/>
<ie:param name="TYPE" data="TextMessage"/>
<ie:param name="DBUSER" data="admin"/>
<ie:param name="PASSWD" data="admin"/>
<ie:param name="PUT_STRING" data="${@FORM[]CONTENT[]}"/>
<ie:param name="GROUP_OUT" data="${@FORM[]group_out[0]}" default="output"/>
</ie:webject>
<% }
catch (Exception e) {
ESILogger.error(CLASSNAME, "Error while executing the Create-Object webject."); ESILogger.stackTrace(CLASSNAME, e);
e.printStackTrace();
msg = e.getLocalizedMessage(); successful = false;
}
}%>
<!-- Invoke post result processing task -->
<%
/*
Invoke this task in the following cases only
1. 响应传送失败。
2. 响应传送成功,并且首选项“启用公布结果”设置为“是”
*/
boolean invokePostResult = ESIProperties.getProperty(ESIPropertyRequest.ENABLE_POST_RESULT, true, (WTContained)primaryBusinessObject);
if( !successful || (successful && invokePostResult) ) {
ESILogger.debug(CLASSNAME, "Invoking the task in ParseAndProcessResult.xml."); try{
Task task = new Task(); task.setService(getService());
task.setTaskURI("com/ptc/windchill/esi/export/ParseAndProcessResult.xml"); task.addParam("supporting-adapter", (String)getParam("supporting-adapter")); task.addParam("target", target);
task.addParam("response", content); task.addParam("successful", successful); task.addParam("msg", msg); task.addParam("objectID", objectID); task.addParam("type", cls); task.addParam("transactionID", transactionID); task.addParam("username", username); task.invoke();
}catch (Exception ex) {
ESILogger.error(CLASSNAME, "Error while invoking the task in ParseAndProcessResult.xml."); ESILogger.stackTrace(CLASSNAME, ex);
ex.printStackTrace();
}
}
%>
</PROCESS>
这对您有帮助吗?