private void read(javax.jms.TextMessage message) throws WSIFException {
Trc.entry(this, message);
// Need to determine the format type mapping
if (!XML_ENCODING.equals(getFormatEncoding(fieldBindingModel)))
throw new WSIFException("Unable to support non XML encodings in a JMS Text Message");
boolean wsifFormat = false;
try {
// Read the text into the document
javax.xml.parsers.DocumentBuilderFactory factory =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
javax.xml.parsers.DocumentBuilder builder =
factory.newDocumentBuilder();
builder.setErrorHandler(null);
String text = message.getText();
java.io.ByteArrayInputStream is =
new java.io.ByteArrayInputStream(text.getBytes());
org.w3c.dom.Document doc = builder.parse(is);
// Check to see if the document element is the message
if (fieldMessageModel
.getQName()
.getLocalPart()
.equals(doc.getDocumentElement().getLocalName())) {
wsifFormat = true;
// Need to make the message mutable
message.clearBody();
// Parse the document ignoring the document element which should be the message name
// The contents should represent the parts as elements
for (org.w3c.dom.Node n =
doc.getDocumentElement().getFirstChild();
n != null;
n = n.getNextSibling()) {
if (n.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
String partName = n.getLocalName();
java.io.ByteArrayOutputStream os =
new java.io.ByteArrayOutputStream();
org.apache.xml.serialize.OutputFormat format =
new org.apache.xml.serialize.OutputFormat();
org.apache.xml.serialize.TextSerializer serializer =
new org.apache.xml.serialize.TextSerializer();
serializer.setOutputFormat(format);
serializer.setOutputByteStream(os);
format.setOmitXMLDeclaration(true);
//format.setOmitDocumentType(true);
serializer.serialize((org.w3c.dom.Element) n);
os.flush();
// Get the contents
String partText = os.toString();
javax.wsdl.Part partModel =
fieldMessageModel.getPart(partName);
JMSFormatHandler fh = getFormatHandler(partName);
if (fh != null) {
fh.setPartQName(
new javax.xml.namespace.QName(
fieldMessageModel
.getQName()
.getNamespaceURI(),
partModel.getName()));
message.setText(partText);
fh.read(message);
//fh.setObjectPart(n);
setObjectPart(partName, fh.getObjectPart());
// ?? Do I want to store the format handler instead???
//partToFHMap.put(partKey, formatHandler);
} else {
// No format handler - pass the part contents directly
setObjectPart(partName, partText);
}
}
}
// Reset the message to original text
message.setText(text);
}
} catch (JMSException e) {
Trc.exception(e);
throw new WSIFException("Error in read.", e);
} catch (javax.xml.parsers.ParserConfigurationException e) {
Trc.exception(e);
throw new WSIFException("Error in read.", e);
} catch (Exception e) {
Trc.exception(e);
// For all other exceptions ignore since it is likely due to parsing of a non-XML document
}
try {
if (!wsifFormat) {
// Unknown format - either XML or Text
// Pass the contents of the message to each part of the message model
Object[] partNames =
fieldMessageParts != null
? fieldMessageParts.toArray()
: fieldMessageModel.getParts().keySet().toArray();
// should only be one part
if (partNames.length != 1)
throw new WSIFException(
"There should only be one part defined in "
+ fieldMessageModel.getQName().getLocalPart());
String partName = partNames[0].toString();
javax.wsdl.Part partModel = fieldMessageModel.getPart(partName);
JMSFormatHandler fh = getFormatHandler(partName);
if (fh != null) {
fh.setPartQName(
new javax.xml.namespace.QName(
fieldMessageModel.getQName().getNamespaceURI(),
partModel.getName()));
fh.read(message);
setObjectPart(partName, fh.getObjectPart());
// ?? Do I want to store the format handler instead???
//partToFHMap.put(partKey, formatHandler);
} else {
// No format handler - pass the part contents directly
setObjectPart(partName, message.getText());
}
}
} catch (JMSException e) {
Trc.exception(e);
throw new WSIFException("Error in read.", e);
}
Trc.exit();
}