Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Program framework using the interface javax.resource.cci.MessageListener

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:

  1. Extract the OltpMessage object from the BCRecord object:

    OltpMessage inMsg = ((BCRecord)record).getOltpMessage();

  2. Set up the message context:

    String inMsgTxt;
    OltpMessageContext oltpMsgCtx = inMsg.getMessageContext();

  3. Access the message content:

    The OltpMessage object allows access to the message content which may be processed in the form of OltpMessageRecord or OltpMessagePart 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();
    	}
    }
    
  4. Create an OLTPMessage object for the reply message:

    An OLTP message-driven bean for dialog communication uses the OltpMessageContext interface to create an OltpMessage object for the reply message:

    OltpMessage outMsg = oltpMsgCtx.createMessage();

  5. The OltpMessage object needs to be populated with the reply message content. You can do this in different ways using OltpMessageRecord and/or OltpMessagePart 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); 
    
  6. 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 .