Search in sources :

Example 6 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestTableTests method assertResponseContentType.

private RestResponse assertResponseContentType(Map<String, List<String>> headers, String mediaType) throws Exception {
    FakeRestRequest requestWithAcceptHeader = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build();
    table.startRow();
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.endRow();
    RestResponse response = buildResponse(table, new AbstractRestChannel(requestWithAcceptHeader, true) {

        @Override
        public void sendResponse(RestResponse response) {
        }
    });
    assertThat(response.contentType(), equalTo(mediaType));
    return response;
}
Also used : RestResponse(org.elasticsearch.rest.RestResponse) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) AbstractRestChannel(org.elasticsearch.rest.AbstractRestChannel)

Example 7 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestTableTests method assertResponse.

private void assertResponse(Map<String, List<String>> headers, String mediaType, String body) throws Exception {
    RestResponse response = assertResponseContentType(headers, mediaType);
    assertThat(response.content().utf8ToString(), equalTo(body));
}
Also used : RestResponse(org.elasticsearch.rest.RestResponse)

Example 8 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestRefreshAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index")));
    refreshRequest.indicesOptions(IndicesOptions.fromRequest(request, refreshRequest.indicesOptions()));
    return channel -> client.admin().indices().refresh(refreshRequest, new RestBuilderListener<RefreshResponse>(channel) {

        @Override
        public RestResponse buildResponse(RefreshResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(response.getStatus(), builder);
        }
    });
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) RestActions.buildBroadcastShardsHeader(org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 9 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestSyncedFlushAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, IndicesOptions.lenientExpandOpen());
    SyncedFlushRequest syncedFlushRequest = new SyncedFlushRequest(Strings.splitStringByCommaToArray(request.param("index")));
    syncedFlushRequest.indicesOptions(indicesOptions);
    return channel -> client.admin().indices().syncedFlush(syncedFlushRequest, new RestBuilderListener<SyncedFlushResponse>(channel) {

        @Override
        public RestResponse buildResponse(SyncedFlushResponse results, XContentBuilder builder) throws Exception {
            builder.startObject();
            results.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(results.restStatus(), builder);
        }
    });
}
Also used : SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) NodeClient(org.elasticsearch.client.node.NodeClient) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) SyncedFlushResponse(org.elasticsearch.action.admin.indices.flush.SyncedFlushResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) SyncedFlushRequest(org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 10 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class RestTypesExistsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    TypesExistsRequest typesExistsRequest = new TypesExistsRequest(Strings.splitStringByCommaToArray(request.param("index")), Strings.splitStringByCommaToArray(request.param("type")));
    typesExistsRequest.local(request.paramAsBoolean("local", typesExistsRequest.local()));
    typesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, typesExistsRequest.indicesOptions()));
    return channel -> client.admin().indices().typesExists(typesExistsRequest, new RestResponseListener<TypesExistsResponse>(channel) {

        @Override
        public RestResponse buildResponse(TypesExistsResponse response) throws Exception {
            if (response.isExists()) {
                return new BytesRestResponse(OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
            } else {
                return new BytesRestResponse(NOT_FOUND, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
            }
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) RestResponse(org.elasticsearch.rest.RestResponse) IOException(java.io.IOException) NOT_FOUND(org.elasticsearch.rest.RestStatus.NOT_FOUND) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) BytesArray(org.elasticsearch.common.bytes.BytesArray) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) TypesExistsRequest(org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) TypesExistsResponse(org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse) NodeClient(org.elasticsearch.client.node.NodeClient) HEAD(org.elasticsearch.rest.RestRequest.Method.HEAD) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) TypesExistsRequest(org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) TypesExistsResponse(org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse) IOException(java.io.IOException)

Aggregations

RestResponse (org.elasticsearch.rest.RestResponse)51 NodeClient (org.elasticsearch.client.node.NodeClient)48 Settings (org.elasticsearch.common.settings.Settings)48 RestController (org.elasticsearch.rest.RestController)48 RestRequest (org.elasticsearch.rest.RestRequest)48 GET (org.elasticsearch.rest.RestRequest.Method.GET)40 Strings (org.elasticsearch.common.Strings)33 IOException (java.io.IOException)31 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)31 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)30 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)27 RestBuilderListener (org.elasticsearch.rest.action.RestBuilderListener)25 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)23 OK (org.elasticsearch.rest.RestStatus.OK)20 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)20 Table (org.elasticsearch.common.Table)17 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)12 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)12 RestActions.buildBroadcastShardsHeader (org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader)11 RestStatus (org.elasticsearch.rest.RestStatus)10