|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Java Plug-in and Global Environment |
« View previous topic :: View next topic » |
Author |
Message
|
EKhalil |
Posted: Thu May 06, 2004 4:13 am Post subject: Java Plug-in and Global Environment |
|
|
Voyager
Joined: 29 Apr 2003 Posts: 99 Location: Boston, MA
|
Hey,
Could someone please provide some input …
The Java Plug-in - MQInquiryNode (developed in-house) inquires on queues or other MQObjects' attributes and stores the values it retrieves in the Environment.Variables tree.
The Flow/s - MQInquiryNode is used in the Exception Handling sub flow, which is wired off the input node catch terminal.
Scenario - The message flow receives an MRM message which is too long/short for the message format specified in the statement:
CREATE LASTCHILD OF Environment.Variables.MRM_Record DOMAIN 'MRM' PARSE (bitstream(InputBody), 785, 500, 'DPDEFT807O001', 'HubReplyMessage', 'CWF').
When later attempting to reference a field within this record, a parser error is thrown indicating buffer underrun/overflow, which sends the message down the exception handling path. The first compute node in the exception handling path inserts several fields into the Environment.Variables tree, then a later trace node produces a trace of the Environment.Variables tree, including Environment.Variables.MRM_Record. Depending on the length of the message, the trace contains either the whole message (if the incoming test message was too long) or a truncated one (if too short).
Now the message is passed to the plug-in. In the plug-in, an error occurs while invoking the propagate method and the trace node following the plug-in produces a trace, which stops at Environment.Variables.MRM_Record.
The Question - How is the in-house node different from the primitives that it can not deal with the message being present in the Environment??? What exactly happens to the Environment when the CREATE/PARSE fails? I can see the overlaying MRM format in the trace, but the left over bytes are not visible. Are they in the Environment? |
|
Back to top |
|
 |
