Package com.trafficparrot.sdk.messaging
Class JmsResponse
java.lang.Object
com.trafficparrot.sdk.messaging.JmsResponse
- All Implemented Interfaces:
Comparable<JmsResponse>
- Direct Known Subclasses:
JmsResponse
The response of a JMS mapping: the message Traffic Parrot sends when a request message matches. A
JmsResponseTransformer receives the mapping's response and returns the one to send:
return new JmsResponse(response.destination, "{\"status\": \"received\"}");
or, to send a message it has built itself, withJakartaResponseMessage(com.trafficparrot.sdk.messaging.Destination, jakarta.jms.Message, long, java.util.Optional<com.trafficparrot.sdk.messaging.DestinationLookup>). 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 MessageBodyTypeHowtextis turned into the message body;TEXTwhen none is given.final DestinationThe queue or topic the response is sent to, unlessdestinationLookupsends it to the request's reply-to destination.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 Optional<jakarta.jms.Message>AJmsResponseTransformercan return a jakarta.jms.Message object instead of just transforming the mapping values.final StringThe class name of a kind of JMS message,javax.jms.TextMessageorjavax.jms.BytesMessage; when none is given, the oneJmsMessageType.jmsMessageType(com.trafficparrot.sdk.messaging.MessageBodyType)gives for thebodyType.final StringThe class name of theJmsResponseTransformerthe mapping uses, orNO_TRANSFORMER.final com.github.tomakehurst.wiremock.extension.ParametersThe mapping's own parameters for its transformer, which reads them from the response it is given; null when the mapping has none.static final StringThejmsResponseTransformerClassNameof a response that uses no transformer.final List<JmsProperty>The JMS properties to set on the response message; empty when there are none.final StringContent resolved frombodyFileNameat load time.final Optional<javax.jms.Message>Deprecated.final StringThe message body, which may hold Handlebars expressions. -
Constructor Summary
ConstructorsModifierConstructorDescriptionJmsResponse(Destination destination, Object object) Creates a response that uses no transformer and whose body is a Java object, held as its JSON with the object's class as the body type.JmsResponse(Destination destination, String text) Creates a text response that uses no transformer, which is what a transformer usually returns.protectedJmsResponse(Destination destination, String jmsResponseTransformerClassName, com.github.tomakehurst.wiremock.extension.Parameters jmsResponseTransformerParameters, String text, String bodyFileName, MessageBodyType bodyType, String jmsMessageType, List<? extends JmsProperty> properties, Long fixedDelayInMilliseconds, Optional<DestinationLookup> destinationLookup, Optional<javax.jms.Message> responseMessage, Optional<jakarta.jms.Message> jakartaResponseMessage, String resolvedText) Creates a response with every field, for a subclass.JmsResponse(Destination destination, String jmsResponseTransformerClassName, com.github.tomakehurst.wiremock.extension.Parameters jmsResponseTransformerParameters, String text, String bodyFileName, MessageBodyType bodyType, String jmsMessageType, List<JmsProperty> properties, Long fixedDelayInMilliseconds, Optional<DestinationLookup> destinationLookup, Optional<javax.jms.Message> responseMessage) Creates a response with every field a mapping file can set.JmsResponse(Destination destination, String jmsResponseTransformerClassName, Object object) Creates a response whose body is a Java object, held as its JSON with the object's class as the body type.JmsResponse(Destination destination, String jmsResponseTransformerClassName, String text) Creates a text response with no JMS properties and no delay.JmsResponse(Destination destination, String jmsResponseTransformerClassName, String text, MessageBodyType bodyType) Creates a response with an inline body of a given type, no JMS properties and no delay.JmsResponse(Destination destination, String jmsResponseTransformerClassName, String text, MessageBodyType bodyType, String jmsMessageType, List<JmsProperty> properties, Long fixedDelayInMilliseconds) Creates a response with an inline body, JMS properties, a delay and a JMS message type.JmsResponse(Destination destination, String jmsResponseTransformerClassName, String text, MessageBodyType bodyType, List<JmsProperty> properties, long fixedDelayInMilliseconds) Creates a response with an inline body, JMS properties and a delay, sent as the kind of JMS message that suits the body type. -
Method Summary
Modifier and TypeMethodDescriptionstatic JmsResponsebase64BytesResponse(Destination destination, byte[] bytes) A response that uses no transformer and whose body is these bytes, held as Base64 with theBYTESbody type.static JmsResponsebase64BytesResponse(Destination destination, String jmsResponseTransformerClassName, byte[] bytes) A response whose body is these bytes, held as Base64 with theBYTESbody type.intcompareTo(JmsResponse other) The response body content to send: the file-resolvedresolvedTextwhen set, otherwise the inlinetext.booleanWhether the response names a transformer.static JmsResponseprintableCharactersBytesResponse(Destination destination, byte[] bytes) A response that uses no transformer and whose body is these bytes, held in the printable-characters encoding with thePRINTABLE_CHARACTERSbody type, which keeps readable text readable in the mapping file.static JmsResponseprintableCharactersBytesResponse(Destination destination, String jmsResponseTransformerClassName, byte[] bytes) A response whose body is these bytes, held in the printable-characters encoding with thePRINTABLE_CHARACTERSbody type.toString()voidvalidate()Checks the response is one Traffic Parrot can send: it does not set bothtextandbodyFileName, a body read frombodyFileNamehas theTEXTbody type, and the text of a Java object body is JSON that reads as an object of its class (Handlebars expressions are read as null).static JmsResponsewithJakartaResponseMessage(Destination destination, jakarta.jms.Message jakartaMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup) A response that sends ajakarta.jmsmessage the transformer has built itself, in place of one built from a body and a body type.withResolvedText(String resolvedText) Returns a copy withresolvedTextset (the content read frombodyFileNameat load time).
-
Field Details
-
NO_TRANSFORMER
ThejmsResponseTransformerClassNameof 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 destination. -
jmsResponseTransformerClassName
The class name of theJmsResponseTransformerthe mapping uses, orNO_TRANSFORMER. -
jmsResponseTransformerParameters
public final com.github.tomakehurst.wiremock.extension.Parameters jmsResponseTransformerParametersThe mapping's own parameters for its transformer, which reads them from the response it is given; null when the mapping has none. They are not part of theparametersargument ofdoTransform. -
text
The message body, which may hold Handlebars expressions. How it is written depends on thebodyType: as text, as the bytes its Base64 or printable-characters text encodes, or as the Java object or protobuf message its JSON describes. Null when the body comes frombodyFileNameor the response carries a message. -
bodyFileName
A file under__filesthat holds the body, used in place of an inlinetext. Supported only with theTEXTbody type. -
bodyType
Howtextis turned into the message body;TEXTwhen none is given. -
jmsMessageType
The class name of a kind of JMS message,javax.jms.TextMessageorjavax.jms.BytesMessage; when none is given, the oneJmsMessageType.jmsMessageType(com.trafficparrot.sdk.messaging.MessageBodyType)gives for thebodyType. It is saved with the mapping. The kind of message Traffic Parrot sends is decided by thebodyType, not by this. -
properties
The JMS properties to set on the response message; empty when there are none. -
destinationLookup
Where the response is sent. Empty, or the default constant, sends it to the reply-to destination the request names and todestinationwhen it names none;USE_MAPPING_RESPONSE_DESTINATIONsends it todestination. -
fixedDelayMilliseconds
public final long fixedDelayMillisecondsHow long Traffic Parrot waits before it sends the response, in milliseconds; 0 for no delay. -
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
Deprecated.UsejakartaResponseMessageinstead. This field is kept for backward compatibility with old javax.jms customer plugins. -
jakartaResponseMessage
AJmsResponseTransformercan return a jakarta.jms.Message object instead of just transforming the mapping values. The framework reads this field first; if empty, falls back toresponseMessagefor old plugins.
-
-
Constructor Details
-
JmsResponse
public JmsResponse(Destination destination, String jmsResponseTransformerClassName, com.github.tomakehurst.wiremock.extension.Parameters jmsResponseTransformerParameters, String text, String bodyFileName, MessageBodyType bodyType, String jmsMessageType, List<JmsProperty> properties, Long fixedDelayInMilliseconds, Optional<DestinationLookup> destinationLookup, Optional<javax.jms.Message> responseMessage) 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 tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMERjmsResponseTransformerParameters- the mapping's parameters for its transformer; may be nulltext- the body; null whenbodyFileNameis setbodyFileName- a file under__filesto read the body from; null whentextis setbodyType- how the text is turned into the message body; null forTEXTjmsMessageType- the class name kept asjmsMessageType; null for the one that suits the body typeproperties- the JMS properties to set on the message; null for nonefixedDelayInMilliseconds- the delay before sending, in milliseconds; null for nonedestinationLookup- where the response is sent, asdestinationLookupdescribesresponseMessage- ajavax.jmsmessage to send as it is, in place of one built from the other fields; a mapping file cannot set it
-
JmsResponse
protected JmsResponse(Destination destination, String jmsResponseTransformerClassName, com.github.tomakehurst.wiremock.extension.Parameters jmsResponseTransformerParameters, String text, String bodyFileName, MessageBodyType bodyType, String jmsMessageType, List<? extends JmsProperty> properties, Long fixedDelayInMilliseconds, Optional<DestinationLookup> destinationLookup, Optional<javax.jms.Message> responseMessage, Optional<jakarta.jms.Message> jakartaResponseMessage, String resolvedText) Creates a response with every field, for a subclass.- Parameters:
destination- the queue or topic to send the response tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMERjmsResponseTransformerParameters- the mapping's parameters for its transformer; may be nulltext- the body; null whenbodyFileNameis setbodyFileName- a file under__filesto read the body from; null whentextis setbodyType- how the text is turned into the message body; null forTEXTjmsMessageType- the class name kept asjmsMessageType; null for the one that suits the body typeproperties- the JMS properties to set on the message; null for none. The list is kept as given, not copiedfixedDelayInMilliseconds- the delay before sending, in milliseconds; null for nonedestinationLookup- where the response is sent, asdestinationLookupdescribesresponseMessage- ajavax.jmsmessage to send as it is; empty to build onejakartaResponseMessage- ajakarta.jmsmessage to send as it is; empty to build oneresolvedText- the content read frombodyFileName; null when there is none
-
JmsResponse
public JmsResponse(Destination destination, String jmsResponseTransformerClassName, String text, MessageBodyType bodyType, String jmsMessageType, List<JmsProperty> properties, Long fixedDelayInMilliseconds) Creates a response with an inline body, JMS properties, a delay and a JMS message type. It goes to the reply-to destination the request names, or todestinationwhen it names none.- Parameters:
destination- the queue or topic to send the response tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMER, which a response returned from a transformer must carrytext- the bodybodyType- how the text is turned into the message body; null forTEXTjmsMessageType- the class name kept asjmsMessageType; null for the one that suits the body typeproperties- the JMS properties to set on the message; null for nonefixedDelayInMilliseconds- the delay before sending, in milliseconds; null for none
-
JmsResponse
public JmsResponse(Destination destination, String jmsResponseTransformerClassName, String text, MessageBodyType bodyType, List<JmsProperty> properties, long fixedDelayInMilliseconds) Creates a response with an inline body, JMS properties and a delay, sent as the kind of JMS message that suits the body type.- Parameters:
destination- the queue or topic to send the response tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMER, which a response returned from a transformer must carrytext- the bodybodyType- how the text is turned into the message body; null forTEXTproperties- the JMS properties to set on the message; null for nonefixedDelayInMilliseconds- the delay before sending, in milliseconds; 0 for none
-
JmsResponse
public JmsResponse(Destination destination, String jmsResponseTransformerClassName, String text, MessageBodyType bodyType) Creates a response with an inline body of a given type, no JMS properties and no delay.- Parameters:
destination- the queue or topic to send the response tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMER, which a response returned from a transformer must carrytext- the bodybodyType- how the text is turned into the message body; null forTEXT
-
JmsResponse
Creates a text response with no JMS properties and no delay.- Parameters:
destination- the queue or topic to send the response tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMER, which a response returned from a transformer must carrytext- the body
-
JmsResponse
Creates a text response that uses no transformer, which is what a transformer usually returns. It has no JMS properties and no delay.- Parameters:
destination- the queue or topic to send the response to when the request names no reply-to destinationtext- the body
-
JmsResponse
public JmsResponse(Destination destination, String jmsResponseTransformerClassName, Object object) throws com.fasterxml.jackson.core.JsonProcessingException Creates a response whose body is a Java object, held as its JSON with the object's class as the body type.- Parameters:
destination- the queue or topic to send the response tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMER, which a response returned from a transformer must carryobject- the object to send- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if the object cannot be written as JSON
-
JmsResponse
public JmsResponse(Destination destination, Object object) throws com.fasterxml.jackson.core.JsonProcessingException Creates a response that uses no transformer and whose body is a Java object, held as its JSON with the object's class as the body type.- Parameters:
destination- the queue or topic to send the response toobject- the object to send- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if the object cannot be written as JSON
-
-
Method Details
-
base64BytesResponse
A response that uses no transformer and whose body is these bytes, held as Base64 with theBYTESbody type.- Parameters:
destination- the queue or topic to send the response tobytes- the body- Returns:
- the response
-
base64BytesResponse
public static JmsResponse base64BytesResponse(Destination destination, String jmsResponseTransformerClassName, byte[] bytes) A response whose body is these bytes, held as Base64 with theBYTESbody type.- Parameters:
destination- the queue or topic to send the response tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMERbytes- the body- Returns:
- the response
-
printableCharactersBytesResponse
A response that uses no transformer and whose body is these bytes, held in the printable-characters encoding with thePRINTABLE_CHARACTERSbody type, which keeps readable text readable in the mapping file.- Parameters:
destination- the queue or topic to send the response tobytes- the body- Returns:
- the response
-
printableCharactersBytesResponse
public static JmsResponse printableCharactersBytesResponse(Destination destination, String jmsResponseTransformerClassName, byte[] bytes) A response whose body is these bytes, held in the printable-characters encoding with thePRINTABLE_CHARACTERSbody type.- Parameters:
destination- the queue or topic to send the response tojmsResponseTransformerClassName- the transformer's class name, orNO_TRANSFORMERbytes- the body- Returns:
- the response
-
withJakartaResponseMessage
public static JmsResponse withJakartaResponseMessage(Destination destination, jakarta.jms.Message jakartaMessage, long fixedDelayMilliseconds, Optional<DestinationLookup> destinationLookup) A response that sends ajakarta.jmsmessage the transformer has built itself, in place of one built from a body and a body type.- Parameters:
destination- the queue or topic to send the response tojakartaMessage- the message to sendfixedDelayMilliseconds- the delay before sending, in milliseconds; 0 for nonedestinationLookup- where the response is sent, asdestinationLookupdescribes- Returns:
- the response, which uses no transformer
-
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
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<JmsResponse>
-
hasTransformer
public boolean hasTransformer()Whether the response names a transformer.- Returns:
- true unless
jmsResponseTransformerClassNameis blank orNO_TRANSFORMER
-
validate
Checks the response is one Traffic Parrot can send: it does not set bothtextandbodyFileName, a body read frombodyFileNamehas theTEXTbody type, and the text of a Java object body is JSON that reads as an object of its class (Handlebars expressions are read as null).- Throws:
IOException- if it is not, with a message saying which rule it breaks
-
jakartaResponseMessageinstead.