BEA Logo BEA Collaborate Release 2.0

  BEA Home  |  Events  |  Solutions  |  Partners  |  Products  |  Services  |  Download  |  Developer Center  |  WebSUPPORT

 

   Collaborate Documentation   |   Messaging   |   Previous Topic   |   Next Topic   |   Contents   |   Index

Receiving XOCP Business Messages

 

The following sections describe how to receive XOCP business messages in a c-enabler application:

 


About Receiving XOCP Business Messages

C-enabler applications must implement the onMessage method in the ConversationHandler interface to receive and process business messages. The onMessage method has the following signature.

Listing 4-1 Signature for onMessage Method

public void onMessage(XOCPMessage msg)

The c-enabler session invokes the onMessage method whenever a c-enabler receives a business message, passing the business message as an input parameter. The c-enabler application retrieves the XOCPMessage object containing the business message and then calls methods on that instance to process the message.

If a c-enabler application receives multiple business documents in a conversation, the onMessage implementation first determines the type of document received (such as a bid request or bid reward), and then processes that document accordingly.

In addition, the onMessage implementation might contain code that constructs and sends a business message. For example, a conversation participant c-enabler application might implement onMessage to receive a request, process the request, and then create and send the reply document.

 


Receiving an XOCP Business Message

Listing 4-2 describes the onMessage implementation in the Partner2Servlet of the Verifier application. This onMessage implementation processes the initial business document (a request) sent from the Partner1Servlet. It then creates and sends a reply document back to the Partner1 node.

Tasks Performed

The onMessage code performs the following tasks:

  1. Retrieves the Quality of Service for the business message by calling the getQoS method on the XOCPMessage instance.

    The application uses the same Quality of Service settings to send the reply message.

  2. Retrieves the payload parts of the business message by calling the getPayloadParts method on the XOCPMessage instance.

  3. Retrieves the first (and only) business document in the PayloadPart[] array.

  4. Extracts the associated XML document by calling the getDocument method on the BusinessDocument instance.

  5. Retrieves and examines parts of the XML document using methods on the Document instance, which is an instance of the org.w3c.dom.Document class provided in the org.w3c.dom package published by the World Wide Web Consortium (www.w3.org).

    A c-enabler application can also use a third party implementation of that package, such as the org.apache.xerces.dom package provided by The Apache XML Project (www.apache.org), which is what the Verifier application uses to create and process business documents.

  6. Retrieves the data string ("ABCDEFGHI") embedded in the business document and converts it to all lowercase letters.

  7. Constructs a reply document, specifies the same Quality of Service as the request document, and sends the document to Trading Partner 1.

Code Listing

The following listing is the onMessage implementation in the Partner2Servlet of the Verifier application.

Listing 4-2 onMessage Implementation in Partner2Servlet

public void onMessage(XOCPMessage rmsg) {
try{
QualityOfService qos = rmsg.getQoS();

PayloadPart[] payload = rmsg.getPayloadParts();
Document rq = null;

if (payload != null && payload.length > 0){
BusinessDocument bd = (BusinessDocument)payload[0];
rq = bd.getDocument();
}
if (rq == null){
throw new Exception("Did not get a request document");
}
Conversation conv = rmsg.getConversation();

Element root = rq.getDocumentElement();
String name = root.getNodeName();
if (!name.equals("request")){
debug("Received "+name+" instead of a request");
return;
}
Text revStr = (Text)root.getFirstChild();

// Create the return document
DOMImplementationImpl domi = new DOMImplementationImpl();
DocumentType dType = domi.createDocumentType("reply", null, "reply.dtd");
rq = new DocumentImpl(dType);
root = rq.createElement("reply");
String sendStr = new String(revStr.getData());
root.appendChild(rq.createTextNode(sendStr.toLowerCase()));
rq.appendChild(root);

XOCPMessage smsg = new XOCPMessage("");
smsg.addPayloadPart(new BusinessDocument(rq));
smsg.setQoS(qos);
smsg.setExpression("//trading-partner[@name=\'Partner1\']");

smsg.setConversation(conv);
smsg.sendAndWait(0);

}catch(Exception e){
e.printStackTrace();
}
}

 

back to top previous page