public static XContentBuilder emptyBuilder(RestRequest request) throws IOException { return restContentBuilder(request, request.hasContent() ? request.content() : null).startObject().endObject(); }
/** * Get the content of the request or the contents of the {@code source} param or throw an exception if both are missing. * Prefer {@link #contentOrSourceParamParser()} or {@link #withContentOrSourceParamParserOrNull(CheckedConsumer)} if you need a parser. */ public final Tuple<XContentType, BytesReference> contentOrSourceParam() { if (hasContentOrSourceParam() == false) { throw new ElasticsearchParseException("request body or source parameter is required"); } else if (hasContent()) { return new Tuple<>(xContentType.get(), requiredContent()); } String source = param("source"); String typeParam = param("source_content_type"); if (source == null || typeParam == null) { throw new IllegalStateException("source and source_content_type parameters are required"); } BytesArray bytes = new BytesArray(source); final XContentType xContentType = parseContentType(Collections.singletonList(typeParam)); if (xContentType == null) { throw new IllegalStateException("Unknown value for source_content_type [" + typeParam + "]"); } return new Tuple<>(xContentType, bytes); }
public static XContentBuilder restContentBuilder(RestRequest request) throws IOException { // use the request body as the auto detect source (if it exists) return restContentBuilder(request, request.hasContent() ? request.content() : null); }
/** * Does this request have content or a {@code source} parameter? Use this instead of {@link #hasContent()} if this * {@linkplain RestHandler} treats the {@code source} parameter like the body content. */ public final boolean hasContentOrSourceParam() { return hasContent() || hasParam("source"); }
/** * If there is any content then call {@code applyParser} with the parser, otherwise do nothing. */ public final void applyContentParser(CheckedConsumer<XContentParser, IOException> applyParser) throws IOException { if (hasContent()) { try (XContentParser parser = contentParser()) { applyParser.accept(parser); } } }
/** * @return content of the request body or throw an exception if the body or content type is missing */ public final BytesReference requiredContent() { if (hasContent() == false) { throw new ElasticsearchParseException("request body is required"); } else if (xContentType.get() == null) { throw new IllegalStateException("unknown content type"); } return content(); }
final int contentLength = request.hasContent() ? request.content().length() : 0;
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { if (request.hasContent()) { throw new IllegalArgumentException("forcemerge takes arguments in query parameters, not in the request body"); } ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index"))); mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions())); mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments())); mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes())); mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush())); return channel -> client.admin().indices().forceMerge(mergeRequest, new RestToXContentListener<>(channel)); } }
Boolean writeIndex = null; if (request.hasContent()) { try (XContentParser parser = request.contentParser()) { XContentParser.Token token = parser.nextToken();
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index")); if (request.hasContent()) { createIndexRequest.source(request.content(), request.getXContentType()); } if (request.hasParam("update_all_types")) { DEPRECATION_LOGGER.deprecated("[update_all_types] is deprecated since indices may not have more than one type anymore"); } createIndexRequest.updateAllTypes(request.paramAsBoolean("update_all_types", false)); createIndexRequest.timeout(request.paramAsTime("timeout", createIndexRequest.timeout())); createIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createIndexRequest.masterNodeTimeout())); createIndexRequest.waitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards"))); return channel -> client.admin().indices().create(createIndexRequest, new RestToXContentListener<>(channel)); } }
/** * Does this request have content or a {@code source} parameter? Use this instead of {@link #hasContent()} if this * {@linkplain RestHandler} treats the {@code source} parameter like the body content. */ public final boolean hasContentOrSourceParam() { return hasContent() || hasParam("source"); }
/** * Does this request have content or a {@code source} parameter? Use this instead of {@link #hasContent()} if this * {@linkplain RestHandler} treats the {@code source} parameter like the body content. */ public final boolean hasContentOrSourceParam() { return hasContent() || hasParam("source"); }
/** * Does this request have content or a {@code source} parameter? Use this instead of {@link #hasContent()} if this * {@linkplain RestHandler} treats the {@code source} parameter like the body content. */ public final boolean hasContentOrSourceParam() { return hasContent() || hasParam("source"); }
/** * If there is any content then call {@code applyParser} with the parser, otherwise do nothing. */ public final void applyContentParser(CheckedConsumer<XContentParser, IOException> applyParser) throws IOException { if (hasContent()) { try (XContentParser parser = contentParser()) { applyParser.accept(parser); } } }
/** * If there is any content then call {@code applyParser} with the parser, otherwise do nothing. */ public final void applyContentParser(CheckedConsumer<XContentParser, IOException> applyParser) throws IOException { if (hasContent()) { try (XContentParser parser = contentParser()) { applyParser.accept(parser); } } }
/** * If there is any content then call {@code applyParser} with the parser, otherwise do nothing. */ public final void applyContentParser(CheckedConsumer<XContentParser, IOException> applyParser) throws IOException { if (hasContent()) { try (XContentParser parser = contentParser()) { applyParser.accept(parser); } } }
/** * @return content of the request body or throw an exception if the body or content type is missing */ public final BytesReference requiredContent() { if (hasContent() == false) { throw new ElasticsearchParseException("request body is required"); } else if (xContentType.get() == null) { throw new IllegalStateException("unknown content type"); } return content(); }
/** * @return content of the request body or throw an exception if the body or content type is missing */ public final BytesReference requiredContent() { if (hasContent() == false) { throw new ElasticsearchParseException("request body is required"); } else if (xContentType.get() == null) { throw new IllegalStateException("unknown content type"); } return content(); }
/** * @return content of the request body or throw an exception if the body or content type is missing */ public final BytesReference requiredContent() { if (hasContent() == false) { throw new ElasticsearchParseException("request body is required"); } else if (xContentType.get() == null) { throw new IllegalStateException("unknown content type"); } return content(); }
public EditableRestRequest(final RestRequest innerRestquest) { this.innerRestquest = innerRestquest; content = innerRestquest.content(); params = innerRestquest.params(); method = innerRestquest.method(); uri = innerRestquest.uri(); rawPath = innerRestquest.rawPath(); hasContent = innerRestquest.hasContent(); contentUnsafe = innerRestquest.contentUnsafe(); }