|
6 | 6 | * compatible open source license.
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -package org.opensearch.api; |
| 9 | +package org.opensearch.plugin.api; |
10 | 10 |
|
11 |
| -import java.io.IOException; |
12 |
| -import java.util.List; |
13 |
| - |
14 |
| -import org.opensearch.api.action.api.APIAction; |
15 |
| -import org.opensearch.api.action.api.APIRequest; |
16 |
| -import org.opensearch.api.action.api.APIResponse; |
17 | 11 | import org.opensearch.client.node.NodeClient;
|
18 | 12 | import org.opensearch.core.rest.RestStatus;
|
19 | 13 | import org.opensearch.core.xcontent.XContentBuilder;
|
| 14 | +import org.opensearch.plugin.api.action.api.APIAction; |
| 15 | +import org.opensearch.plugin.api.action.api.APIRequest; |
| 16 | +import org.opensearch.plugin.api.action.api.APIResponse; |
20 | 17 | import org.opensearch.rest.BaseRestHandler;
|
21 | 18 | import org.opensearch.rest.BytesRestResponse;
|
| 19 | +import org.opensearch.rest.RestController; |
22 | 20 | import org.opensearch.rest.RestRequest;
|
23 | 21 | import org.opensearch.rest.RestResponse;
|
24 | 22 | import org.opensearch.rest.action.RestBuilderListener;
|
25 | 23 |
|
26 |
| -import static org.opensearch.rest.RestRequest.Method.GET; |
| 24 | +import java.io.IOException; |
| 25 | +import java.util.List; |
| 26 | + |
27 | 27 | import static java.util.Arrays.asList;
|
28 | 28 | import static java.util.Collections.unmodifiableList;
|
| 29 | +import static org.opensearch.rest.RestRequest.Method.GET; |
29 | 30 |
|
30 | 31 | /**
|
31 | 32 | * A REST handler.
|
32 | 33 | */
|
33 | 34 | public class RestAPIAction extends BaseRestHandler {
|
| 35 | + RestController restController; |
| 36 | + |
| 37 | + RestAPIAction(RestController restController) { |
| 38 | + this.restController = restController; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * |
| 43 | + * @return |
| 44 | + */ |
34 | 45 | @Override
|
35 | 46 | public String getName() {
|
36 | 47 | return "api";
|
37 | 48 | }
|
38 | 49 |
|
| 50 | + /** |
| 51 | + * |
| 52 | + * @return |
| 53 | + */ |
39 | 54 | @Override
|
40 |
| - public List routes() { |
41 |
| - return unmodifiableList(asList( |
42 |
| - new Route(GET, "/_plugins/api") |
43 |
| - )); |
| 55 | + public List<Route> routes() { |
| 56 | + return unmodifiableList(asList(new Route(GET, "/_plugins/api"))); |
44 | 57 | }
|
45 | 58 |
|
| 59 | + /** |
| 60 | + * |
| 61 | + * @param request the request to execute |
| 62 | + * @param client client for executing actions on the local node |
| 63 | + * @return |
| 64 | + * @throws IOException |
| 65 | + */ |
46 | 66 | @Override
|
47 | 67 | protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
48 | 68 | return channel -> client.execute(APIAction.INSTANCE, new APIRequest(), new RestBuilderListener<APIResponse>(channel) {
|
49 | 69 | @Override
|
50 | 70 | public RestResponse buildResponse(APIResponse response, XContentBuilder builder) throws Exception {
|
| 71 | + response.setRestController(restController); |
51 | 72 | response.toXContent(builder, request);
|
52 | 73 | return new BytesRestResponse(RestStatus.OK, builder);
|
53 | 74 | }
|
|
0 commit comments