Transcoding between message formats
A mediation can convert a message from one format to another without changing the semantic meaning of the message. This operation is referred to as transcoding a message.
The following code is an example mediation handler that transcodes a message into a new message format, providing that the message can be transcoded:
private static final String NEW_FORMAT = "JMS:text"; public boolean(MessageContext context) throws MessageContextException { try { SIMessageContext msgCtx = (SIMessageContext)context; SIMessage msg = msgCtx.getMessage(); DataGraph newDg = msg.getNewDataGraph(NEW_FORMAT); msg.setDataGraph(newDg,NEW_FORMAT); return true; } catch(Exception e) { // Reroute the original message to the exception destination MessageContextException mce = new MessageContextException("Unable to transcode to "+NEW_FORMAT",e); throw mce; } }The following table describes which messages can be transcoded, and gives the outcome for each format pairing. Note that the abbreviation DG represents "data graph". The numbers within brackets in the table are explained as follows:
- (1) A message with format JMS: cannot have a payload. It does not carry any message data other than the message properties. If a mediation calls getDataGraph() on a message with format JMS:, null is always returned. All other message formats must have a message payload. This means that a message with format JMS: cannot be transcoded into another format. If a mediation needs to change a message with format JMS: into a message with any other format, the mediation needs to call the methods SIDataGraphFactory.getInstance().createDataGraph(newFormat) and setDataGraph on the SIMessage object to change the message contents.
- (2) null is always returned if a mediation calls getDataGraph() on a message with format JMS:
- (3) A mediation can call the method getNewDataGraph() on a message to return a copy datagraph with the same format as the message. The copy can be edited, leaving the original message unchanged. For SOAP and Beans, we can change the message model by editing the format string to change the value that follows the ":".
convert the messages from one format to another. The table shows the transcoding options that is possible between the different formats,
To JMS: To JMS:text To JMS:bytes To JMS:stream To JMS:object To SOAP: To Bean: From JMS: DG=null (1) DG=null (1) DG=null (1) DG=null (1) DG=null (1) DG=null (1) DG=null (1) From JMS:text DG=null (2) Yes (3) Yes, bytes contain UTF-8 Yes, if text contains XML that conforms to the correct schema. No Yes, if message content is valid SOAP. Yes, if message content is valid SOAP. From JMS:bytes DG=null (2) Yes, but only when the bytes can correctly be interpreted as a UTF-8 string. Yes (3) Yes, if bytes contain XML that conforms to the correct schema. Yes, assume that bytes are a serialized object. Yes, if message content is valid SOAP. Yes, if message content is valid SOAP. From JMS:stream DG=null (2) Yes, text is XML transcoding. Yes, bytes contain XML transcoding. Yes (3) No No No From JMS:object DG=null (2) No Yes, bytes contain the object serialization. No Yes (3) No No From SOAP: DG=null (2) Yes Yes No No Yes (3) - if message content matches the new WSDL. Yes From Bean: DG=null (2) Yes Yes No No Yes Yes (3) - if message content matches the new WSDL.
Subtopics
- XML schema definition for JMS stream messages
This is the XML schema definition for transcoding JMS stream messages to message types.
- Transcoding a message payload into a byte array
We can transcode the message payload into a byte array.
- Transcoding a byte array into a message payload
A mediation can transcode a byte array into a message payload without changing the meaning of the message.
- Web services messages overview
To work with the data graph form of web services messages, we need to know the structure of the data graph, and how to develop code that can navigate the data graph.
- JMS formats
To write code that can access the different JMS message types, we need to know how each message type is mapped to SDO, and how to retrieve the message format string from the message.
XML schema definition for JMS stream messages Transcoding a byte array into a message payload Transcoding a message payload into a byte array Reference topic