Class IbmMqResponseTransformer
- All Implemented Interfaces:
com.trafficparrot.sdk.internal.RenderableInUI
public class ReplyWithOrderStatus extends IbmMqResponseTransformer {
@Override
protected IbmMqResponse doTransform(Destination requestDestination, MQMessage requestMessage, IbmMqResponse response, Parameters parameters) throws IOException {
String requestBody = SdkIbmMqUtils.readMessageBodySkipHeaders(requestMessage);
String status = requestBody.contains("<urgent>true</urgent>") ? "EXPEDITED" : "QUEUED";
return new IbmMqResponse(response.destination, "<reply><status>" + status + "</status></reply>");
}
}
Put the jar in lib/external, add the class name to trafficparrot.ibmmq.responsetransformers and
restart Traffic Parrot. A mapping uses the transformer by naming its class in a response's
ibmMqResponseTransformerClassName; each response names one transformer at most.
It runs when a request message has matched the mapping, before Traffic Parrot renders the response: the response it
receives is the mapping's as written, Handlebars expressions included, and the one it returns is then rendered and
sent. Because the returned text is rendered, text copied into it from the request message is evaluated as a
template too; to send request content as it is, return a message the extension has built, with
IbmMqResponse.withResponseMessage(com.trafficparrot.sdk.messaging.Destination, com.ibm.mq.MQMessage, long, java.util.Optional<com.trafficparrot.sdk.messaging.DestinationLookup>), which is sent without rendering.
Traffic Parrot creates a new instance for each response it transforms. To use what Traffic Parrot offers
extensions, such as its database connections, give the class a public constructor that takes a
TrafficParrotServices.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.slf4j.LoggerThe logger given to the constructor; by default one named afterIbmMqResponseTransformer. -
Constructor Summary
ConstructorsConstructorDescriptionCreates the transformer with aloggernamed afterIbmMqResponseTransformer.IbmMqResponseTransformer(org.slf4j.Logger logger) Creates the transformer with a logger of the extension's choice. -
Method Summary
Modifier and TypeMethodDescriptionprotected IbmMqResponsedoTransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response) Deprecated.protected IbmMqResponsedoTransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response, com.github.tomakehurst.wiremock.extension.Parameters parameters) Deprecated.OverridedoTransform(Destination, MQMessage, IbmMqResponse, Parameters)instead.protected IbmMqResponsedoTransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response) Deprecated.OverridedoTransform(Destination, MQMessage, IbmMqResponse, Parameters)instead.protected IbmMqResponsedoTransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response, com.github.tomakehurst.wiremock.extension.Parameters parameters) The transformation: override this one, and no otherdoTransform.The name Traffic Parrot's web interface shows for this transformer in a mapping's list of response transformers.final IbmMqResponsetransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response, com.github.tomakehurst.wiremock.extension.Parameters parameters) The entry point for plugins compiled against thecom.trafficparrot.sdk.jmstypes.final IbmMqResponsetransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response, com.github.tomakehurst.wiremock.extension.Parameters parameters) Called by Traffic Parrot.
-
Field Details
-
logger
protected final org.slf4j.Logger loggerThe logger given to the constructor; by default one named afterIbmMqResponseTransformer.
-
-
Constructor Details
-
IbmMqResponseTransformer
public IbmMqResponseTransformer()Creates the transformer with aloggernamed afterIbmMqResponseTransformer. -
IbmMqResponseTransformer
public IbmMqResponseTransformer(org.slf4j.Logger logger) Creates the transformer with a logger of the extension's choice.- Parameters:
logger- theloggerto use, for example one named after the extension's own class
-
-
Method Details
-
transform
public final IbmMqResponse transform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response, com.github.tomakehurst.wiremock.extension.Parameters parameters) Called by Traffic Parrot. RunsdoTransform. If that throws, or returns a response whoseibmMqResponseTransformerClassNameis anything butIbmMqResponse.NO_TRANSFORMER, the error is logged and the reply is a text message whose body is the error message. It goes to the reply-to queue the request names, or to the mapping's response destination when the request names none.- Parameters:
requestDestination- the queue or topic the request message arrived onrequestMessage- the request messageresponse- the mapping's response, as writtenparameters- Traffic Parrot's runtime properties, asdoTransformdescribes- Returns:
- what
doTransformreturned, or the error reply
-
transform
public final IbmMqResponse transform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response, com.github.tomakehurst.wiremock.extension.Parameters parameters) The entry point for plugins compiled against thecom.trafficparrot.sdk.jmstypes.- Parameters:
requestDestination- the queue or topic the request message arrived onrequestMessage- the request messageresponse- the mapping's response, as writtenparameters- Traffic Parrot's runtime properties, asdoTransformdescribes- Returns:
- what
doTransformreturned, or the error reply
-
doTransform
protected IbmMqResponse doTransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response, com.github.tomakehurst.wiremock.extension.Parameters parameters) throws Exception The transformation: override this one, and no otherdoTransform. The other three are the forms earlier extensions override; each is reached only when the ones before it are not overridden.- Parameters:
requestDestination- the queue or topic the request message arrived onrequestMessage- the request message.SdkIbmMqUtilsreads its body and leaves its read position where it wasresponse- the mapping's response, as writtenparameters- Traffic Parrot's runtime properties:(Properties) parameters.get("properties")for the virtual service and"sharedProperties"for the installation root, each withdataDirectory,databaseConnectionsFileandscenarioDirectory- Returns:
- the response to render and send. Its
ibmMqResponseTransformerClassNamemust beIbmMqResponse.NO_TRANSFORMER, as the two-argumentIbmMqResponseconstructor andIbmMqResponse.withResponseMessage(com.trafficparrot.sdk.messaging.Destination, com.ibm.mq.MQMessage, long, java.util.Optional<com.trafficparrot.sdk.messaging.DestinationLookup>)set it - Throws:
Exception- if the response cannot be transformed; the reply is then a text message that names this class and the exception's message, sent astransform(com.trafficparrot.sdk.messaging.Destination, com.ibm.mq.MQMessage, com.trafficparrot.sdk.ibmmq.IbmMqResponse, com.github.tomakehurst.wiremock.extension.Parameters)describes, and the exception is logged
-
doTransform
@Deprecated protected IbmMqResponse doTransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response, com.github.tomakehurst.wiremock.extension.Parameters parameters) throws Exception Deprecated.OverridedoTransform(Destination, MQMessage, IbmMqResponse, Parameters)instead.The transformation as extensions compiled against thecom.trafficparrot.sdk.jmstypes declare it.- Parameters:
requestDestination- the queue or topic the request message arrived onrequestMessage- the request messageresponse- the mapping's response, as writtenparameters- Traffic Parrot's runtime properties- Returns:
- the response to render and send
- Throws:
Exception- if the response cannot be transformed
-
doTransform
@Deprecated protected IbmMqResponse doTransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response) throws Exception Deprecated.OverridedoTransform(Destination, MQMessage, IbmMqResponse, Parameters)instead.For backwards compatibility, allow old extensions to override only the method withoutParameters- Parameters:
requestDestination- the queue or topic the request message arrived onrequestMessage- the request messageresponse- the mapping's response, as written- Returns:
- the response to render and send
- Throws:
Exception- if the response cannot be transformed
-
doTransform
@Deprecated protected IbmMqResponse doTransform(Destination requestDestination, com.ibm.mq.MQMessage requestMessage, IbmMqResponse response) throws Exception Deprecated.OverridedoTransform(Destination, MQMessage, IbmMqResponse, Parameters)instead.The transformation as the earliest extensions declare it: withoutParameters, and with thecom.trafficparrot.sdk.jmsdestination type.- Parameters:
requestDestination- the queue or topic the request message arrived onrequestMessage- the request messageresponse- the mapping's response, as written- Returns:
- the response to render and send
- Throws:
Exception- if the response cannot be transformedIllegalStateException- if the extension overrides nodoTransformmethod
-
getDisplayName
The name Traffic Parrot's web interface shows for this transformer in a mapping's list of response transformers.- Specified by:
getDisplayNamein interfacecom.trafficparrot.sdk.internal.RenderableInUI- Returns:
- the class's simple name, unless overridden
-
doTransform(Destination, MQMessage, IbmMqResponse, Parameters)instead.