Java Code Examples for org.elasticsearch.rest.RestChannel#newBuilder()
The following examples show how to use
org.elasticsearch.rest.RestChannel#newBuilder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalUsersApiAction.java From deprecated-security-advanced-modules with Apache License 2.0 | 6 votes |
@Override protected AbstractConfigurationValidator postProcessApplyPatchResult(RestChannel channel, RestRequest request, JsonNode existingResourceAsJsonNode, JsonNode updatedResourceAsJsonNode, String resourceName) { AbstractConfigurationValidator retVal = null; JsonNode passwordNode = updatedResourceAsJsonNode.get("password"); if (passwordNode != null) { String plainTextPassword = passwordNode.asText(); try { XContentBuilder builder = channel.newBuilder(); builder.startObject(); builder.field("password", plainTextPassword); builder.endObject(); retVal = getValidator(request, BytesReference.bytes(builder), resourceName); } catch (IOException e) { log.error(e); } ((ObjectNode) updatedResourceAsJsonNode).remove("password"); ((ObjectNode) updatedResourceAsJsonNode).set("hash", new TextNode(hash(plainTextPassword.toCharArray()))); return retVal; } return null; }
Example 2
Source File: AbstractApiAction.java From deprecated-security-advanced-modules with Apache License 2.0 | 5 votes |
protected static XContentBuilder convertToJson(RestChannel channel, ToXContent toxContent) { try { XContentBuilder builder = channel.newBuilder(); toxContent.toXContent(builder, ToXContent.EMPTY_PARAMS); return builder; } catch (IOException e) { throw ExceptionsHelper.convertToElastic(e); } }
Example 3
Source File: AbstractApiAction.java From deprecated-security-advanced-modules with Apache License 2.0 | 5 votes |
protected void response(RestChannel channel, RestStatus status, String message) { try { final XContentBuilder builder = channel.newBuilder(); builder.startObject(); builder.field("status", status.name()); builder.field("message", message); builder.endObject(); channel.sendResponse(new BytesRestResponse(status, builder)); } catch (IOException e) { throw ExceptionsHelper.convertToElastic(e); } }
Example 4
Source File: AbstractApiAction.java From deprecated-security-advanced-modules with Apache License 2.0 | 5 votes |
protected void successResponse(RestChannel channel) { try { final XContentBuilder builder = channel.newBuilder(); builder.startObject(); channel.sendResponse( new BytesRestResponse(RestStatus.OK, builder)); } catch (IOException e) { internalErrorResponse(channel, "Unable to fetch license: " + e.getMessage()); log.error("Cannot fetch convert license to XContent due to", e); } }
Example 5
Source File: JobRestHandler.java From elasticsearch-rest-command with The Unlicense | 5 votes |
private void sendQuery(int from, final RestRequest request,final RestChannel channel, SearchResponse response, List<String> fieldNames, boolean showMeta){ XContentBuilder builder; try { builder = channel.newBuilder(); Search.buildQuery(from, builder, response, logger, fieldNames, showMeta); channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); } catch (IOException e) { sendFailure(request, channel, e); } }
Example 6
Source File: JobRestHandler.java From elasticsearch-rest-command with The Unlicense | 5 votes |
private void sendQuery(int from, final RestRequest request,final RestChannel channel, QueryResponse response, List<String> fieldNames, boolean showMeta){ XContentBuilder builder; try { builder = channel.newBuilder(); Search.buildQuery(from, builder, response, logger, fieldNames, showMeta); channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); } catch (IOException e) { sendFailure(request, channel, e); } }
Example 7
Source File: JobRestHandler.java From elasticsearch-rest-command with The Unlicense | 5 votes |
private void sendTimeline(final RestRequest request,final RestChannel channel, SearchResponse response){ XContentBuilder builder; try { builder = channel.newBuilder(); Search.buildTimeline(builder, response, logger); channel.sendResponse(new BytesRestResponse(response.status(), builder)); } catch (IOException e) { sendFailure(request, channel, e); } }
Example 8
Source File: AbstractConfigurationValidator.java From deprecated-security-advanced-modules with Apache License 2.0 | 4 votes |
public XContentBuilder errorsAsXContent(RestChannel channel) { try { final XContentBuilder builder = channel.newBuilder(); builder.startObject(); if(lastException != null) { builder.field("details", lastException.toString()); } switch (this.errorType) { case NONE: builder.field("status", "error"); builder.field("reason", errorType.getMessage()); break; case INVALID_CONFIGURATION: builder.field("status", "error"); builder.field("reason", ErrorType.INVALID_CONFIGURATION.getMessage()); addErrorMessage(builder, INVALID_KEYS_KEY, invalidKeys); addErrorMessage(builder, MISSING_MANDATORY_KEYS_KEY, missingMandatoryKeys); addErrorMessage(builder, MISSING_MANDATORY_OR_KEYS_KEY, missingMandatoryKeys); break; case INVALID_PASSWORD: builder.field("status", "error"); builder.field("reason", esSettings.get(ConfigConstants.OPENDISTRO_SECURITY_RESTAPI_PASSWORD_VALIDATION_ERROR_MESSAGE, "Password does not match minimum criteria")); break; case WRONG_DATATYPE: builder.field("status", "error"); builder.field("reason", ErrorType.WRONG_DATATYPE.getMessage()); for (Entry<String, String> entry : wrongDatatypes.entrySet()) { builder.field(entry.getKey(), entry.getValue()); } break; default: builder.field("status", "error"); builder.field("reason", errorType.getMessage()); } builder.endObject(); return builder; } catch (IOException ex) { log.error("Cannot build error settings", ex); return null; } }