|
The nodes of interest are the Parameter nodes containing the name, data type, and IsArray attributes, which would be enough for the user. Also note the values that hold the actual value for each of the parameters.
You can write sample code to read the above XML using the OnMessage method of the JMS component, as shown in Listing 8. You can use the extracted values to make calls to any type of bean, such as the CMP entity bean.
Listing 8. Code to read TextMessage XML
public void onMessage(javax.jms.Message msg)
{
try
{
TextMessage tm = (TextMessage)msg;
ByteArrayInputStream br = new ByteArrayInputStream(tm.getText().getBytes());
DOMParser parser = new DOMParser();
InputSource in = new InputSource(br);
parser.parse(in);;
Document document = parser.getDocument();
NodeList nodelist=document.getElementsByTagName("Value");
int nIter =0;
String[] strArray = new String[5];
while(nIte<nodelist.getLength());
{
Node node = nodelist.item(nIter);
strArray[nIter]=node.getFirstChild().getNodeValue();
nIter++;
}
int cruiseID = Integer.parseInt(strArray[1]);
int orderID = Integer.parseInt(strArray[2]);
int passengerID = Integer.parseInt(strArray[4]);
String passengerName = strArray[3];
// This call can invoke an EJB component
insertToDB(cruiseID,orderID,passengerName,passengerID);
}
catch(MessageFormatException mfex)
{
mfex.printStackTrace();
}
catch(JMSException jmsex)
{
jmsex.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
} |
|