antelder 2002/06/24 04:11:23 Modified: java/src/org/apache/wsif/providers/jms JMSMessage.java Log: Tidy up the JMSMessage code (chgs from Norman) Revision Changes Path 1.5 +90 -132 xml-axis-wsif/java/src/org/apache/wsif/providers/jms/JMSMessage.java Index: JMSMessage.java =================================================================== RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/jms/JMSMessage.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JMSMessage.java 12 Jun 2002 21:07:50 -0000 1.4 +++ JMSMessage.java 24 Jun 2002 11:11:23 -0000 1.5 @@ -72,6 +72,7 @@ import javax.jms.ObjectMessage; import javax.jms.TextMessage; +import javax.jms.JMSException; import javax.wsdl.Binding; import javax.wsdl.Definition; import javax.wsdl.Message; @@ -223,9 +224,6 @@ : fieldMessageModel.getParts().keySet().toArray(); String namespace = ""; - //serializer.startPrefixMapping("tns", namespace); - //serializer.endPrefixMapping("tns"); - // Start the document serializer.startDocument(); @@ -258,16 +256,7 @@ if (fh != null) { fh.setObjectPart(parts.get(partName)); - // Sets up the PartFormatHandler - /* - try { - ((org.apache.wsif.format.literal.PartFormatHandler)fh).setPartQName(partQName); - - } - catch (ClassCastException e) { - // Not a PartFormatHandler - } - */ + // Send the message since it is the native format // Reinitialize the message content message.setText(""); @@ -339,16 +328,6 @@ org.apache.wsif.format.jms.JMSFormatHandler fh = getFormatHandler(partName); if (fh != null) { - // Sets up the PartFormatHandler - /* - try { - ((org.apache.wsif.format.literal.PartFormatHandler)fh).setPartQName(partQName); - - } - catch (ClassCastException e) { - // Not a PartFormatHandler - } - */ fh.setObjectPart(parts.get(partName)); fh.write(message); result.put(partName, message.getObject()); @@ -398,6 +377,8 @@ if (!getFormatEncoding(fieldBindingModel).equals(XML_ENCODING)) throw new org.apache.wsif.WSIFException( "Unable to support non XML encodings in a JMS Text Message"); + + boolean wsifFormat = false; try { @@ -419,6 +400,8 @@ .getQName() .getLocalPart() .equals(doc.getDocumentElement().getLocalName())) { + + wsifFormat = true; // Need to make the message mutable message.clearBody(); @@ -454,18 +437,6 @@ if (fh != null) { - // Sets up the PartFormatHandler - /* - try { - // Calculate the QName for the part - javax.wsdl.QName partQName = - new javax.wsdl.QName(fieldMessageModel.getQName().getNamespaceURI(), partModel.getName()); - ((org.apache.wsif.format.literal.PartFormatHandler)fh).setPartQName(partQName); - } - catch (ClassCastException e) { - } - */ - message.setText(partText); fh.read(message); @@ -483,54 +454,55 @@ // Reset the message to original text message.setText(text); - } else { - // Unknown format - // Pass the contents of the message to each part of the message model - should only be one part - Object[] partNames = - fieldMessageParts != null - ? fieldMessageParts.toArray() - : fieldMessageModel.getParts().keySet().toArray(); - - // Use a hash map to hold the objects - java.util.HashMap result = new java.util.HashMap(); - for (int i = 0; i < partNames.length; i++) { - String partName = partNames[i].toString(); - - javax.wsdl.Part partModel = fieldMessageModel.getPart(partName); - org.apache.wsif.format.jms.JMSFormatHandler fh = getFormatHandler(partName); - - if (fh != null) { - - // Sets up the PartFormatHandler - /* - try { - // Calculate the QName for the part - javax.wsdl.QName partQName = - new javax.wsdl.QName(fieldMessageModel.getQName().getNamespaceURI(), partModel.getName()); - ((org.apache.wsif.format.literal.PartFormatHandler)fh).setPartQName(partQName); - } - catch (ClassCastException e) { - } - */ - - 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 (Exception e) { - throw new org.apache.wsif.WSIFException("Error in read.", e); } - } + catch (JMSException e) { + throw new WSIFException("Error in read.", e); + } + catch (javax.xml.parsers.ParserConfigurationException e) { + throw new WSIFException("Error in read.", e); + } + catch (Exception e) { + // For all other exceptions ignore since it is likely due to parsing of a non-XML document + } + + 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.read(message); + + setObjectPart(partName, fh.getObjectPart()); + + // ?? Do I want to store the format handler instead??? + //partToFHMap.put(partKey, formatHandler); + + } + else { + try { + // No format handler - pass the part contents directly + setObjectPart(partName, message.getText()); + } + catch (JMSException e) { + throw new WSIFException("Error in read.", e); + } + } + } + } /** * Reads the JMS ObjectMessage @@ -572,17 +544,6 @@ if (fh != null) { - // Sets up the PartFormatHandler - /* - try { - // Calculate the QName for the part - javax.wsdl.QName partQName = - new javax.wsdl.QName(fieldMessageModel.getQName().getNamespaceURI(), partModel.getName()); - ((org.apache.wsif.format.literal.PartFormatHandler)fh).setPartQName(partQName); - } - catch (ClassCastException e) { - } - */ // Should be serializable since retrieved it over the wire message.setObject((java.io.Serializable) map.get(partName)); fh.read(message); @@ -603,47 +564,44 @@ message.setObject((java.io.Serializable) object); } else { // It is an unknown format - // Pass the contents of the message to each part of the message model - should only be one part - - for (int i = 0; i < partNames.length; i++) { - String partName = partNames[i].toString(); - - javax.wsdl.Part partModel = fieldMessageModel.getPart(partName); - org.apache.wsif.format.jms.JMSFormatHandler fh = getFormatHandler(partName); - - if (fh != null) { - - // Sets up the PartFormatHandler - /* - try { - // Calculate the QName for the part - javax.wsdl.QName partQName = - new javax.wsdl.QName(fieldMessageModel.getQName().getNamespaceURI(), partModel.getName()); - ((org.apache.wsif.format.literal.PartFormatHandler)fh).setPartQName(partQName); - } - catch (ClassCastException e) { - } - */ - fh.read(message); - - setObjectPart(partName, fh.getObjectPart()); - - // ?? Do I want to store the format handler instead??? - //partToFHMap.put(partKey, formatHandler); - - } else { - // No format handler defined - setObjectPart(partName, message.getObject()); - } - - } - } - } catch (Exception e) { - throw new org.apache.wsif.WSIFException("Error in read.", e); - } - } + // Pass the contents of the message to each part of the message model + + // 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.read(message); + + setObjectPart(partName, fh.getObjectPart()); + + // ?? Do I want to store the format handler instead??? + //partToFHMap.put(partKey, formatHandler); + + } + else { + // No format handler defined + setObjectPart(partName, message.getObject()); + } + + } + } + catch (JMSException e) { + throw new WSIFException("Error in read.", e); + } + } + - // Move to JCA utils - ask Piotr + // Move to WSIF utils ?? private static String getFormatEncoding(Binding bindingModel) { java.util.Iterator iterator = bindingModel.getExtensibilityElements().iterator();