private void addContentTypeHeader(HttpResponse httpResponse, HttpServletResponse httpServletResponse) { if (httpServletResponse.getContentType() == null && httpResponse.getBody() != null && httpResponse.getBody().getContentType() != null) { httpServletResponse.addHeader(CONTENT_TYPE.toString(), httpResponse.getBody().getContentType()); } } }
private void setBody(HttpResponse httpResponse, HttpServletResponse httpServletResponse) { if (httpResponse.getBodyAsString() != null) { if (httpResponse.getBody() instanceof BinaryBody) { IOStreamUtils.writeToOutputStream(base64Converter.base64StringToBytes(httpResponse.getBodyAsString()), httpServletResponse); } else { Charset bodyCharset = httpResponse.getBody().getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(httpResponse.getFirstHeader(CONTENT_TYPE.toString()))); IOStreamUtils.writeToOutputStream(httpResponse.getBodyAsString().getBytes(bodyCharset), httpServletResponse); } } }
outputCookies(numberOfSpacesToIndent + 1, output, httpResponse.getCookieList()); if (!Strings.isNullOrEmpty(httpResponse.getBodyAsString())) { if (httpResponse.getBody() instanceof BinaryBody) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output); BinaryBody body = (BinaryBody) httpResponse.getBody(); output.append(".withBody(new Base64Converter().base64StringToBytes(\"").append(base64Converter.bytesToBase64String(body.getRawBytes())).append("\"))"); } else {
private ByteBuf getBody(HttpResponse response) { ByteBuf content = Unpooled.buffer(0, 0); Body body = response.getBody(); if (body != null) { Object bodyContents = body.getValue(); Charset bodyCharset = body.getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(response.getFirstHeader(CONTENT_TYPE.toString()))); if (bodyContents instanceof byte[]) { content = Unpooled.copiedBuffer((byte[]) bodyContents); } else if (bodyContents instanceof String) { content = Unpooled.copiedBuffer(((String) bodyContents).getBytes(bodyCharset)); } else if (body.toString() != null) { content = Unpooled.copiedBuffer(body.toString().getBytes(bodyCharset)); } } return content; }
private void setBody(HttpResponse httpResponse, HttpServletResponse httpServletResponse) { if (httpResponse.getBodyAsString() != null) { if (httpResponse.getBody() instanceof BinaryBody) { IOStreamUtils.writeToOutputStream(base64Converter.base64StringToBytes(httpResponse.getBodyAsString()), httpServletResponse); } else { Charset bodyCharset = httpResponse.getBody().getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(httpResponse.getFirstHeader(CONTENT_TYPE.toString()))); IOStreamUtils.writeToOutputStream(httpResponse.getBodyAsString().getBytes(bodyCharset), httpServletResponse); } } }
jgen.writeObjectField("cookies", httpResponse.getCookies()); Body body = httpResponse.getBody(); if (body != null) { if (body instanceof StringBody && !((StringBody) body).getValue().isEmpty()) {
outputCookies(numberOfSpacesToIndent + 1, output, httpResponse.getCookieList()); if (!Strings.isNullOrEmpty(httpResponse.getBodyAsString())) { if (httpResponse.getBody() instanceof BinaryBody) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output); BinaryBody body = (BinaryBody) httpResponse.getBody(); output.append(".withBody(new Base64Converter().base64StringToBytes(\"").append(base64Converter.bytesToBase64String(body.getRawBytes())).append("\"))"); } else {
if (response.getBody() != null && response.getBody().getContentType() != null) { fullHttpResponse.headers().set(CONTENT_TYPE, response.getBody().getContentType()); fullHttpResponse.headers().set(CONTENT_LENGTH, connectionOptions.getContentLengthHeaderOverride()); } else if (addContentLength) { Body body = response.getBody(); byte[] bodyBytes = new byte[0]; if (body != null) {
void sendExpectation(Expectation expectation) { HttpResponse httpResponse = sendRequest(request().withMethod("PUT").withPath(calculatePath("expectation")).withBody(expectation != null ? expectationSerializer.serialize(expectation) : "", StandardCharsets.UTF_8)); if (httpResponse != null && httpResponse.getStatusCode() != 201) { throw new ClientException(formatLogMessage("error:{}while submitted expectation:{}", httpResponse.getBody(), expectation)); } }
public HttpResponseDTO(HttpResponse httpResponse) { if (httpResponse != null) { statusCode = httpResponse.getStatusCode(); reasonPhrase = httpResponse.getReasonPhrase(); body = BodyWithContentTypeDTO.createDTO(httpResponse.getBody()); headers = httpResponse.getHeaders(); cookies = httpResponse.getCookies(); delay = (httpResponse.getDelay() != null ? new DelayDTO(httpResponse.getDelay()) : null); connectionOptions = (httpResponse.getConnectionOptions() != null ? new ConnectionOptionsDTO(httpResponse.getConnectionOptions()) : null); } }
private void addContentTypeHeader(HttpResponse httpResponse, HttpServletResponse httpServletResponse) { if (httpServletResponse.getContentType() == null && httpResponse.getBody() != null && httpResponse.getBody().getContentType() != null) { httpServletResponse.addHeader(CONTENT_TYPE.toString(), httpResponse.getBody().getContentType()); } } }
private ByteBuf getBody(HttpResponse response) { ByteBuf content = Unpooled.buffer(0, 0); Body body = response.getBody(); if (body != null) { Object bodyContents = body.getValue(); Charset bodyCharset = body.getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(response.getFirstHeader(CONTENT_TYPE.toString()))); if (bodyContents instanceof byte[]) { content = Unpooled.copiedBuffer((byte[]) bodyContents); } else if (bodyContents instanceof String) { content = Unpooled.copiedBuffer(((String) bodyContents).getBytes(bodyCharset)); } else if (body.toString() != null) { content = Unpooled.copiedBuffer(body.toString().getBytes(bodyCharset)); } } return content; }
jgen.writeObjectField("cookies", httpResponse.getCookies()); Body body = httpResponse.getBody(); if (body != null) { if (body instanceof StringBody && !((StringBody) body).getValue().isEmpty()) {
if (response.getBody() != null && response.getBody().getContentType() != null) { fullHttpResponse.headers().set(CONTENT_TYPE, response.getBody().getContentType()); fullHttpResponse.headers().set(CONTENT_LENGTH, connectionOptions.getContentLengthHeaderOverride()); } else if (addContentLength) { Body body = response.getBody(); byte[] bodyBytes = new byte[0]; if (body != null) {
void sendExpectation(Expectation expectation) { HttpResponse httpResponse = sendRequest(request().withMethod("PUT").withPath(calculatePath("expectation")).withBody(expectation != null ? expectationSerializer.serialize(expectation) : "", StandardCharsets.UTF_8)); if (httpResponse != null && httpResponse.getStatusCode() != 201) { throw new ClientException(formatLogMessage("error:{}while submitted expectation:{}", httpResponse.getBody(), expectation)); } }
public HttpResponseDTO(HttpResponse httpResponse) { if (httpResponse != null) { statusCode = httpResponse.getStatusCode(); reasonPhrase = httpResponse.getReasonPhrase(); body = BodyWithContentTypeDTO.createDTO(httpResponse.getBody()); headers = httpResponse.getHeaders(); cookies = httpResponse.getCookies(); delay = (httpResponse.getDelay() != null ? new DelayDTO(httpResponse.getDelay()) : null); connectionOptions = (httpResponse.getConnectionOptions() != null ? new ConnectionOptionsDTO(httpResponse.getConnectionOptions()) : null); } }