private static XContentParser createParser(String mediaType, String content) throws IOException { return XContentType.fromMediaTypeOrFormat(mediaType) // .xContent() // .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, content); }
XContentType responseContentType = XContentType.fromMediaTypeOrFormat(format); if (responseContentType == null) { if (requestContentType != null) {
public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception { RestRequest request = channel.request(); XContentType xContentType = XContentType.fromMediaTypeOrFormat(request.param("format", request.header("Accept"))); if (xContentType != null) { return buildXContentBuilder(table, channel); } return buildTextPlainResponse(table, channel); }
XContentType contentType = XContentType.fromMediaTypeOrFormat(options.get(CONTENT_TYPE_OPTION)); out.writeBoolean(true); out.writeEnum(contentType);
protected final <Resp> Resp parseEntity(final HttpEntity entity, final CheckedFunction<XContentParser, Resp, IOException> entityParser) throws IOException { if (entity == null) { throw new IllegalStateException("Response body expected but not returned"); } if (entity.getContentType() == null) { throw new IllegalStateException("Elasticsearch didn't return the [Content-Type] header, unable to parse response body"); } XContentType xContentType = XContentType.fromMediaTypeOrFormat(entity.getContentType().getValue()); if (xContentType == null) { throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue()); } try (XContentParser parser = xContentType.xContent().createParser(registry, DEPRECATION_HANDLER, entity.getContent())) { return entityParser.apply(parser); } }
protected final <Resp> Resp parseEntity(final HttpEntity entity, final CheckedFunction<XContentParser, Resp, IOException> entityParser) throws IOException { if (entity == null) { throw new IllegalStateException("Response body expected but not returned"); } if (entity.getContentType() == null) { throw new IllegalStateException("Elasticsearch didn't return the [Content-Type] header, unable to parse response body"); } XContentType xContentType = XContentType.fromMediaTypeOrFormat(entity.getContentType().getValue()); if (xContentType == null) { throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue()); } try (XContentParser parser = xContentType.xContent().createParser(registry, DEPRECATION_HANDLER, entity.getContent())) { return entityParser.apply(parser); } }
/** * Convert the entity from a {@link Response} into a map of maps. */ public Map<String, Object> entityAsMap(Response response) throws IOException { XContentType xContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue()); try (XContentParser parser = createParser(xContentType.xContent(), response.getEntity().getContent())) { return parser.map(); } }
XContentType responseContentType = XContentType.fromMediaTypeOrFormat(format); if (responseContentType == null) { if (requestContentType != null) {
XContentType responseContentType = XContentType.fromMediaTypeOrFormat(format); if (responseContentType == null) { if (requestContentType != null) {
XContentType responseContentType = XContentType.fromMediaTypeOrFormat(format); if (responseContentType == null) { if (requestContentType != null) {
protected final <Resp> Resp parseEntity(final Response entity, final CheckedFunction<XContentParser, Resp, IOException> entityParser) throws IOException { XContentType xContentType = XContentType.fromMediaTypeOrFormat(entity.contentType()); if (xContentType == null) { throw new IllegalStateException("Unsupported Content-Type: " + entity.contentType()); } try (XContentParser parser = xContentType.xContent().createParser(registry, entity.bodyString())) { return entityParser.apply(parser); } }
throw new IllegalStateException("Elasticsearch didn't return the [Content-Type] header, unable to parse response body"); XContentType xContentType = XContentType.fromMediaTypeOrFormat(entity.getContentType().getValue()); if (xContentType == null) { throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue());
throw new IllegalStateException("Elasticsearch didn't return the [Content-Type] header, unable to parse response body"); XContentType xContentType = XContentType.fromMediaTypeOrFormat(entity.getContentType().getValue()); if (xContentType == null) { throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue());
public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception { RestRequest request = channel.request(); XContentType xContentType = XContentType .fromMediaTypeOrFormat(request.param("format", request.header("Content-Type"))); if (xContentType != null) { return buildXContentBuilder(table, channel); } return buildTextPlainResponse(table, channel); }
public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception { RestRequest request = channel.request(); XContentType xContentType = XContentType.fromMediaTypeOrFormat(request.param("format", request.header("Accept"))); if (xContentType != null) { return buildXContentBuilder(table, channel); } return buildTextPlainResponse(table, channel); }
public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception { RestRequest request = channel.request(); XContentType xContentType = XContentType.fromMediaTypeOrFormat(request.param("format", request.header("Accept"))); if (xContentType != null) { return buildXContentBuilder(table, channel); } return buildTextPlainResponse(table, channel); }
public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception { RestRequest request = channel.request(); XContentType xContentType = XContentType.fromMediaTypeOrFormat(request.param("format", request.header("Accept"))); if (xContentType != null) { return buildXContentBuilder(table, channel); } return buildTextPlainResponse(table, channel); }
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; } }
XContentType contentType = XContentType.fromMediaTypeOrFormat(options.get(CONTENT_TYPE_OPTION)); out.writeBoolean(true); contentType.writeTo(out);