Class SdkIbmMqUtils

java.lang.Object
com.trafficparrot.sdk.ibmmq.SdkIbmMqUtils

public class SdkIbmMqUtils extends Object
Helpers for an IbmMqResponseTransformer that works with MQMessage objects: reading and replacing a message's body, describing a message for a log, and closing IBM MQ objects.

 String requestBody = SdkIbmMqUtils.readMessageBodySkipHeaders(requestMessage);
 logger.info("Received " + SdkIbmMqUtils.mqMessageToString(requestMessage));
 
The methods that read a message put its read position back where it was, so a transformer can read the request and Traffic Parrot can still read it afterwards.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static boolean
    Whether mqMessageToString(com.ibm.mq.MQMessage) includes the message body.
    static boolean
    Whether mqMessageToString(com.ibm.mq.MQMessage) writes the message body in the printable-characters encoding, which shows binary content, rather than decoding it as UTF-8.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Not needed, since every method is static.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    byteArrayAsHexString(byte[] correlationId)
    Bytes in upper-case hexadecimal, as IBM MQ tools show a message id or correlation id.
    static void
    closeQuietly(com.ibm.mq.MQDestination mqDestination)
    Closes a queue or topic without throwing: a failure is logged at DEBUG.
    static String
    correlationIdToString(com.ibm.mq.MQMessage message)
    A message's correlation id in upper-case hexadecimal.
    static void
    disconnectAndCloseQuietly(com.ibm.mq.MQQueueManager mqQueueManager)
    Disconnects from a queue manager and closes it without throwing: a failure is logged at DEBUG.
    static void
    disconnectQuietly(com.ibm.mq.MQQueueManager mqQueueManager)
    Disconnects from a queue manager without throwing: a failure is logged at DEBUG.
    static String
    A put time as an ISO-8601 instant in UTC, such as 2020-01-03T10:15:30Z.
    static byte[]
    loggableMessageBytes(com.ibm.mq.MQMessage message)
    The message's bytes as sent, except that a CICS bridge header's Authenticator, a password or passticket, is masked.
    static String
    messageIdToString(com.ibm.mq.MQMessage message)
    A message's id in upper-case hexadecimal.
    static String
    mqMessageToString(com.ibm.mq.MQMessage message)
    A description of a message for a log, one field to a line: its format, message id and correlation id in hexadecimal, reply-to names, body, sequence number, user id, put application name, put time, character set and properties.
    static String
    putDateTime(com.ibm.mq.MQMessage message)
    When a message was put, as formatPutDateTime(java.util.GregorianCalendar) writes it.
    static String
    readMessageBodySkipHeaders(com.ibm.mq.MQMessage message)
    A message's body as text, without the rules and formatting headers of a message in the MQFMT_RF_HEADER_1 or MQFMT_RF_HEADER_2 format; for any other format, the same as readMessageString(com.ibm.mq.MQMessage).
    static byte[]
    readMessageBytes(com.ibm.mq.MQMessage message)
    The whole of a message's data as bytes, any header included.
    static String
    readMessageString(com.ibm.mq.MQMessage message)
    The whole of a message's data as text, any header included, decoded in the message's character set.
    static String
    resolvedDestinationName(com.ibm.mq.MQDestination mqDestination)
    The name of the queue or topic an open destination resolved to.
    static void
    setMessageBody(com.ibm.mq.MQMessage message, String body)
    Replaces a message's body with this text, keeping the rules and formatting headers of a message in the MQFMT_RF_HEADER_1 or MQFMT_RF_HEADER_2 format, for a transformer that sends on a changed copy of the request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logMessageBody

      public static boolean logMessageBody
      Whether mqMessageToString(com.ibm.mq.MQMessage) includes the message body. True unless an extension sets it: Traffic Parrot's trafficparrot.ibmmq.logger.logMessageBody property governs Traffic Parrot's own logging and does not change this.
    • logMessageBodyAsPrintableCharacters

      public static boolean logMessageBodyAsPrintableCharacters
      Whether mqMessageToString(com.ibm.mq.MQMessage) writes the message body in the printable-characters encoding, which shows binary content, rather than decoding it as UTF-8. False unless an extension sets it: Traffic Parrot's trafficparrot.ibmmq.logger.logMessageBodyAsPrintableCharacters property does not change this.
  • Constructor Details

    • SdkIbmMqUtils

      public SdkIbmMqUtils()
      Not needed, since every method is static. Declared so that code which creates an instance keeps working.
  • Method Details

    • resolvedDestinationName

      public static String resolvedDestinationName(com.ibm.mq.MQDestination mqDestination) throws com.ibm.mq.MQException
      The name of the queue or topic an open destination resolved to.
      Parameters:
      mqDestination - the open queue or topic
      Returns:
      its resolved queue name, or if that is blank its resolved object string, or if that is blank too the name it was opened with
      Throws:
      com.ibm.mq.MQException - if IBM MQ cannot give the name
    • closeQuietly

      public static void closeQuietly(com.ibm.mq.MQDestination mqDestination)
      Closes a queue or topic without throwing: a failure is logged at DEBUG. Logs the close at INFO.
      Parameters:
      mqDestination - the queue or topic to close; null is ignored
    • disconnectQuietly

      public static void disconnectQuietly(com.ibm.mq.MQQueueManager mqQueueManager)
      Disconnects from a queue manager without throwing: a failure is logged at DEBUG. Logs the disconnect at INFO.
      Parameters:
      mqQueueManager - the queue manager to disconnect from; null is ignored
    • disconnectAndCloseQuietly

      public static void disconnectAndCloseQuietly(com.ibm.mq.MQQueueManager mqQueueManager)
      Disconnects from a queue manager and closes it without throwing: a failure is logged at DEBUG. Logs it at INFO.
      Parameters:
      mqQueueManager - the queue manager to disconnect from and close; null is ignored
    • mqMessageToString

      public static String mqMessageToString(com.ibm.mq.MQMessage message)
      A description of a message for a log, one field to a line: its format, message id and correlation id in hexadecimal, reply-to names, body, sequence number, user id, put application name, put time, character set and properties. A long body is cut short, a CICS bridge header's Authenticator is masked, and the body is left out when logMessageBody is false. It does not throw: if the message cannot be read, the error is logged and the result says so.
      Parameters:
      message - the message to describe
      Returns:
      the description
    • messageIdToString

      public static String messageIdToString(com.ibm.mq.MQMessage message)
      A message's id in upper-case hexadecimal.
      Parameters:
      message - the message
      Returns:
      its messageId, two characters to a byte
    • correlationIdToString

      public static String correlationIdToString(com.ibm.mq.MQMessage message)
      A message's correlation id in upper-case hexadecimal.
      Parameters:
      message - the message
      Returns:
      its correlationId, two characters to a byte
    • byteArrayAsHexString

      public static String byteArrayAsHexString(byte[] correlationId)
      Bytes in upper-case hexadecimal, as IBM MQ tools show a message id or correlation id.
      Parameters:
      correlationId - the bytes; any byte array, not only a correlation id
      Returns:
      two characters to a byte
    • readMessageString

      public static String readMessageString(com.ibm.mq.MQMessage message) throws IOException
      The whole of a message's data as text, any header included, decoded in the message's character set. The message's read position is put back where it was.
      Parameters:
      message - the message to read
      Returns:
      its data as text
      Throws:
      IOException - if the message cannot be read
    • readMessageBytes

      public static byte[] readMessageBytes(com.ibm.mq.MQMessage message) throws IOException
      The whole of a message's data as bytes, any header included. The message's read position is put back where it was. To log the bytes, use loggableMessageBytes(com.ibm.mq.MQMessage).
      Parameters:
      message - the message to read
      Returns:
      its data, in a new array
      Throws:
      IOException - if the message cannot be read
    • loggableMessageBytes

      public static byte[] loggableMessageBytes(com.ibm.mq.MQMessage message) throws IOException
      The message's bytes as sent, except that a CICS bridge header's Authenticator, a password or passticket, is masked. Use these, not readMessageBytes(com.ibm.mq.MQMessage), wherever the message is logged.
      Parameters:
      message - the message to read
      Returns:
      its data, in a new array, with the Authenticator of a message in the MQFMT_CICS format replaced by asterisks
      Throws:
      IOException - if the message cannot be read
    • putDateTime

      public static String putDateTime(com.ibm.mq.MQMessage message)
      When a message was put, as formatPutDateTime(java.util.GregorianCalendar) writes it.
      Parameters:
      message - the message
      Returns:
      its putDateTime as text
    • formatPutDateTime

      public static String formatPutDateTime(GregorianCalendar putDateTime)
      A put time as an ISO-8601 instant in UTC, such as 2020-01-03T10:15:30Z.
      Parameters:
      putDateTime - the time; may be null
      Returns:
      the time as text, or "null" when there is none
    • readMessageBodySkipHeaders

      public static String readMessageBodySkipHeaders(com.ibm.mq.MQMessage message) throws IOException
      A message's body as text, without the rules and formatting headers of a message in the MQFMT_RF_HEADER_1 or MQFMT_RF_HEADER_2 format; for any other format, the same as readMessageString(com.ibm.mq.MQMessage). The message's read position is put back where it was.
      Parameters:
      message - the message to read
      Returns:
      its body as text, decoded in the message's character set
      Throws:
      IOException - if the message cannot be read
      IllegalArgumentException - if its headers cannot be read
    • setMessageBody

      public static void setMessageBody(com.ibm.mq.MQMessage message, String body) throws IOException
      Replaces a message's body with this text, keeping the rules and formatting headers of a message in the MQFMT_RF_HEADER_1 or MQFMT_RF_HEADER_2 format, for a transformer that sends on a changed copy of the request. The message ends where the new body ends, and its position is left there.
      Parameters:
      message - the message to change
      body - the new body, written in the message's character set
      Throws:
      IOException - if the message cannot be written
      IllegalArgumentException - if its headers cannot be read