use of org.elasticsearch.rest.BytesRestResponse in project elasticsearch by elastic.
the class TestDeprecationHeaderRestAction method prepareRequest.
// List<String> casts
@SuppressWarnings("unchecked")
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
final List<String> settings;
try (XContentParser parser = request.contentParser()) {
final Map<String, Object> source = parser.map();
if (source.containsKey("deprecated_settings")) {
deprecationLogger.deprecated(DEPRECATED_USAGE);
settings = (List<String>) source.get("deprecated_settings");
} else {
settings = (List<String>) source.get("settings");
}
}
return channel -> {
final XContentBuilder builder = channel.newBuilder();
builder.startObject().startArray("settings");
for (String setting : settings) {
builder.startObject().field(setting, SETTINGS.get(setting).getRaw(this.settings)).endObject();
}
builder.endArray().endObject();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
};
}
use of org.elasticsearch.rest.BytesRestResponse in project elasticsearch by elastic.
the class TestResponseHeaderRestAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if ("password".equals(request.header("Secret"))) {
RestResponse response = new BytesRestResponse(RestStatus.OK, "Access granted");
response.addHeader("Secret", "granted");
return channel -> channel.sendResponse(response);
} else {
RestResponse response = new BytesRestResponse(RestStatus.UNAUTHORIZED, "Access denied");
response.addHeader("Secret", "required");
return channel -> channel.sendResponse(response);
}
}
Aggregations