@Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { try (XContentParser parser = request.contentOrSourceParamParser()) { parser.mapStrings().forEach((k, v) -> request.params().putIfAbsent(k, v)); } catch (IOException e) { LOGGER.warn("Please use json format params, like: {\"sql\":\"SELECT * FROM test\"}"); return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, XContentType.JSON.mediaType(), jsonExplanation)); } else { Map<String, String> params = request.params();
public void addFilterSettingParams(RestRequest request) { if (patterns.isEmpty() == false) { request.params().put(SETTINGS_FILTER_PARAM, patternString); } }
Iterator<MethodHandlers> getAllHandlers(final RestRequest request) { // Between retrieving the correct path, we need to reset the parameters, // otherwise parameters are parsed out of the URI that aren't actually handled. final Map<String, String> originalParams = new HashMap<>(request.params()); return handlers.retrieveAll(getPath(request), () -> { // PathTrie modifies the request, so reset the params between each iteration request.params().clear(); request.params().putAll(originalParams); return request.params(); }); }
@Override public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { request.params().put("op_type", "create"); return RestIndexAction.this.prepareRequest(request, client); } }
/** * Creates a new REST request. * * @param xContentRegistry the content registry * @param uri the raw URI that will be parsed into the path and the parameters * @param headers a map of the header; this map should implement a case-insensitive lookup * @throws BadParameterException if the parameters can not be decoded * @throws ContentTypeHeaderException if the Content-Type header can not be parsed */ public RestRequest(final NamedXContentRegistry xContentRegistry, final String uri, final Map<String, List<String>> headers) { this(xContentRegistry, params(uri), path(uri), headers); }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { ClusterRerouteRequest clusterRerouteRequest = createRequest(request); settingsFilter.addFilterSettingParams(request); if (clusterRerouteRequest.explain()) { request.params().put("explain", Boolean.TRUE.toString()); } // by default, return everything but metadata final String metric = request.param("metric"); if (metric == null) { request.params().put("metric", DEFAULT_METRICS); } return channel -> client.admin().cluster().reroute(clusterRerouteRequest, new RestToXContentListener<>(channel)); }
public static ClearIndicesCacheRequest fromRequest(final RestRequest request, ClearIndicesCacheRequest clearIndicesCacheRequest) { for (Map.Entry<String, String> entry : request.params().entrySet()) { if (Fields.QUERY.match(entry.getKey(), LoggingDeprecationHandler.INSTANCE)) { clearIndicesCacheRequest.queryCache(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.queryCache())); } else if (Fields.REQUEST.match(entry.getKey(), LoggingDeprecationHandler.INSTANCE)) { clearIndicesCacheRequest.requestCache(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.requestCache())); } else if (Fields.FIELDDATA.match(entry.getKey(), LoggingDeprecationHandler.INSTANCE)) { clearIndicesCacheRequest.fieldDataCache(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.fieldDataCache())); } else if (Fields.FIELDS.match(entry.getKey(), LoggingDeprecationHandler.INSTANCE)) { clearIndicesCacheRequest.fields(request.paramAsStringArray(entry.getKey(), clearIndicesCacheRequest.fields())); } } return clearIndicesCacheRequest; }
private static XContentBuilder build(RestChannel channel, RestStatus status, Exception e) throws IOException { ToXContent.Params params = channel.request(); if (params.paramAsBoolean("error_trace", !REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT)) { params = new ToXContent.DelegatingMapParams(singletonMap(REST_EXCEPTION_SKIP_STACK_TRACE, "false"), params); } else if (e != null) { Supplier<?> messageSupplier = () -> new ParameterizedMessage("path: {}, params: {}", channel.request().rawPath(), channel.request().params()); if (status.getStatus() < 500) { SUPPRESSED_ERROR_LOGGER.debug(messageSupplier, e); } else { SUPPRESSED_ERROR_LOGGER.warn(messageSupplier, e); } } XContentBuilder builder = channel.newErrorBuilder().startObject(); ElasticsearchException.generateFailureXContent(builder, params, e, channel.detailedErrorsEnabled()); builder.field(STATUS, status.getStatus()); builder.endObject(); return builder; }
public void addFilterSettingParams(RestRequest request) { if (patterns.isEmpty() == false) { request.params().put(SETTINGS_FILTER_PARAM, patternString); } }
public void addFilterSettingParams(RestRequest request) { if (patterns.isEmpty() == false) { request.params().put(SETTINGS_FILTER_PARAM, patternString); } }
Iterator<MethodHandlers> getAllHandlers(final RestRequest request) { // Between retrieving the correct path, we need to reset the parameters, // otherwise parameters are parsed out of the URI that aren't actually handled. final Map<String, String> originalParams = new HashMap<>(request.params()); return handlers.retrieveAll(getPath(request), () -> { // PathTrie modifies the request, so reset the params between each iteration request.params().clear(); request.params().putAll(originalParams); return request.params(); }); }
@Override public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { request.params().put("op_type", "create"); return RestIndexAction.this.prepareRequest(request, client); } }
@Override public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { request.params().put("op_type", "create"); return RestIndexAction.this.prepareRequest(request, client); } }
/** * Creates a new REST request. * * @param xContentRegistry the content registry * @param uri the raw URI that will be parsed into the path and the parameters * @param headers a map of the header; this map should implement a case-insensitive lookup * @throws BadParameterException if the parameters can not be decoded * @throws ContentTypeHeaderException if the Content-Type header can not be parsed */ public RestRequest(final NamedXContentRegistry xContentRegistry, final String uri, final Map<String, List<String>> headers) { this(xContentRegistry, params(uri), path(uri), headers); }
/** * Creates a new REST request. * * @param xContentRegistry the content registry * @param uri the raw URI that will be parsed into the path and the parameters * @param headers a map of the header; this map should implement a case-insensitive lookup * @throws BadParameterException if the parameters can not be decoded * @throws ContentTypeHeaderException if the Content-Type header can not be parsed */ public RestRequest(final NamedXContentRegistry xContentRegistry, final String uri, final Map<String, List<String>> headers) { this(xContentRegistry, params(uri), path(uri), headers); }
@Override public void handleRequest(RestRequest request, RestChannel channel, final Client client) { request.params().put("op_type", "create"); RestPutSearchTemplateAction.this.handleRequest(request, channel, client); } }
@Override protected RestChannelConsumer doCatRequest(RestRequest request, NodeClient client) { AnsjRequest ansjRequest = new AnsjRequest(request.path()); ansjRequest.asMap().putAll(request.params()); return channel -> client.execute(AnsjAction.INSTANCE, ansjRequest, new RestResponseListener<AnsjResponse>(channel) { @Override public RestResponse buildResponse(final AnsjResponse ansjResponse) throws Exception { return ChineseRestTable.response(channel, ansjResponse.asMap()); } }); }
@Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { AnsjRequest ansjRequest = new AnsjRequest(); ansjRequest.asMap().putAll(request.params()); return channel -> client.execute(AnsjAction.INSTANCE, ansjRequest, new RestToXContentListener<>(channel)); }
private RestHandler getHandler(RestRequest request) { String path = getPath(request); PathTrie<RestHandler> handlers = getHandlersForMethod(request.method()); if (handlers != null) { return handlers.retrieve(path, request.params()); } else { return null; } }
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(); }