Package com.trafficparrot.sdk.http
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
FieldsModifier and TypeFieldDescriptionprotected final com.github.tomakehurst.wiremock.http.RequestThe request that stands in for the client's. -
Constructor Summary
ConstructorsConstructorDescriptionTransformedRequestDefinition(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 TypeMethodDescriptioncom.github.tomakehurst.wiremock.http.ResponseDefinitioncopy()voidsetOriginalRequest(com.github.tomakehurst.wiremock.http.Request originalRequest) Keeps the transformed request.toString()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
-
Field Details
-
transformedRequest
protected final com.github.tomakehurst.wiremock.http.Request transformedRequestThe 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 copiedtransformedRequest- the request to use in place of the client's, usually aTransformedRequest
-
-
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:
setOriginalRequestin classcom.github.tomakehurst.wiremock.http.ResponseDefinition- Parameters:
originalRequest- the client's request
-
copy
public com.github.tomakehurst.wiremock.http.ResponseDefinition copy()- Overrides:
copyin classcom.github.tomakehurst.wiremock.http.ResponseDefinition
-
toString
- Overrides:
toStringin classcom.github.tomakehurst.wiremock.http.ResponseDefinition
-