Class TransformedRequestDefinition

java.lang.Object
com.github.tomakehurst.wiremock.http.ResponseDefinition
com.trafficparrot.sdk.http.TransformedRequestDefinition

public class TransformedRequestDefinition extends com.github.tomakehurst.wiremock.http.ResponseDefinition
A response definition that carries a changed request. An HttpResponseDefinitionTransformer returns one so that a proxied mapping sends the changed request to the backend in place of the one the client sent:

 public class AddRequestIdHeader extends HttpResponseDefinitionTransformer {
     @Override
     public ResponseDefinition doTransform(ServeEvent serveEvent, Parameters parameters) {
         ResponseDefinition responseDefinition = serveEvent.getResponseDefinition();
         if (!responseDefinition.isProxyResponse()) {
             return responseDefinition;
         }
         Request request = TransformedRequest.like(serveEvent.getRequest())
                 .withHeader(HttpHeader.httpHeader("X-Request-Id", UUID.randomUUID().toString()));
         return new TransformedRequestDefinition(responseDefinition, request);
     }

     @Override
     public String getName() {
         return "addRequestIdHeader";
     }
 }
 
The changed request is sent only while HTTP response templating is off (trafficparrot.http.handlebars.enabled=false). With templating on, as Traffic Parrot ships, the backend receives the client's request unchanged.

Wrap the response definition of a proxied mapping only. The copy keeps its status, headers, proxy settings, delays, fault and transformers, but not the body a mapping answers with itself: an inline text body is no longer rendered and a body file is no longer read, so check isProxyResponse() first, as the example does.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final com.github.tomakehurst.wiremock.http.Request
    The request that stands in for the client's.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TransformedRequestDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition original, com.github.tomakehurst.wiremock.http.Request transformedRequest)
    Creates a copy of a response definition that carries a changed request.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.github.tomakehurst.wiremock.http.ResponseDefinition
     
    void
    setOriginalRequest(com.github.tomakehurst.wiremock.http.Request originalRequest)
    Keeps the transformed request.
     

    Methods inherited from class com.github.tomakehurst.wiremock.http.ResponseDefinition

    badRequest, badRequestEntity, browserProxy, copyOf, created, equals, getAdditionalProxyRequestHeaders, getBase64Body, getBody, getBodyFileName, getByteBody, getByteBodyIfBinary, getChunkedDribbleDelay, getDelayDistribution, getFault, getFixedDelayMilliseconds, getHeaders, getJsonBody, getOriginalRequest, getProxyBaseUrl, getProxyUrl, getProxyUrlPrefixToRemove, getRemoveProxyRequestHeaders, getReponseBody, getStatus, getStatusMessage, getTextBody, getTransformerParameters, getTransformers, hashCode, hasTransformer, isFromConfiguredStub, isProxyResponse, noContent, notAuthorised, notConfigured, notFound, notPermitted, notPermitted, ok, okEmptyJson, okForJson, redirectTo, specifiesBinaryBodyContent, specifiesBodyContent, specifiesBodyFile, specifiesTextBodyContent, wasConfigured

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • transformedRequest

      protected final com.github.tomakehurst.wiremock.http.Request transformedRequest
      The request that stands in for the client's.
  • Constructor Details

    • TransformedRequestDefinition

      public TransformedRequestDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition original, com.github.tomakehurst.wiremock.http.Request transformedRequest)
      Creates a copy of a response definition that carries a changed request.
      Parameters:
      original - a proxied mapping's response definition, whose status, headers, proxy settings, delays, fault, transformers and transformer parameters are copied
      transformedRequest - the request to use in place of the client's, usually a TransformedRequest
  • Method Details

    • setOriginalRequest

      public void setOriginalRequest(com.github.tomakehurst.wiremock.http.Request originalRequest)
      Keeps the transformed request. Traffic Parrot calls this with the client's request, which is logged at INFO beside the transformed one and otherwise disregarded.
      Overrides:
      setOriginalRequest in class com.github.tomakehurst.wiremock.http.ResponseDefinition
      Parameters:
      originalRequest - the client's request
    • copy

      public com.github.tomakehurst.wiremock.http.ResponseDefinition copy()
      Overrides:
      copy in class com.github.tomakehurst.wiremock.http.ResponseDefinition
    • toString

      public String toString()
      Overrides:
      toString in class com.github.tomakehurst.wiremock.http.ResponseDefinition