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; }
public String getContentType() { if (this instanceof BodyWithContentType) { return this.getContentType(); } return null; }
@JsonIgnore public byte[] getBodyAsRawBytes() { return this.body != null ? this.body.getRawBytes() : new byte[0]; }
jgen.writeBooleanField("secure", httpRequest.isSecure()); if (httpRequest.getBody() != null && !Strings.isNullOrEmpty(String.valueOf(httpRequest.getBody().getValue()))) { jgen.writeObjectField("body", httpRequest.getBody());
private boolean bodyMatches(HttpRequest context, HttpRequest request) { boolean bodyMatches = true; String bodyAsString = request.getBody() != null ? new String(request.getBody().getRawBytes(), request.getBody().getCharset(StandardCharsets.UTF_8)) : ""; if (!bodyAsString.isEmpty()) { if (bodyMatcher instanceof BinaryMatcher) { bodyMatches = matches(context, bodyMatcher, request.getBodyAsRawBytes()); } else { if (bodyMatcher instanceof ExactStringMatcher || bodyMatcher instanceof SubStringMatcher || bodyMatcher instanceof RegexStringMatcher || bodyMatcher instanceof XmlStringMatcher) { bodyMatches = matches(context, bodyMatcher, string(bodyAsString)); } else { bodyMatches = matches(context, bodyMatcher, bodyAsString); } } if (!bodyMatches) { try { bodyMatches = bodyDTOMatcher.equals(objectMapper.readValue(bodyAsString, BodyDTO.class)); } catch (Throwable e) { // ignore this exception as this exception would typically get thrown for "normal" HTTP requests (i.e. not clear or retrieve) } } } return bodyMatches; }
@JsonIgnore public String getBodyAsString() { if (body != null) { return body.toString(); } else { return null; } }
@JsonIgnore public Charset getCharset(Charset defaultIfNotSet) { if (this instanceof BodyWithContentType) { return this.getCharset(defaultIfNotSet); } return defaultIfNotSet; }
headersToIgnore) ); assertEquals(StaticTestExpectationResponseCallback.httpRequests.get(0).getBody().getValue(), "an_example_body_http"); assertEquals(StaticTestExpectationResponseCallback.httpRequests.get(0).getPath().getValue(), calculatePath("callback")); assertEquals(StaticTestExpectationResponseCallback.httpRequests.get(1).getBody().getValue(), "an_example_body_https"); assertEquals(StaticTestExpectationResponseCallback.httpRequests.get(1).getPath().getValue(), calculatePath("callback"));
private boolean bodyMatches(HttpRequest context, HttpRequest request) { boolean bodyMatches = true; String bodyAsString = request.getBody() != null ? new String(request.getBody().getRawBytes(), request.getBody().getCharset(StandardCharsets.UTF_8)) : ""; if (!bodyAsString.isEmpty()) { if (bodyMatcher instanceof BinaryMatcher) { bodyMatches = matches(context, bodyMatcher, request.getBodyAsRawBytes()); } else { if (bodyMatcher instanceof ExactStringMatcher || bodyMatcher instanceof SubStringMatcher || bodyMatcher instanceof RegexStringMatcher || bodyMatcher instanceof XmlStringMatcher) { bodyMatches = matches(context, bodyMatcher, string(bodyAsString)); } else { bodyMatches = matches(context, bodyMatcher, bodyAsString); } } if (!bodyMatches) { try { bodyMatches = bodyDTOMatcher.equals(objectMapper.readValue(bodyAsString, BodyDTO.class)); } catch (Throwable e) { // ignore this exception as this exception would typically get thrown for "normal" HTTP requests (i.e. not clear or retrieve) } } } return bodyMatches; }
@JsonIgnore public byte[] getRawBytes() { return toString().getBytes(UTF_8); }
@JsonIgnore public Charset getCharset(Charset defaultIfNotSet) { if (this instanceof BodyWithContentType) { return this.getCharset(defaultIfNotSet); } return defaultIfNotSet; }
private ByteBuf getBody(HttpRequest httpRequest) { ByteBuf content = Unpooled.buffer(0, 0); Body body = httpRequest.getBody(); if (body != null) { Object bodyContents = body.getValue(); Charset bodyCharset = body.getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(httpRequest.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.writeBooleanField("secure", httpRequest.isSecure()); if (httpRequest.getBody() != null && !Strings.isNullOrEmpty(String.valueOf(httpRequest.getBody().getValue()))) { jgen.writeObjectField("body", httpRequest.getBody());
&& httpRequest.getBody().getContentType() != null) { request.headers().set(CONTENT_TYPE, httpRequest.getBody().getContentType());
@JsonIgnore public String getBodyAsString() { if (body != null) { return body.toString(); } else { return null; } }
@JsonIgnore public byte[] getBodyAsRawBytes() { return this.body != null ? this.body.getRawBytes() : new byte[0]; }
byte[] bodyBytes = new byte[0]; if (body != null) { Object bodyContents = body.getValue(); Charset bodyCharset = body.getCharset(ContentTypeMapper.getCharsetFromContentTypeHeader(response.getFirstHeader(CONTENT_TYPE.toString()))); if (bodyContents instanceof byte[]) { bodyBytes = (byte[]) bodyContents; } else if (bodyContents instanceof String) { bodyBytes = ((String) bodyContents).getBytes(bodyCharset); } else if (body.toString() != null) { bodyBytes = body.toString().getBytes(bodyCharset);
public String getContentType() { if (this instanceof BodyWithContentType) { return this.getContentType(); } return null; }