public void sendResponse(RestChannel channel){ try { String json = ElasticUtils.hitsAsStringResult(results,metaResults); BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, json); channel.sendResponse(bytesRestResponse); } catch (IOException e) { e.printStackTrace(); } }
private void sendDefaultResponse(SearchHits hits, RestChannel channel) { try { String json = ElasticUtils.hitsAsStringResult(hits, new MetaSearchResult()); BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, json); channel.sendResponse(bytesRestResponse); } catch (IOException e) { e.printStackTrace(); } } }
@Override public boolean reRequestAuthentication(final RestChannel channel, AuthCredentials creds) { final BytesRestResponse wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED, "Unauthorized"); wwwAuthenticateResponse.addHeader("WWW-Authenticate", "Basic realm=\"Search Guard\""); channel.sendResponse(wwwAuthenticateResponse); return true; }
private void respondSuccess(RestRequest request, RestChannel channel, RestStatus status) { try { XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("success", true); builder.endObject(); channel.sendResponse(new BytesRestResponse(status, builder)); } catch (IOException e) { errorResponse(request, channel, e); } }
private void respondError(RestRequest request, RestChannel channel, String error, RestStatus status) { try { XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("success", false); builder.field("error", error); builder.endObject(); channel.sendResponse(new BytesRestResponse(status, builder)); } catch (IOException e) { errorResponse(request, channel, e); } }
private void errorResponse(RestRequest request, RestChannel channel, Throwable e) { try { channel.sendResponse(new XContentThrowableRestResponse(request, e)); logger.error("errorResponse", e); } catch (IOException ioEx) { logger.error("Failed to send failure response", ioEx); } }
@Override public void execute(Client client, Map<String, String> params, QueryAction queryAction, RestChannel channel) throws Exception { Object queryResult = QueryActionElasticExecutor.executeAnyAction(client, queryAction); boolean flat = getBooleanOrDefault(params,"flat",false); String separator = ","; if(params.containsKey("separator")){ separator = params.get("separator"); } boolean includeScore = getBooleanOrDefault(params,"_score",false); boolean includeType = getBooleanOrDefault(params,"_type",false); boolean includeId = getBooleanOrDefault(params,"_id",false); CSVResult result = new CSVResultsExtractor(includeScore,includeType,includeId).extractResults(queryResult,flat,separator); String newLine = "\n"; if(params.containsKey("newLine")){ newLine = params.get("newLine"); } String csvString = buildString(separator, result, newLine); BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, csvString); channel.sendResponse(bytesRestResponse); }
@Override public void accept(RestChannel channel) throws Exception { XContentBuilder builder = channel.newBuilder(); RestStatus restStatus = RestStatus.OK; BytesRestResponse response = null; try { String status = "UP"; String message = null; builder.startObject(); if ("strict".equalsIgnoreCase(mode) && registry.isInitialized() == false) { status = "DOWN"; message = "Not initialized"; restStatus = RestStatus.SERVICE_UNAVAILABLE; } builder.field("message", message); builder.field("mode", mode); builder.field("status", status); builder.endObject(); response = new BytesRestResponse(restStatus, builder); } finally { builder.close(); } channel.sendResponse(response); }
channel.sendResponse(response);
return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, XContentType.JSON.mediaType(), jsonExplanation)); } else { Map<String, String> params = request.params();
channel.sendResponse(response);
private void list(RestRequest request, RestChannel channel, Client esClient) { try { Map<String, Object> rivers = getRivers(request.paramAsInt("page", 1), request.paramAsInt("count", 10), esClient); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.value(rivers); channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); } catch (Throwable e) { errorResponse(request, channel, e); } }
channel.sendResponse(new BytesRestResponse(RestStatus.SERVICE_UNAVAILABLE, "Search Guard not initialized (SG11). See http://docs.search-guard.com/v6/sgadmin")); return false; log.error("Cannot authenticate user because admin user is not permitted to login via HTTP"); auditLog.logFailedLogin(authenticatedUser.getName(), true, null, request); channel.sendResponse(new BytesRestResponse(RestStatus.FORBIDDEN, "Cannot authenticate user because admin user is not permitted to login via HTTP")); return false; channel.sendResponse(new BytesRestResponse(RestStatus.UNAUTHORIZED, "Authentication finally failed")); return false;
log.error(exception); auditLog.logBadHeaders(request); channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, exception)); return true; log.error(exception); auditLog.logBadHeaders(request); channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, exception)); return true; log.error("No ssl info", e); auditLog.logSSLException(request, e); channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, e)); return true;
channel.sendResponse(response);
@Override public final void onFailure(Exception e) { try { channel.sendResponse(new BytesRestResponse(channel, e)); } catch (Exception inner) { inner.addSuppressed(e); logger.error("failed to send failure response", inner); } } }
@Override public void sendResponse(RestResponse response) { close(); delegate.sendResponse(response); }
@Override protected final void processResponse(Response response) throws Exception { channel.sendResponse(buildResponse(response)); }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, HELP)); }
private void sendContentTypeErrorMessage(RestRequest restRequest, RestChannel channel) throws IOException { final List<String> contentTypeHeader = restRequest.getAllHeaderValues("Content-Type"); final String errorMessage; if (contentTypeHeader == null) { errorMessage = "Content-Type header is missing"; } else { errorMessage = "Content-Type header [" + Strings.collectionToCommaDelimitedString(restRequest.getAllHeaderValues("Content-Type")) + "] is not supported"; } channel.sendResponse(BytesRestResponse.createSimpleErrorResponse(channel, NOT_ACCEPTABLE, errorMessage)); }