Java Code Examples for com.github.tomakehurst.wiremock.http.ResponseDefinition#getHeaders()
The following examples show how to use
com.github.tomakehurst.wiremock.http.ResponseDefinition#getHeaders() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IronTestUtils.java From irontest with Apache License 2.0 | 6 votes |
/** * By default, unmatched WireMock stub request (ServeEvent) does not have the actual response headers or response body. * This method update the unmatched serveEvent obtained from the WireMockServer by changing its response headers and body to the actual values. * @param serveEvent * @return the input serveEvent if it was matched; * a new ServeEvent object with all fields same as the input serveEvent, except for the response headers and body, if it was unmatched. */ public static ServeEvent updateUnmatchedStubRequest(ServeEvent serveEvent, WireMockServer wireMockServer) { if (serveEvent.getWasMatched()) { return serveEvent; } else { PlainTextStubNotMatchedRenderer renderer = (PlainTextStubNotMatchedRenderer) wireMockServer.getOptions() .getNotMatchedRenderer(); ResponseDefinition responseDefinition = renderer.render(wireMockServer, serveEvent.getRequest()); LoggedResponse response = serveEvent.getResponse(); com.github.tomakehurst.wiremock.http.HttpHeaders updatedHeaders = responseDefinition.getHeaders(); String updatedBody = responseDefinition.getBody().substring(2); // remove the leading \r\n LoggedResponse updatedResponse = new LoggedResponse(response.getStatus(), updatedHeaders, Encoding.encodeBase64(updatedBody.getBytes()), response.getFault(), null); ServeEvent updatedServeEvent = new ServeEvent(serveEvent.getId(), serveEvent.getRequest(), serveEvent.getStubMapping(), serveEvent.getResponseDefinition(), updatedResponse, serveEvent.getWasMatched(), serveEvent.getTiming()); return updatedServeEvent; } }
Example 2
Source File: WireMockRestServiceServer.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private HttpHeaders responseHeaders(ResponseDefinition response) { HttpHeaders headers = new HttpHeaders(); if (response.getHeaders() != null) { for (HttpHeader header : response.getHeaders().all()) { if (!header.keyEquals("Content-Type")) { for (String value : header.values()) { headers.add(header.key(), value); } } } } return headers; }
Example 3
Source File: WireMockRestServiceServer.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private MediaType contentType(ResponseDefinition response) { String value = null; if (response.getHeaders() != null) { HttpHeader header = response.getHeaders().getHeader("Content-Type"); if (header != null && header.isPresent()) { value = header.firstValue(); } } return value == null ? MediaType.TEXT_PLAIN : MediaType.valueOf(value); }