Package com.trafficparrot.sdk.ibmmq
Class IbmMqResponse
java.lang.Object
com.trafficparrot.sdk.ibmmq.IbmMqResponse
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionfinal StringA file under__filesthat holds the body, used in place of an inlinetext.final IbmMqCharacterSetThe character set anMQFMT_STRINGbody is written in;UTF_8when none is given.final DestinationThe queue or topic the response is sent to, unlessdestinationLookupsends it to the request's reply-to queue.final Optional<DestinationLookup>Where the response is sent.final longHow long Traffic Parrot waits before it sends the response, in milliseconds; 0 for no delay.final IbmMqMessageFormatThe MQ format of the message;MQFMT_STRINGwhen none is given.final StringThe class name of theIbmMqResponseTransformerthe mapping uses, orNO_TRANSFORMER.static final StringTheibmMqResponseTransformerClassNameof a response that uses no transformer.final StringThe reply-to queue manager name the mapping sets on the response message, if it sets one.final StringThe reply-to queue name the mapping sets on the response message, if it sets one.final StringContent resolved frombodyFileNameat load time.final Optional<com.ibm.mq.MQMessage>AIbmMqResponseTransformercan return anMQMessageobject instead of just transforming the mapping values.final StringThe message body, which may hold Handlebars expressions. -
Constructor Summary
ConstructorsConstructorDescriptionIbmMqResponse(Destination destination, com.ibm.mq.MQMessage responseMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup) Creates a response that sendsresponseMessageas it is, from the deprecatedcom.trafficparrot.sdk.jmsdestination type.IbmMqResponse(Destination destination, String text) Creates a text response from the deprecatedcom.trafficparrot.sdk.jmsdestination type.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 deprecatedcom.trafficparrot.sdk.jmsdestination type.IbmMqResponse(Destination destination, com.ibm.mq.MQMessage responseMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup) Creates a response that sendsresponseMessageas it is.IbmMqResponse(Destination destination, String text) Creates a text response, which is what a transformer usually returns: anMQFMT_STRINGmessage inUTF_8with no delay and no transformer, sent to the reply-to queue the request names, or todestinationwhen it names none.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.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 theUTF_8character set, and no reply-to names.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. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(IbmMqResponse other) com.ibm.mq.MQMessagecreateMessage(byte[] correlationId, String replyToQueueManagerNameHeader, String replyToQueueNameHeader) The message Traffic Parrot sends for this response: theresponseMessageas it is when the response carries one, otherwise a new message with this correlation id and these reply-to names, the response'sformatand its body.The response body content to send: the file-resolvedresolvedTextwhen set, otherwise the inlinetext.booleanWhether the response goes todestinationwhatever reply-to queue the request names.booleanWhether the response names a transformer.toString()booleanWhether the response goes to the reply-to queue the request names, and todestinationonly when it names none.voidvalidate()Checks the response is one Traffic Parrot can send: it does not set bothtextandbodyFileName, and a body read frombodyFileNamehas theMQFMT_STRINGformat.withResolvedText(String resolvedText) Returns a copy withresolvedTextset (the content read frombodyFileNameat load time).static IbmMqResponsewithResponseMessage(Destination destination, com.ibm.mq.MQMessage responseMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup) Static: builds a new response that sendsresponseMessageas it is, as the(Destination, MQMessage, long, Optional)constructor does, taking the destination lookup asDestinationLookuprather than the deprecated IBM MQ enum.static voidwriteMessage(com.ibm.mq.MQMessage mqMessage, IbmMqMessageFormat format, String text) Writes a body to a message aswriteMessage(MQMessage, IbmMqMessageFormat, String, int)does, in theUTF_8character set.static voidwriteMessage(com.ibm.mq.MQMessage mqMessage, IbmMqMessageFormat format, String text, int characterSet) Writes a body to a message, for a transformer that builds its ownMQMessage.
-
Field Details
-
NO_TRANSFORMER
TheibmMqResponseTransformerClassNameof a response that uses no transformer. A response returned from a transformer must carry it.- See Also:
-
destination
The queue or topic the response is sent to, unlessdestinationLookupsends it to the request's reply-to queue. -
ibmMqResponseTransformerClassName
The class name of theIbmMqResponseTransformerthe mapping uses, orNO_TRANSFORMER. -
format
The MQ format of the message;MQFMT_STRINGwhen none is given. -
text
The message body, which may hold Handlebars expressions. For the binary formats (MQFMT_RF_HEADER_1,MQFMT_RF_HEADER_2andMQFMT_NONE) it is the printable-characters encoding of the bytes to write. Null when the body comes frombodyFileNameor the response carries aresponseMessage. -
bodyFileName
A file under__filesthat holds the body, used in place of an inlinetext. Supported only with theMQFMT_STRINGformat. -
fixedDelayMilliseconds
public final long fixedDelayMillisecondsHow long Traffic Parrot waits before it sends the response, in milliseconds; 0 for no delay. -
characterSet
The character set anMQFMT_STRINGbody is written in;UTF_8when none is given. -
destinationLookup
Where the response is sent. Empty, or the default constant, sends it to the reply-to queue the request names and todestinationwhen it names none;USE_MAPPING_RESPONSE_DESTINATIONalways sends it todestination. -
replyToQueueManagerName
The reply-to queue manager name the mapping sets on the response message, if it sets one. -
replyToQueueName
The reply-to queue name the mapping sets on the response message, if it sets one. -
resolvedText
Content resolved frombodyFileNameat load time. Held here rather than intextso the persisted model keepsbodyFileNameset andtextnull (non-destructive).transientso the filesystem mapper never writes it to disk; set only viawithResolvedText(String)and read viaeffectiveText(). The web-UI mapper re-includes it (via a mix-in) so the editor can display the content. -
responseMessage
AIbmMqResponseTransformercan return anMQMessageobject 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 toibmMqResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMERformat- the MQ format; null forMQFMT_STRINGtext- the body; null whenbodyFileNameis setbodyFileName- a file under__filesto read the body from; null whentextis setfixedDelayInMilliseconds- the delay before sending, in milliseconds; null for nonecharacterSet- the character set of anMQFMT_STRINGbody; null forUTF_8destinationLookup- where the response is sent, asdestinationLookupdescribesresponseMessage- a message to send as it is, in place of one built from the other fields; a mapping file cannot set itreplyToQueueManagerName- the reply-to queue manager name to set on the response messagereplyToQueueName- 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 toibmMqResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMER, which a response returned from a transformer must carryformat- the MQ format; null forMQFMT_STRINGtext- the bodyfixedDelayInMilliseconds- the delay before sending, in milliseconds; null for nonecharacterSet- the character set of anMQFMT_STRINGbody; null forUTF_8destinationLookup- where the response is sent, asdestinationLookupdescribesresponseMessage- 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 theUTF_8character set, and no reply-to names.- Parameters:
destination- the queue or topic to send the response toibmMqResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMER, which a response returned from a transformer must carryformat- the MQ format; null forMQFMT_STRINGtext- the bodyfixedDelayInMilliseconds- the delay before sending, in milliseconds; null for nonedestinationLookup- where the response is sent, asdestinationLookupdescribesresponseMessage- a message to send as it is, in place of one built from the other fields; empty to build one
-
IbmMqResponse
Creates a text response, which is what a transformer usually returns: anMQFMT_STRINGmessage inUTF_8with no delay and no transformer, sent to the reply-to queue the request names, or todestinationwhen it names none.- Parameters:
destination- the queue or topic to send the response to when the request names no reply-to queuetext- the body
-
IbmMqResponse
public IbmMqResponse(Destination destination, com.ibm.mq.MQMessage responseMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup) Creates a response that sendsresponseMessageas 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 toresponseMessage- 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 itfixedDelayMilliseconds- the delay before sending, in milliseconds; 0 for nonedestinationLookup- where the response is sent, asdestinationLookupdescribes
-
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 deprecatedcom.trafficparrot.sdk.jmsdestination type. It keeps extensions compiled against that type working; new code passes acom.trafficparrot.sdk.messaging.Destination.- Parameters:
destination- the queue or topic to send the response toibmMqResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMERformat- the MQ format; null forMQFMT_STRINGtext- the bodyfixedDelayInMilliseconds- the delay before sending, in milliseconds; null for nonedestinationLookup- where the response is sent, asdestinationLookupdescribesresponseMessage- a message to send as it is; empty to build one
-
IbmMqResponse
Creates a text response from the deprecatedcom.trafficparrot.sdk.jmsdestination 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 queuetext- the body
-
IbmMqResponse
public IbmMqResponse(Destination destination, com.ibm.mq.MQMessage responseMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup) Creates a response that sendsresponseMessageas it is, from the deprecatedcom.trafficparrot.sdk.jmsdestination type. It keeps extensions compiled against that type working.- Parameters:
destination- the queue or topic to send the response toresponseMessage- 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 itfixedDelayMilliseconds- the delay before sending, in milliseconds; 0 for nonedestinationLookup- where the response is sent, asdestinationLookupdescribes
-
-
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 sendsresponseMessageas it is, as the(Destination, MQMessage, long, Optional)constructor does, taking the destination lookup asDestinationLookuprather than the deprecated IBM MQ enum.Optional.of(USE_MAPPING_RESPONSE_DESTINATION)sends it todestination, 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 todestination.- Parameters:
destination- the queue or topic to send the response toresponseMessage- 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 itfixedDelayMilliseconds- the delay before sending, in milliseconds; 0 for nonedestinationLookup- 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: theresponseMessageas it is when the response carries one, otherwise a new message with this correlation id and these reply-to names, the response'sformatand 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 nonereplyToQueueManagerNameHeader- the reply-to queue manager name for a new messagereplyToQueueNameHeader- 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 aswriteMessage(MQMessage, IbmMqMessageFormat, String, int)does, in theUTF_8character set.- Parameters:
mqMessage- the message to write the body toformat- the format the body is written fortext- 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 ownMQMessage. AnMQFMT_STRINGbody 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'sformatfield is left for the caller to set.- Parameters:
mqMessage- the message to write the body toformat- the format the body is written fortext- the bodycharacterSet- the CCSID of anMQFMT_STRINGbody, such asIbmMqCharacterSet.ccsid- Throws:
IOException- if the body cannot be written
-
withResolvedText
Returns a copy withresolvedTextset (the content read frombodyFileNameat load time). Every persisted field is preserved so a subsequent save re-writesbodyFileNamewith nulltext, keeping the sidecar reference intact.- Parameters:
resolvedText- the content of thebodyFileNamefile- Returns:
- the copy
-
effectiveText
The response body content to send: the file-resolvedresolvedTextwhen set, otherwise the inlinetext.- Returns:
- the body, or null when the response has none
-
validate
Checks the response is one Traffic Parrot can send: it does not set bothtextandbodyFileName, and a body read frombodyFileNamehas theMQFMT_STRINGformat.- 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 todestinationonly when it names none.- Returns:
- true if
destinationLookupis empty or the default constant
-
forceMappingDestinationLookup
public boolean forceMappingDestinationLookup()Whether the response goes todestinationwhatever reply-to queue the request names.- Returns:
- true if
destinationLookupisUSE_MAPPING_RESPONSE_DESTINATION
-
hasTransformer
public boolean hasTransformer()Whether the response names a transformer.- Returns:
- true unless
ibmMqResponseTransformerClassNameis blank orNO_TRANSFORMER
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<IbmMqResponse>
-