Package com.trafficparrot.sdk.ibmmq
Class SdkIbmMqUtils
java.lang.Object
com.trafficparrot.sdk.ibmmq.SdkIbmMqUtils
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
FieldsModifier and TypeFieldDescriptionstatic booleanWhethermqMessageToString(com.ibm.mq.MQMessage)includes the message body.static booleanWhethermqMessageToString(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 -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbyteArrayAsHexString(byte[] correlationId) Bytes in upper-case hexadecimal, as IBM MQ tools show a message id or correlation id.static voidcloseQuietly(com.ibm.mq.MQDestination mqDestination) Closes a queue or topic without throwing: a failure is logged at DEBUG.static StringcorrelationIdToString(com.ibm.mq.MQMessage message) A message's correlation id in upper-case hexadecimal.static voiddisconnectAndCloseQuietly(com.ibm.mq.MQQueueManager mqQueueManager) Disconnects from a queue manager and closes it without throwing: a failure is logged at DEBUG.static voiddisconnectQuietly(com.ibm.mq.MQQueueManager mqQueueManager) Disconnects from a queue manager without throwing: a failure is logged at DEBUG.static StringformatPutDateTime(GregorianCalendar putDateTime) A put time as an ISO-8601 instant in UTC, such as2020-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 StringmessageIdToString(com.ibm.mq.MQMessage message) A message's id in upper-case hexadecimal.static StringmqMessageToString(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 StringputDateTime(com.ibm.mq.MQMessage message) When a message was put, asformatPutDateTime(java.util.GregorianCalendar)writes it.static StringreadMessageBodySkipHeaders(com.ibm.mq.MQMessage message) A message's body as text, without the rules and formatting headers of a message in theMQFMT_RF_HEADER_1orMQFMT_RF_HEADER_2format; for any other format, the same asreadMessageString(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 StringreadMessageString(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 StringresolvedDestinationName(com.ibm.mq.MQDestination mqDestination) The name of the queue or topic an open destination resolved to.static voidsetMessageBody(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 theMQFMT_RF_HEADER_1orMQFMT_RF_HEADER_2format, for a transformer that sends on a changed copy of the request.
-
Field Details
-
logMessageBody
public static boolean logMessageBodyWhethermqMessageToString(com.ibm.mq.MQMessage)includes the message body. True unless an extension sets it: Traffic Parrot'strafficparrot.ibmmq.logger.logMessageBodyproperty governs Traffic Parrot's own logging and does not change this. -
logMessageBodyAsPrintableCharacters
public static boolean logMessageBodyAsPrintableCharactersWhethermqMessageToString(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'strafficparrot.ibmmq.logger.logMessageBodyAsPrintableCharactersproperty 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
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 whenlogMessageBodyis 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
A message's id in upper-case hexadecimal.- Parameters:
message- the message- Returns:
- its
messageId, two characters to a byte
-
correlationIdToString
A message's correlation id in upper-case hexadecimal.- Parameters:
message- the message- Returns:
- its
correlationId, two characters to a byte
-
byteArrayAsHexString
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
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
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, useloggableMessageBytes(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
The message's bytes as sent, except that a CICS bridge header's Authenticator, a password or passticket, is masked. Use these, notreadMessageBytes(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_CICSformat replaced by asterisks - Throws:
IOException- if the message cannot be read
-
putDateTime
When a message was put, asformatPutDateTime(java.util.GregorianCalendar)writes it.- Parameters:
message- the message- Returns:
- its
putDateTimeas text
-
formatPutDateTime
A put time as an ISO-8601 instant in UTC, such as2020-01-03T10:15:30Z.- Parameters:
putDateTime- the time; may be null- Returns:
- the time as text, or
"null"when there is none
-
readMessageBodySkipHeaders
A message's body as text, without the rules and formatting headers of a message in theMQFMT_RF_HEADER_1orMQFMT_RF_HEADER_2format; for any other format, the same asreadMessageString(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 readIllegalArgumentException- if its headers cannot be read
-
setMessageBody
Replaces a message's body with this text, keeping the rules and formatting headers of a message in theMQFMT_RF_HEADER_1orMQFMT_RF_HEADER_2format, 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 changebody- the new body, written in the message's character set- Throws:
IOException- if the message cannot be writtenIllegalArgumentException- if its headers cannot be read
-