@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); }
/** * Handle a requests with no candidate handlers (return a 400 Bad Request * error). */ private void handleBadRequest(RestRequest request, RestChannel channel) throws IOException { try (XContentBuilder builder = channel.newErrorBuilder()) { builder.startObject(); { builder.field("error", "no handler found for uri [" + request.uri() + "] and method [" + request.method() + "]"); } builder.endObject(); channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder)); } }
@Override public void dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext) { if (request.rawPath().equals("/favicon.ico")) { handleFavicon(request, channel); return; } try { tryAllHandlers(request, channel, threadContext); } catch (Exception e) { try { channel.sendResponse(new BytesRestResponse(channel, e)); } catch (Exception inner) { inner.addSuppressed(e); logger.error(() -> new ParameterizedMessage("failed to send failure response for uri [{}]", request.uri()), inner); } } }
/** * Handle requests to a valid REST endpoint using an unsupported HTTP * method. A 405 HTTP response code is returned, and the response 'Allow' * header includes a list of valid HTTP methods for the endpoint (see * <a href="https://tools.ietf.org/html/rfc2616#section-10.4.6">HTTP/1.1 - * 10.4.6 - 405 Method Not Allowed</a>). */ private void handleUnsupportedHttpMethod(RestRequest request, RestChannel channel, Set<RestRequest.Method> validMethodSet) { try { BytesRestResponse bytesRestResponse = BytesRestResponse.createSimpleErrorResponse(channel, METHOD_NOT_ALLOWED, "Incorrect HTTP method for uri [" + request.uri() + "] and method [" + request.method() + "], allowed: " + validMethodSet); bytesRestResponse.addHeader("Allow", Strings.collectionToDelimitedString(validMethodSet, ",")); channel.sendResponse(bytesRestResponse); } catch (final IOException e) { logger.warn("failed to send bad request response", e); channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); } }
if ("suggest".equals(indexMetric)) { deprecationLogger.deprecated( "the suggest index metric is deprecated on the nodes stats API [" + request.uri() + "]");
if (consumer != null) { if ("suggest".equals(metric)) { deprecationLogger.deprecated("the suggest metric is deprecated on the indices stats API [" + request.uri() + "]");
public void sendErrorResponse(RestRequest request, RestChannel channel, Throwable e) { try { channel.sendResponse(new BytesRestResponse(channel, e)); } catch (Throwable e1) { logger.error("failed to send failure response for uri [" + request.uri() + "]", e1); } }
/** * Handle a requests with no candidate handlers (return a 400 Bad Request * error). */ private void handleBadRequest(RestRequest request, RestChannel channel) throws IOException { try (XContentBuilder builder = channel.newErrorBuilder()) { builder.startObject(); { builder.field("error", "no handler found for uri [" + request.uri() + "] and method [" + request.method() + "]"); } builder.endObject(); channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder)); } }
/** * Handle a requests with no candidate handlers (return a 400 Bad Request * error). */ private void handleBadRequest(RestRequest request, RestChannel channel) throws IOException { try (XContentBuilder builder = channel.newErrorBuilder()) { builder.startObject(); { builder.field("error", "no handler found for uri [" + request.uri() + "] and method [" + request.method() + "]"); } builder.endObject(); channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder)); } }
@Override public void dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext) { if (request.rawPath().equals("/favicon.ico")) { handleFavicon(request, channel); return; } try { tryAllHandlers(request, channel, threadContext); } catch (Exception e) { try { channel.sendResponse(new BytesRestResponse(channel, e)); } catch (Exception inner) { inner.addSuppressed(e); logger.error(() -> new ParameterizedMessage("failed to send failure response for uri [{}]", request.uri()), inner); } } }
@Override public void dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext) { if (request.rawPath().equals("/favicon.ico")) { handleFavicon(request, channel); return; } try { tryAllHandlers(request, channel, threadContext); } catch (Exception e) { try { channel.sendResponse(new BytesRestResponse(channel, e)); } catch (Exception inner) { inner.addSuppressed(e); logger.error(() -> new ParameterizedMessage("failed to send failure response for uri [{}]", request.uri()), inner); } } }
@Override public void continueProcessing(RestRequest request, RestChannel channel) { try { int loc = index.getAndIncrement(); if (loc > filters.length) { throw new IllegalStateException("filter continueProcessing was called more than expected"); } else if (loc == filters.length) { executionFilter.process(request, channel, this); } else { RestFilter preProcessor = filters[loc]; preProcessor.process(request, channel, this); } } catch (Exception e) { try { channel.sendResponse(new BytesRestResponse(channel, e)); } catch (IOException e1) { logger.error("Failed to send failure response for uri [" + request.uri() + "]", e1); } } } }
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(); }
public void handleRequest(final RestRequest request, final RestChannel channel) { // Get the parameters final Map<String, List<String>> params = parseUriParams(request.uri()); // generate the search request SearchRequest searchRequest = getSearchRequest(params, request); searchRequest.listenerThreaded(false); // execute the search client.search(searchRequest, new ActionListener<SearchResponse>() { @Override public void onResponse(SearchResponse response) { try { // write response solrResponseWriter.writeResponse(createSearchResponse(params, request, response), request, channel); } catch (Exception e) { onFailure(e); } } @Override public void onFailure(Throwable e) { try { logger.error("Error processing executing search", e); channel.sendResponse(new XContentThrowableRestResponse(request, e)); } catch (IOException e1) { logger.error("Failed to send failure response", e1); } } }); }
/** * Handle requests to a valid REST endpoint using an unsupported HTTP * method. A 405 HTTP response code is returned, and the response 'Allow' * header includes a list of valid HTTP methods for the endpoint (see * <a href="https://tools.ietf.org/html/rfc2616#section-10.4.6">HTTP/1.1 - * 10.4.6 - 405 Method Not Allowed</a>). */ private void handleUnsupportedHttpMethod(RestRequest request, RestChannel channel, Set<RestRequest.Method> validMethodSet) { try { BytesRestResponse bytesRestResponse = BytesRestResponse.createSimpleErrorResponse(channel, METHOD_NOT_ALLOWED, "Incorrect HTTP method for uri [" + request.uri() + "] and method [" + request.method() + "], allowed: " + validMethodSet); bytesRestResponse.addHeader("Allow", Strings.collectionToDelimitedString(validMethodSet, ",")); channel.sendResponse(bytesRestResponse); } catch (final IOException e) { logger.warn("failed to send bad request response", e); channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); } }
/** * Handle requests to a valid REST endpoint using an unsupported HTTP * method. A 405 HTTP response code is returned, and the response 'Allow' * header includes a list of valid HTTP methods for the endpoint (see * <a href="https://tools.ietf.org/html/rfc2616#section-10.4.6">HTTP/1.1 - * 10.4.6 - 405 Method Not Allowed</a>). */ private void handleUnsupportedHttpMethod(RestRequest request, RestChannel channel, Set<RestRequest.Method> validMethodSet) { try { BytesRestResponse bytesRestResponse = BytesRestResponse.createSimpleErrorResponse(channel, METHOD_NOT_ALLOWED, "Incorrect HTTP method for uri [" + request.uri() + "] and method [" + request.method() + "], allowed: " + validMethodSet); bytesRestResponse.addHeader("Allow", Strings.collectionToDelimitedString(validMethodSet, ",")); channel.sendResponse(bytesRestResponse); } catch (final IOException e) { logger.warn("failed to send bad request response", e); channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); } }
public void dispatchRequest(final RestRequest request, final RestChannel channel) { try { if (request instanceof NettyHttpRequest) { NettyHttpRequest nettyHttpRequest = (NettyHttpRequest)request; if ("PATCH".equalsIgnoreCase(nettyHttpRequest.getMethod())) { RestHandler handler = patchHandlers.retrieve(request.rawPath()); if (handler != null) { handler.handleRequest(request, channel); } } } } catch (Throwable e) { try { channel.sendResponse(new BytesRestResponse(channel, e)); } catch (Throwable e1) { logger.error("failed to send failure response for uri [" + request.uri() + "]", e1); } } } }
void executeHandler(RestRequest request, RestChannel channel) throws Exception { final RestHandler handler = getHandler(request); if (handler != null) { handler.handleRequest(request, channel); } else { if (request.method() == RestRequest.Method.OPTIONS) { // when we have OPTIONS request, simply send OK by default (with the Access Control Origin header which gets automatically added) channel.sendResponse(new BytesRestResponse(OK)); } else { channel.sendResponse(new BytesRestResponse(BAD_REQUEST, "No handler found for uri [" + request.uri() + "] and method [" + request.method() + "]")); } } }
void dispatchRequest(final RestRequest request, final RestChannel channel, final NodeClient client, ThreadContext threadContext, final RestHandler handler) throws Exception { if (checkRequestParameters(request, channel) == false) { channel .sendResponse(BytesRestResponse.createSimpleErrorResponse(channel,BAD_REQUEST, "error traces in responses are disabled.")); } else { for (String key : headersToCopy) { String httpHeader = request.header(key); if (httpHeader != null) { threadContext.putHeader(key, httpHeader); } } if (handler == null) { if (request.method() == RestRequest.Method.OPTIONS) { // when we have OPTIONS request, simply send OK by default (with the Access Control Origin header which gets automatically added) channel.sendResponse(new BytesRestResponse(OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); } else { final String msg = "No handler found for uri [" + request.uri() + "] and method [" + request.method() + "]"; channel.sendResponse(new BytesRestResponse(BAD_REQUEST, msg)); } } else { final RestHandler wrappedHandler = Objects.requireNonNull(handlerWrapper.apply(handler)); wrappedHandler.handleRequest(request, channel, client); } } }
inner.addSuppressed(e); logger.error((Supplier<?>) () -> new ParameterizedMessage("failed to send failure response for uri [{}]", request.uri()), inner);