Class IbmMqResponse

java.lang.Object
com.trafficparrot.sdk.ibmmq.IbmMqResponse
All Implemented Interfaces:
Comparable<IbmMqResponse>

public class IbmMqResponse extends Object implements Comparable<IbmMqResponse>
A response of a native IBM MQ mapping: the message Traffic Parrot sends when a request message matches. An IbmMqResponseTransformer receives the mapping's response and returns the one to send, either as text, which Traffic Parrot then renders:

 return new IbmMqResponse(response.destination, "<reply><status>QUEUED</status></reply>");
 
or as an MQMessage it has built itself, which is sent as it is:

 return IbmMqResponse.withResponseMessage(response.destination, message, response.fixedDelayMilliseconds, Optional.empty());
 
A response does not change; build a new one to change anything. The body is either text or the content of the bodyFileName file, never both.
  • Field Details

    • NO_TRANSFORMER

      public static final String NO_TRANSFORMER
      The ibmMqResponseTransformerClassName of a response that uses no transformer. A response returned from a transformer must carry it.
      See Also:
    • destination

      public final Destination destination
      The queue or topic the response is sent to, unless destinationLookup sends it to the request's reply-to queue.
    • ibmMqResponseTransformerClassName

      public final String ibmMqResponseTransformerClassName
      The class name of the IbmMqResponseTransformer the mapping uses, or NO_TRANSFORMER.
    • format

      public final IbmMqMessageFormat format
      The MQ format of the message; MQFMT_STRING when none is given.
    • text

      public final String text
      The message body, which may hold Handlebars expressions. For the binary formats (MQFMT_RF_HEADER_1, MQFMT_RF_HEADER_2 and MQFMT_NONE) it is the printable-characters encoding of the bytes to write. Null when the body comes from bodyFileName or the response carries a responseMessage.
    • bodyFileName

      public final String bodyFileName
      A file under __files that holds the body, used in place of an inline text. Supported only with the MQFMT_STRING format.
    • fixedDelayMilliseconds

      public final long fixedDelayMilliseconds
      How long Traffic Parrot waits before it sends the response, in milliseconds; 0 for no delay.
    • characterSet

      public final IbmMqCharacterSet characterSet
      The character set an MQFMT_STRING body is written in; UTF_8 when none is given.
    • destinationLookup

      public final Optional<DestinationLookup> destinationLookup
      Where the response is sent. Empty, or the default constant, sends it to the reply-to queue the request names and to destination when it names none; USE_MAPPING_RESPONSE_DESTINATION always sends it to destination.
    • replyToQueueManagerName

      public final String replyToQueueManagerName
      The reply-to queue manager name the mapping sets on the response message, if it sets one.
    • replyToQueueName

      public final String replyToQueueName
      The reply-to queue name the mapping sets on the response message, if it sets one.
    • resolvedText

      public final transient String resolvedText
      Content resolved from bodyFileName at load time. Held here rather than in text so the persisted model keeps bodyFileName set and text null (non-destructive). transient so the filesystem mapper never writes it to disk; set only via withResolvedText(String) and read via effectiveText(). The web-UI mapper re-includes it (via a mix-in) so the editor can display the content.
    • responseMessage

      public final transient Optional<com.ibm.mq.MQMessage> responseMessage
      A IbmMqResponseTransformer can return an MQMessage object instead of just transforming the mapping values.
  • Constructor Details

    • IbmMqResponse

      public IbmMqResponse(Destination destination, String ibmMqResponseTransformerClassName, IbmMqMessageFormat format, String text, String bodyFileName, Long fixedDelayInMilliseconds, IbmMqCharacterSet characterSet, Optional<DestinationLookup> destinationLookup, Optional<com.ibm.mq.MQMessage> responseMessage, String replyToQueueManagerName, String replyToQueueName)
      Creates a response with every field a mapping file can set. Traffic Parrot reads a mapping's response through this constructor.
      Parameters:
      destination - the queue or topic to send the response to
      ibmMqResponseTransformerClassName - the transformer's class name, or NO_TRANSFORMER
      format - the MQ format; null for MQFMT_STRING
      text - the body; null when bodyFileName is set
      bodyFileName - a file under __files to read the body from; null when text is set
      fixedDelayInMilliseconds - the delay before sending, in milliseconds; null for none
      characterSet - the character set of an MQFMT_STRING body; null for UTF_8
      destinationLookup - where the response is sent, as destinationLookup describes
      responseMessage - a message to send as it is, in place of one built from the other fields; a mapping file cannot set it
      replyToQueueManagerName - the reply-to queue manager name to set on the response message
      replyToQueueName - the reply-to queue name to set on the response message
    • IbmMqResponse

      public IbmMqResponse(Destination destination, String ibmMqResponseTransformerClassName, IbmMqMessageFormat format, String text, Long fixedDelayInMilliseconds, IbmMqCharacterSet characterSet, Optional<DestinationLookup> destinationLookup, Optional<com.ibm.mq.MQMessage> responseMessage)
      Creates a response with an inline body and a character set, and no reply-to names.
      Parameters:
      destination - the queue or topic to send the response to
      ibmMqResponseTransformerClassName - the transformer's class name, or NO_TRANSFORMER, which a response returned from a transformer must carry
      format - the MQ format; null for MQFMT_STRING
      text - the body
      fixedDelayInMilliseconds - the delay before sending, in milliseconds; null for none
      characterSet - the character set of an MQFMT_STRING body; null for UTF_8
      destinationLookup - where the response is sent, as destinationLookup describes
      responseMessage - a message to send as it is, in place of one built from the other fields; empty to build one
    • IbmMqResponse

      public IbmMqResponse(Destination destination, String ibmMqResponseTransformerClassName, IbmMqMessageFormat format, String text, Long fixedDelayInMilliseconds, Optional<DestinationLookup> destinationLookup, Optional<com.ibm.mq.MQMessage> responseMessage)
      Creates a response with an inline body in the UTF_8 character set, and no reply-to names.
      Parameters:
      destination - the queue or topic to send the response to
      ibmMqResponseTransformerClassName - the transformer's class name, or NO_TRANSFORMER, which a response returned from a transformer must carry
      format - the MQ format; null for MQFMT_STRING
      text - the body
      fixedDelayInMilliseconds - the delay before sending, in milliseconds; null for none
      destinationLookup - where the response is sent, as destinationLookup describes
      responseMessage - a message to send as it is, in place of one built from the other fields; empty to build one
    • IbmMqResponse

      public IbmMqResponse(Destination destination, String text)
      Creates a text response, which is what a transformer usually returns: an MQFMT_STRING message in UTF_8 with no delay and no transformer, sent to the reply-to queue the request names, or to destination when it names none.
      Parameters:
      destination - the queue or topic to send the response to when the request names no reply-to queue
      text - the body
    • IbmMqResponse

      public IbmMqResponse(Destination destination, com.ibm.mq.MQMessage responseMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup)
      Creates a response that sends responseMessage as it is. withResponseMessage(com.trafficparrot.sdk.messaging.Destination, com.ibm.mq.MQMessage, long, java.util.Optional<com.trafficparrot.sdk.messaging.DestinationLookup>) does the same and takes the destination lookup as the type that is not deprecated.
      Parameters:
      destination - the queue or topic to send the response to
      responseMessage - the message to send as it is: createMessage(byte[], java.lang.String, java.lang.String) sets no correlation id, format or reply-to names on it
      fixedDelayMilliseconds - the delay before sending, in milliseconds; 0 for none
      destinationLookup - where the response is sent, as destinationLookup describes
    • IbmMqResponse

      public IbmMqResponse(Destination destination, String ibmMqResponseTransformerClassName, IbmMqMessageFormat format, String text, Long fixedDelayInMilliseconds, Optional<DestinationLookup> destinationLookup, Optional<com.ibm.mq.MQMessage> responseMessage)
      Creates a response with an inline body, from the deprecated com.trafficparrot.sdk.jms destination type. It keeps extensions compiled against that type working; new code passes a com.trafficparrot.sdk.messaging.Destination.
      Parameters:
      destination - the queue or topic to send the response to
      ibmMqResponseTransformerClassName - the transformer's class name, or NO_TRANSFORMER
      format - the MQ format; null for MQFMT_STRING
      text - the body
      fixedDelayInMilliseconds - the delay before sending, in milliseconds; null for none
      destinationLookup - where the response is sent, as destinationLookup describes
      responseMessage - a message to send as it is; empty to build one
    • IbmMqResponse

      public IbmMqResponse(Destination destination, String text)
      Creates a text response from the deprecated com.trafficparrot.sdk.jms destination type. It keeps extensions compiled against that type working.
      Parameters:
      destination - the queue or topic to send the response to when the request names no reply-to queue
      text - the body
    • IbmMqResponse

      public IbmMqResponse(Destination destination, com.ibm.mq.MQMessage responseMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup)
      Creates a response that sends responseMessage as it is, from the deprecated com.trafficparrot.sdk.jms destination type. It keeps extensions compiled against that type working.
      Parameters:
      destination - the queue or topic to send the response to
      responseMessage - the message to send as it is: createMessage(byte[], java.lang.String, java.lang.String) sets no correlation id, format or reply-to names on it
      fixedDelayMilliseconds - the delay before sending, in milliseconds; 0 for none
      destinationLookup - where the response is sent, as destinationLookup describes
  • Method Details

    • withResponseMessage

      public static IbmMqResponse withResponseMessage(Destination destination, com.ibm.mq.MQMessage responseMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup)
      Static: builds a new response that sends responseMessage as it is, as the (Destination, MQMessage, long, Optional) constructor does, taking the destination lookup as DestinationLookup rather than the deprecated IBM MQ enum. Optional.of(USE_MAPPING_RESPONSE_DESTINATION) sends it to destination, ignoring the reply-to queue name the request carries; Optional.empty() or the default constant send it to that reply-to queue when the request names one, else to destination.
      Parameters:
      destination - the queue or topic to send the response to
      responseMessage - the message to send as it is: createMessage(byte[], java.lang.String, java.lang.String) sets no correlation id, format or reply-to names on it
      fixedDelayMilliseconds - the delay before sending, in milliseconds; 0 for none
      destinationLookup - where the response is sent
      Returns:
      the response
    • createMessage

      public com.ibm.mq.MQMessage createMessage(byte[] correlationId, String replyToQueueManagerNameHeader, String replyToQueueNameHeader) throws IOException
      The message Traffic Parrot sends for this response: the responseMessage as it is when the response carries one, otherwise a new message with this correlation id and these reply-to names, the response's format and its body.
      Parameters:
      correlationId - the correlation id for a new message; Traffic Parrot passes the request's correlation id, or its message id when it has none
      replyToQueueManagerNameHeader - the reply-to queue manager name for a new message
      replyToQueueNameHeader - the reply-to queue name for a new message
      Returns:
      the message to send
      Throws:
      IOException - if the body cannot be written to the message
    • writeMessage

      public static void writeMessage(com.ibm.mq.MQMessage mqMessage, IbmMqMessageFormat format, String text) throws IOException
      Writes a body to a message as writeMessage(MQMessage, IbmMqMessageFormat, String, int) does, in the UTF_8 character set.
      Parameters:
      mqMessage - the message to write the body to
      format - the format the body is written for
      text - the body
      Throws:
      IOException - if the body cannot be written
    • writeMessage

      public static void writeMessage(com.ibm.mq.MQMessage mqMessage, IbmMqMessageFormat format, String text, int characterSet) throws IOException
      Writes a body to a message, for a transformer that builds its own MQMessage. An MQFMT_STRING body is written as text in the character set given, which is also set on the message. For the other formats the text is the printable-characters encoding of the bytes to write, and the character set is not used. The message's format field is left for the caller to set.
      Parameters:
      mqMessage - the message to write the body to
      format - the format the body is written for
      text - the body
      characterSet - the CCSID of an MQFMT_STRING body, such as IbmMqCharacterSet.ccsid
      Throws:
      IOException - if the body cannot be written
    • withResolvedText

      public IbmMqResponse withResolvedText(String resolvedText)
      Returns a copy with resolvedText set (the content read from bodyFileName at load time). Every persisted field is preserved so a subsequent save re-writes bodyFileName with null text, keeping the sidecar reference intact.
      Parameters:
      resolvedText - the content of the bodyFileName file
      Returns:
      the copy
    • effectiveText

      public String effectiveText()
      The response body content to send: the file-resolved resolvedText when set, otherwise the inline text.
      Returns:
      the body, or null when the response has none
    • validate

      public void validate() throws IOException
      Checks the response is one Traffic Parrot can send: it does not set both text and bodyFileName, and a body read from bodyFileName has the MQFMT_STRING format.
      Throws:
      IOException - if it is not, with a message saying which rule it breaks
    • useDefaultDestinationLookup

      public boolean useDefaultDestinationLookup()
      Whether the response goes to the reply-to queue the request names, and to destination only when it names none.
      Returns:
      true if destinationLookup is empty or the default constant
    • forceMappingDestinationLookup

      public boolean forceMappingDestinationLookup()
      Whether the response goes to destination whatever reply-to queue the request names.
      Returns:
      true if destinationLookup is USE_MAPPING_RESPONSE_DESTINATION
    • hasTransformer

      public boolean hasTransformer()
      Whether the response names a transformer.
      Returns:
      true unless ibmMqResponseTransformerClassName is blank or NO_TRANSFORMER
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(IbmMqResponse other)
      Specified by:
      compareTo in interface Comparable<IbmMqResponse>