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
OltpMessageobject from theBCRecordobject:OltpMessage inMsg = ((BCRecord)record).getOltpMessage();Set up the message context:
String inMsgTxt;OltpMessageContext oltpMsgCtx = inMsg.getMessageContext();Access the message content:
The
OltpMessageobject allows access to the message content which may be processed in the form ofOltpMessageRecordorOltpMessagePartobjects. From these objects, you can retrieve the message content as an object of one of the following types:byte[]StringByteContainer
In the case of
OltpMessagePartobjects 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
OltpMessageRecordobjects 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
OLTPMessageobject for the reply message:An OLTP message-driven bean for dialog communication uses the
OltpMessageContextinterface to create anOltpMessageobject for the reply message:OltpMessage outMsg = oltpMsgCtx.createMessage();The
OltpMessageobject needs to be populated with the reply message content. You can do this in different ways usingOltpMessageRecordand/orOltpMessagePartobjects.In the case of
OltpMessagePartobjects you specify:OltpMessagePart outMsgPart = outMsg.createMessagePart(); outMsgPart.setText("reply"); outMsg.addMessagePart(outMsgPart);In the case of
OltpMessageRecordobjects you specify:OltpMessageRecord outMsgRec = outMsg.createMessageRecord(""); outMsgRec.setText("reply"); outMsg.addMessageRecord(outMsgRec);Before return, the reply message needs to be set in the
BCRecordobject which is subsequently returned from this method:((BCRecord)record).setOltpMessage(outMsg);
You will find a code sample in Example 12 in Code samples for inbound communication.