![]() |
![]() |
|
|
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:
The application uses the same Quality of Service settings to send the reply message.
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.
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();
}
}
![]() |
![]() |
|
Copyright © 2001 BEA Systems, Inc. All rights reserved.
|