Network Deployment (Distributed operating systems), v8.0 > Reference > Developer best practices


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.


Example

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 table below 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:

Message transcoding. The table contains the different formats that can be used to convert the messages from one format to another. The table shows the transcoding options that is possible between the different formats, and it also provides the effect the conversion has on the messages.

  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.


Related


XML schema definition for JMS stream messages
Transcoding a byte array into a message payload
Transcoding a message payload into a byte array

+

Search Tips   |   Advanced Search