@Override protected void handleRequest(RestRequest request, RestChannel channel, Client esClient) throws Exception { logger.debug("uri: {}", request.uri()); logger.debug("action: {}", request.param("action")); if (request.path().endsWith("list")) { list(request, channel, esClient); return; } else if (request.path().endsWith("start")) { start(request, channel, esClient); return; } else if (request.path().endsWith("stop")) { stop(request, channel, esClient); return; } else if (request.path().endsWith("delete")) { delete(request, channel, esClient); return; } respondError(request, channel, "action not found: " + request.uri(), RestStatus.OK); }
if (request.path().endsWith("/_explain")) { final String jsonExplanation = queryAction.explain().explain(); return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, XContentType.JSON.mediaType(), jsonExplanation));
/** * 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); }
Locale.ROOT, "request [%s] contains unrecognized %s%s: ", request.path(), detail, invalids.size() > 1 ? "s" : ""));
@Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId")); Set<String> metrics = Strings.tokenizeByCommaToSet(request.param("metric", "_all")); NodesUsageRequest nodesUsageRequest = new NodesUsageRequest(nodesIds); nodesUsageRequest.timeout(request.param("timeout")); if (metrics.size() == 1 && metrics.contains("_all")) { nodesUsageRequest.all(); } else if (metrics.contains("_all")) { throw new IllegalArgumentException(String.format(Locale.ROOT, "request [%s] contains _all and individual metrics [%s]", request.path(), request.param("metric"))); } else { nodesUsageRequest.clear(); nodesUsageRequest.restActions(metrics.contains("rest_actions")); } return channel -> client.admin().cluster().nodesUsage(nodesUsageRequest, new RestBuilderListener<NodesUsageResponse>(channel) { @Override public RestResponse buildResponse(NodesUsageResponse response, XContentBuilder builder) throws Exception { builder.startObject(); RestActions.buildNodesHeader(builder, channel.request(), response); builder.field("cluster_name", response.getClusterName().value()); response.toXContent(builder, channel.request()); builder.endObject(); return new BytesRestResponse(RestStatus.OK, builder); } }); }
public RequestParser(RestRequest request, Settings settings) { this.path = request.path(); this.request = request; this.settings = settings; }
Locale.ROOT, "request [%s] contains index metrics [%s] but all stats requested", request.path(), request.param("index_metric"))); String.format(Locale.ROOT, "request [%s] contains _all and individual metrics [%s]", request.path(), request.param("metric"))); } else { Locale.ROOT, "request [%s] contains index metrics [%s] but indices stats not requested", request.path(), request.param("index_metric")));
String.format(Locale.ROOT, "request [%s] contains _all and individual metrics [%s]", request.path(), request.param("metric"))); } else {
/** * 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); }
public static boolean isAdminRequest(final RestRequest request) { return stringContainsItemFromListAsCommand(request.path(), BUILT_IN_ADMIN_COMMANDS); }
public static String getId(final RestRequest request) { String id = null; final String path = request.path(); log.debug("Evaluate decoded path for id '" + path + "'"); if (!path.startsWith("/")) { return null; } if (path.length() > 1) { int endIndex; if ((endIndex = path.lastIndexOf('/')) != -1) { id = path.substring(endIndex + 1); if (id.contains("?")) { id = path.substring(id.indexOf("?") + 1); } // if(id.contains("/")) return null; } } log.debug("Id: " + id); return id; }
private AuditMessage(final String username, final String message, final RestRequest request) { auditInfo.put("audit_user", username); auditInfo.put("audit_message", message); auditInfo.put("audit_date", new Date().toString()); auditInfo.put("audit_details_context", String.valueOf(request.getContext())); auditInfo.put("audit_details_headers", Iterables.toString(request.headers())); auditInfo.put("audit_details_rest", request.method() + " " + request.path() + " " + request.params()); auditInfo.put("audit_details_class", request.getClass().toString()); try { auditInfo.put("audit_ip", SecurityUtil.getProxyResolvedHostAddressFromRequest(request, settings).toString()); } catch (final UnknownHostException e) { //no-op } }
public static boolean isWriteRequest(final RestRequest request, boolean strictModeEnabled) { if (request.method() == Method.DELETE || request.method() == Method.PUT) { return true; } if (request.method() == Method.POST) { if (!stringContainsItemFromListAsCommand(request.path(), strictModeEnabled?SecurityUtil.BUILT_IN_READ_COMMANDS_STRICT : SecurityUtil.BUILT_IN_READ_COMMANDS_LAX)) { return true; } } return stringContainsItemFromListAsCommand(request.path(), strictModeEnabled?SecurityUtil.BUILT_IN_WRITE_COMMANDS_STRICT : SecurityUtil.BUILT_IN_WRITE_COMMANDS_LAX); }
@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()); } }); }
private void initialize() { if (!isInitialized) { normalizedPath = normalizePath(request.path()); indexInPath = extractIndexFromPath(normalizedPath); indicesInPath = extractIndicesFromPath(normalizedPath); apiName = extractApiNameFrom(normalizedPath); isInitialized = true; } }
@Override public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { if (request.method().equals(RestRequest.Method.GET)) { return handleGet(request, client); } else if (request.method().equals(RestRequest.Method.POST)) { return handlePost(request, client); } else { throw new IllegalArgumentException("illegal method [" + request.method() + "] for request [" + request.path() + "]"); } }
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { MultiSearchRequest multiSearchRequest = new MultiSearchRequest(); String[] indices = Strings.splitStringByCommaToArray(request.param("index")); String[] types = Strings.splitStringByCommaToArray(request.param("type")); String path = request.path(); boolean isTemplateRequest = isTemplateRequest(path); IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, multiSearchRequest.indicesOptions()); multiSearchRequest.add(RestActions.getRestContent(request), isTemplateRequest, indices, types, request.param("search_type"), request.param("routing"), indicesOptions, allowExplicitIndex); client.execute(CoordinateMultiSearchAction.INSTANCE, multiSearchRequest, new RestToXContentListener<MultiSearchResponse>(channel)); }
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { MultiSearchRequest multiSearchRequest = new MultiSearchRequest(); String[] indices = Strings.splitStringByCommaToArray(request.param("index")); String[] types = Strings.splitStringByCommaToArray(request.param("type")); String path = request.path(); boolean isTemplateRequest = isTemplateRequest(path); IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, multiSearchRequest.indicesOptions()); multiSearchRequest.add(RestActions.getRestContent(request), isTemplateRequest, indices, types, request.param("search_type"), request.param("routing"), indicesOptions, allowExplicitIndex); client.multiSearch(multiSearchRequest, new RestToXContentListener<MultiSearchResponse>(channel)); }