How can I read the message in a JavaComputeNode

In IIB9 we have to send a a-synchronous message to IMS. But this is not supported in the IMSRequest node.

So we thought first to map the fields in a ComputeNode using ESQL. After that using a JavaComputeNode to setup a connection to IMS and send the message with the proper settings for a-synchronous messaging.

Last part (sending a message to IMS) is working in the JavaComputeNode but we can’t figure out how to retrieve the bytestream from the ESQL ComputeNode into the JavaComputeNode.

Below the code that I use with breakpoints to see if the message is received from the ComputeNode. But I can’t find it in the values that are coming in. Did anybody used this before?

public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");

// MbMessage inMessage = new MbMessage(inAssembly.getMessage());
MbMessage inMessage = inAssembly.getMessage();
MbMessage a = inAssembly.getGlobalEnvironment();
MbMessage b = inAssembly.getLocalEnvironment();
MbMessage c = inAssembly.getExceptionList();
//MbMessage outMessage = new MbMessage();

MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly, inMessage);
try {
// create new message as a copy of the input
// Add user code below
MbElement inRoot = inMessage.getRootElement();
MbElement blob = inRoot.getLastChild();
MbMessage outMessage = new MbMessage(inMessage);
MbElement outputRoot = outMessage.getRootElement();
MbElement outputBody = outputRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
byte[] myBytes=(byte[]) blob.getValue();

if (myBytes == null) {
System.out.println("NULL encountered");
} else {
String MessageBodyString = new String(myBytes);
System.out.println("bytes: " + MessageBodyString);
MbElement blobData = outputBody.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,"BLOB", MessageBodyString.getBytes());

System.out.println("converted bytes: " + blobData.toString());
}
outAssembly = new MbMessageAssembly(inAssembly, outMessage);

// SendRecord is generated using the copybook
SendRecord record = getInputRecord(myBytes);
// Populate the IMS specifications
IMSInteractionSpec iSpec = populateInteractionSpec();
// Initiate IMS Factory
IMSConnectionFactory cf = null;
IMSManagedConnectionFactory mcf = new IMSManagedConnectionFactory();
//TODO first hard code this and after that use the values from a propertyfile. But first, let's make it work!
mcf.setHostName("test.server.com");
mcf.setPortNumber(new Integer(12101));
mcf.setDataStoreName("IMT1");

MbMessage env = inAssembly.getGlobalEnvironment();
MbElement inputRequest = env.getRootElement().getFirstElementByPath("Variables\InputRequest");
String test = inputRequest.getLastChild().getFirstChild().getLastChild().getValueAsString();
System.out.println(test);

cf = (IMSConnectionFactory) mcf.createConnectionFactory();
Connection connection = cf.getConnection();
// Create IMS Interaction
IMSInteraction interaction = (IMSInteraction) connection.createInteraction();
// Execute IMS Interaction
interaction.execute(iSpec, record, null);

// End of user code
// ----------------------------------------------------------
} catch (MbException e) {
// Re-throw to allow Broker handling of MbException
throw e;
} catch (RuntimeException e) {
// Re-throw to allow Broker handling of RuntimeException
throw e;
} catch (Exception e) {
// Consider replacing Exception with type(s) thrown by user code
// Example handling ensures all exceptions are re-thrown to be handled in the flow
throw new MbUserException(this, "evaluate()", "", "", e.toString(), null);
}
// The following should only be changed
// if not propagating message to the 'out' terminal
out.propagate(outAssembly);

}

Related:

Leave a Reply