Advanced Customization > Windchill ESI Customization > ERP Connector Customization > Sample I*E task that delivers the ESI response to a JMS queue
Sample I*E task that delivers the ESI response to a JMS queue
The following task may be used to deliver the ESI response to a JMS queue. It works on similar lines to how the default tasks in ExportTo<XXX>.xml work.
<?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[
Required parameters for task:
username - Name of the user who invoked the task. This will serve for authenticating the result.
transaction - The ESITransaction object representing the delivery of data to the input distribution target.
target - The ESITarget object representing the distribution target to which the object is to be published.
objectId - UFID of the primary business object being published.
supporting-adapter - Name of the windchill adapter instance.
type - Name of the SOAP RPC virtual class corresponding to the primary business object being published.
]]>
</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. Delivery of response failed.
2. Response delivery is successful and the preference Enable Post Resultis set to Yes.
*/
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>
Was this helpful?