Sandman |
Posted: Thu May 13, 2004 12:14 pm Post subject: |
|
|
Centurion
Joined: 16 Oct 2001 Posts: 134 Location: Lincoln, RI
|
Anyone?  |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu May 13, 2004 12:41 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I think the answer to
Quote: |
How is the in-house node different from the primitives that it can not deal with the message being present in the Environment??? |
is that it's an in-house node, rather than an IBM developed node.
Other than that...  _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Sandman |
Posted: Thu May 13, 2004 12:46 pm Post subject: |
|
|
Centurion
Joined: 16 Oct 2001 Posts: 134 Location: Lincoln, RI
|
But we even tried commenting out the code that adds items to the Environment and simply pass the message and all its parts through unchanged. Still same problem.  |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu May 13, 2004 1:05 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Can we see the code? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Sandman |
Posted: Mon May 17, 2004 7:12 am Post subject: |
|
|
Centurion
Joined: 16 Oct 2001 Posts: 134 Location: Lincoln, RI
|
Sure. Let's start w/ this. If you'd like to see more, let me know.
Thank you!
Here's the MQInquiryNode:
Code: |
package com.XXXXX.wmqi.plugins;
import java.util.Hashtable;
import com.XXXXX.wmq.MQManagedObjectInquiry;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbInputTerminal;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbNodeInterface;
/**
* @author a4654
*
* This plugin class will query any MQ managed object and return the
* attributes in the global environment.
*/
public class MQInquiryNode extends XXXXXMbNode implements MbNodeInterface {
private static final String nodeName = "MQInquiryNode";
private final String VARIABLE_ELEMENT_NAME_TAG = "Variables";
private String objectType = "Queue";
private String objectTypeID = null;
private String objectName = null;
private String selectorFileName = "selectors.properties";
private MQManagedObjectInquiry mqMOI = null;
/**
* @see java.lang.Object#Object()
*/
public MQInquiryNode() throws Exception {
createInputTerminal("in");
createOutputTerminal("out");
createOutputTerminal("failure");
}
/**
* Method getNodeName declares the name of this node to the broker.
* @return String
*/
public static String getNodeName() {
return nodeName;
}
/**
* Method getObjectName.
* @return String
*/
public String getObjectName() {
return objectName;
}
/**
* Method setObjectName.
* @param attr
*/
public void setObjectName(String attr) {
objectName = attr;
logMessage(LOG_INFORMATIONAL_MSG, "Object Name set to " + attr, "setObjectName");
}
/**
* Method getSelectorFileName.
* @return String
*/
public String getSelectorFileName() {
return selectorFileName;
}
/**
* Method setSelectorFileName.
* @param attr
*/
public void setSelectorFileName(String attr) {
selectorFileName = attr;
logMessage(LOG_INFORMATIONAL_MSG, "Selector File Name set to " + attr, "setSelectorFileName");
}
/**
* Method getObjectType.
* @return String
*/
public String getObjectType() {
return objectType;
}
/**
* Method setObjectType.
* @param attr
* @throws Exception
*/
public void setObjectType(String attr) throws MbException {
if (getObjectType().equalsIgnoreCase("Queue")) {
setObjectTypeID(MQManagedObjectInquiry.QUEUE_OBJECT_TYPE);
}
else if (getObjectType().equalsIgnoreCase("QueueManager")) {
setObjectTypeID(MQManagedObjectInquiry.QUEUEMANAGER_OBJECT_TYPE);
}
else if (getObjectType().equalsIgnoreCase("Process")) {
setObjectTypeID(MQManagedObjectInquiry.PROCESS_OBJECT_TYPE);
}
else if (getObjectType().equalsIgnoreCase("NameList")) {
setObjectTypeID(MQManagedObjectInquiry.NAME_LIST_OBJECT_TYPE);
}
else {
throw getMbUserException("The object type " + attr + " is not a valid type.", "setObjectType");
}
objectType = attr;
logMessage(LOG_INFORMATIONAL_MSG, "Object Type set to " + attr, "setObjectType");
}
/**
* Method setObjectTypeID.
* @param objectTypeID
*/
private void setObjectTypeID(String objectTypeID) {
this.objectTypeID = objectTypeID;
logMessage(LOG_INFORMATIONAL_MSG, "Object Type ID set to " + objectTypeID, "setObjectTypeID");
}
/**
* Method getObjectTypeID.
* @return String
*/
private String getObjectTypeID() {
return objectTypeID;
}
/**
* Method getMQMOInquiry.
* @return MQManagedObjectInquiry
* @throws Exception
*/
private synchronized MQManagedObjectInquiry getMQMOInquiry() throws Exception {
if (null == mqMOI) {
mqMOI = new MQManagedObjectInquiry(getSelectorFileName(), getBroker().getQueueManagerName());
}
return mqMOI;
}
/**
* Method onDelete.
*/
public void onDelete() {
if (null != mqMOI) {
mqMOI.cleanUp();
mqMOI = null;
}
}
/**
* @see com.ibm.broker.plugin.MbNodeInterface#evaluate(MbMessageAssembly, MbInputTerminal)
*/
public void evaluate(MbMessageAssembly assembly, MbInputTerminal inputTerm) throws MbException {
Hashtable attributes = null;
try {
logMessage(LOG_INFORMATIONAL_MSG, "Starting evaluate function", "evaluate");
if (getObjectTypeID().equalsIgnoreCase(MQManagedObjectInquiry.QUEUE_OBJECT_TYPE)) {
if (null == objectName || objectName.trim().length() < 1) {
setObjectName(getQueueNameFromMessage(assembly.getMessage()));
}
}
attributes = getMQMOInquiry().getObjectAttributes(getObjectTypeID(), getObjectName());
logMessage(LOG_INFORMATIONAL_MSG, "MQ Managed Object attributes successfully retrieved", "evaluate");
MbMessage env = new MbMessage(assembly.getGlobalEnvironment());
loadElements(attributes, getElement(env.getRootElement(), VARIABLE_ELEMENT_NAME_TAG, MbElement.TYPE_NAME));
logMessage(LOG_INFORMATIONAL_MSG, "Environment successfully loaded", "evaluate");
getOutputTerminal("out").propagate(
new MbMessageAssembly(assembly, assembly.getLocalEnvironment(), env, assembly.getExceptionList(), assembly.getMessage()));
logMessage(LOG_INFORMATIONAL_MSG, "Output message successfully propogated to out terminal - exiting node now", "evaluate");
}
catch (Exception e) {
logMessage(LOG_ERROR_MSG, e.toString(), "evaluate");
if (getOutputTerminal("failure").isAttached()) {
getOutputTerminal("failure").propagate(assembly);
}
}
catch (Throwable t) {
logMessage(LOG_ERROR_MSG, "The following fatal error occurred: " + t.toString(), "evaluate");
throw getMbUserException("The following fatal error occurred: " + t.toString(), "evaluate");
}
}
/**
* Method getQueueNameFromMessage.
* @param msg The message portion of the assembly passed to the evaluate function.
* @return String
* @throws MbException
*/
protected String getQueueNameFromMessage(MbMessage msg) throws Exception {
String queueName = null;
try {
queueName = (String) msg.getRootElement().getFirstElementByPath("/MQMD/SourceQueue").getValue();
}
catch (Exception e) {
throw new Exception("Error retrieving queue name from message: " + e.toString());
}
return queueName;
}
}
|
And here's the XXXXXMBNode:
Code: |
package com.XXXXX.wmqi.plugins;
import java.util.Enumeration;
import java.util.Hashtable;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbInputTerminal;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbNode;
import com.ibm.broker.plugin.MbNodeInterface;
import com.ibm.broker.plugin.MbService;
import com.ibm.broker.plugin.MbUserException;
/**
* @author a4654
*
* This is the base class for all plugins created by XXXXX.
*/
public abstract class XXXXXMbNode extends MbNode {
public final int LOG_INFORMATIONAL_MSG = 1;
public final int LOG_WARNING_MSG = 2;
public final int LOG_ERROR_MSG = 3;
private final String ELEMENT_PATH_DELIMITER_TAG = "./";
private boolean debug = false;
/**
* @see java.lang.Object#Object()
*/
public XXXXXMbNode() throws MbException {
super();
}
/**
* The setDebug method sets whether informational messages are logged or not.
* @param attr "<b>True</b>" if informational messages are wanted or "<b>False</b>"
* if informational messages are not wanted.
*/
public void setDebug(String attr) {
setDebug(Boolean.getBoolean(attr));
}
/**
* @param attr
*/
protected void setDebug(boolean attr) {
debug = attr;
}
/**
* @return
*/
public String getDebug() {
return String.valueOf(debug);
}
/**
* The isDebug returns a boolean indicating whether informational messages are logged or not.
* @return boolean
*/
public boolean isDebug() {
return debug;
}
/**
* The logMessage method will log an informational, warning or error message based
* on the <i>msgType</i> provided.
* <ul>
* <li>Informational Message Code = 4360</li>
* <li>Warning Message Code = 4361</li>
* <li>Error Message Code = 4362</li>
* </ul>
* @param msgType Available types are:
* <ul>
* <li>LOG_INFORMATIONAL_MSG</li>
* <li>LOG_WARNING_MSG</li>
* <li>LOG_ERROR_MSG</li>
* </ul>
* @param msgText Message to be displayed in the log.
* @param functionName Name of the function in which the message was logged
*/
public void logMessage(int msgType, String msgText, String functionName) {
try {
switch (msgType) {
case LOG_INFORMATIONAL_MSG :
if (isDebug()) {
MbService.logInformation(
getClass().getName(),
functionName,
"WMQIv210",
"4360",
msgText,
new String[] { msgText });
}
break;
case LOG_WARNING_MSG :
MbService.logWarning(
getClass().getName(),
functionName,
"WMQIv210",
"4361",
msgText,
new String[] { msgText });
break;
case LOG_ERROR_MSG :
MbService.logError(
getClass().getName(),
functionName,
"WMQIv210",
"4362",
msgText,
new String[] { msgText });
break;
}
}
catch (Exception e) {
}
}
/**
* The getMbUserException returns a MbUserException with error code of 4362.
* @param errorText Text describing the error
* @param functionName Name of the function from which the error was thrown
* @return MbUserException
*/
public MbUserException getMbUserException(String errorText, String functionName) {
return new MbUserException(
getClass().getName(),
functionName,
"WMQIv210",
"4362",
errorText,
new String[] { errorText });
}
/**
* Method loadEnvironment.
* @param elements Hashtable containing all the elements to be loaded into the
* parent element <i>parentElement</>
* @param parentElement The element into which elements in <i>elements</i> will be added.
* @throws MbException
*/
protected void loadElements(Hashtable elements, MbElement parentElement) throws Exception {
String elementToAddName;
MbElement newElement;
Object elementObjectToAdd;
try {
Enumeration elementNames = elements.keys();
while (elementNames.hasMoreElements()) {
elementToAddName = (String)elementNames.nextElement();
elementObjectToAdd = elements.get(elementToAddName);
if (elementObjectToAdd.getClass().getName().indexOf("Hashtable") >= 0) {
loadElements((Hashtable)elementObjectToAdd, getElement(parentElement, elementToAddName, MbElement.TYPE_NAME));
}
else {
newElement = getElement(parentElement, elementToAddName, MbElement.TYPE_VALUE);
newElement.setValue(elements.get(elementToAddName));
}
}
}
catch (Exception e) {
throw new Exception("Error loading attributes into the environment: " + e.toString());
}
}
/**
* This method will return the first element in the <i>parentElement</i>
* with the name <i>elementName</i>. If the element named <i>elementName</i>
* is not found it will be created and returned.
* @param parentElement The parent of the element being retrieved or added
* @param elementName The name of the element being retrieved or added
* @param elementType The type of the element being added
* @return MbElement
* @throws MbException
*/
protected MbElement getElement(MbElement parentElement, String elementName, int elementType)
throws MbException {
MbElement element =
parentElement.getFirstElementByPath(ELEMENT_PATH_DELIMITER_TAG + elementName);
if (null == element) {
element = parentElement.createElementAsLastChild(elementType);
element.setName(elementName);
}
return element;
}
}
|
|
|
Back to top |
|
 |
Sandman |
Posted: Thu May 20, 2004 7:13 am Post subject: |
|
|
Centurion
Joined: 16 Oct 2001 Posts: 134 Location: Lincoln, RI
|
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|