An OLTP message-driven bean (CCI) receives the inbound message as the record
parameter of the onMessage()
method of the MessageListener
interface. The received object is of type BCRecord
and contains an OltpMessage
object. From the OltpMessage
object you can retrieve an OltpMessageContext
object that in turn contains attributes of the received message and also serves dialog OLTP message-driven beans as a factory for creating a response message:
Extract the
OltpMessage
object from theBCRecord
object:OltpMessage inMsg = ((BCRecord)record).getOltpMessage();
Set up the message context:
String inMsgTxt;
OltpMessageContext oltpMsgCtx = inMsg.getMessageContext();
Access the message content:
The
OltpMessage
object allows access to the message content which may be processed in the form ofOltpMessageRecord
orOltpMessagePart
objects. From these objects, you can retrieve the message content as an object of one of the following types:byte[]
String
ByteContainer
In the case of
OltpMessagePart
objects you specify:if (inMsg.countMessageParts() > 0) { OltpMessagePart inMsgPart; Iterator it<OltpMessagePart> = inMsg.getMessageParts(); for ( ; it.hasNext(); ) { inMsgPart = it.next(); inMsgTxt = inMsgPart.getText(); } } }
In the case of
OltpMessageRecord
objects you specify:if (inMsg.countMessageRecords() > 0) { OltpMessageRecord inMsgRec; Iterator it<OltpMessageRecord> = inMsg.getMessageRecords(); for ( ; it.hasNext(); ) { inMsgRec = (OltpMessageRecord) it.next(); inMsgTxt = inMsgRec.getText(); } }
Create an
OLTPMessage
object for the reply message:An OLTP message-driven bean for dialog communication uses the
OltpMessageContext
interface to create anOltpMessage
object for the reply message:OltpMessage outMsg = oltpMsgCtx.createMessage();
The
OltpMessage
object needs to be populated with the reply message content. You can do this in different ways usingOltpMessageRecord
and/orOltpMessagePart
objects.In the case of
OltpMessagePart
objects you specify:OltpMessagePart outMsgPart = outMsg.createMessagePart(); outMsgPart.setText("reply"); outMsg.addMessagePart(outMsgPart);
In the case of
OltpMessageRecord
objects you specify:OltpMessageRecord outMsgRec = outMsg.createMessageRecord(""); outMsgRec.setText("reply"); outMsg.addMessageRecord(outMsgRec);
Before return, the reply message needs to be set in the
BCRecord
object which is subsequently returned from this method:((BCRecord)record).setOltpMessage(outMsg);
You will find a code sample in Example 18 in Code samples for inbound communication .