public static ObjectPath createFromResponse(Response response) throws IOException { byte[] bytes = EntityUtils.toByteArray(response.getEntity()); String contentType = response.getHeader("Content-Type"); XContentType xContentType = XContentType.fromMediaTypeOrFormat(contentType); return ObjectPath.createFromXContent(xContentType.xContent(), new BytesArray(bytes)); }
public ClientYamlTestResponse(Response response) throws IOException { this.response = response; if (response.getEntity() != null) { String contentType = response.getHeader("Content-Type"); this.bodyContentType = XContentType.fromMediaTypeOrFormat(contentType); try { byte[] bytes = EntityUtils.toByteArray(response.getEntity()); //skip parsing if we got text back (e.g. if we called _cat apis) if (bodyContentType != null) { this.parsedResponse = ObjectPath.createFromXContent(bodyContentType.xContent(), new BytesArray(bytes)); } this.body = bytes; } catch (IOException e) { EntityUtils.consumeQuietly(response.getEntity()); throw e; } } else { this.body = null; this.bodyContentType = null; } }