forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[Backport 2.x] Support transport action names when registerin…
…g NamedRoutes (opensearch-project#7957) (opensearch-project#8459)" This reverts commit cd82f4c.
- Loading branch information
1 parent
54eef1f
commit ebf3ebc
Showing
11 changed files
with
185 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
server/src/main/java/org/opensearch/extensions/rest/RouteHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.extensions.rest; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.opensearch.rest.RestHandler.Route; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.RestRequest.Method; | ||
|
||
/** | ||
* A subclass of {@link Route} that includes a handler method for that route. | ||
*/ | ||
public class RouteHandler extends Route { | ||
|
||
private final String name; | ||
|
||
private final Function<RestRequest, ExtensionRestResponse> responseHandler; | ||
|
||
/** | ||
* Handle the method and path with the specified handler. | ||
* | ||
* @param method The {@link Method} to handle. | ||
* @param path The path to handle. | ||
* @param handler The method which handles the method and path. | ||
*/ | ||
public RouteHandler(Method method, String path, Function<RestRequest, ExtensionRestResponse> handler) { | ||
super(method, path); | ||
this.responseHandler = handler; | ||
this.name = null; | ||
} | ||
|
||
/** | ||
* Handle the method and path with the specified handler. | ||
* | ||
* @param name The name of the handler. | ||
* @param method The {@link Method} to handle. | ||
* @param path The path to handle. | ||
* @param handler The method which handles the method and path. | ||
*/ | ||
public RouteHandler(String name, Method method, String path, Function<RestRequest, ExtensionRestResponse> handler) { | ||
super(method, path); | ||
this.responseHandler = handler; | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Executes the handler for this route. | ||
* | ||
* @param request The request to handle | ||
* @return the {@link ExtensionRestResponse} result from the handler for this route. | ||
*/ | ||
public ExtensionRestResponse handleRequest(RestRequest request) { | ||
return responseHandler.apply(request); | ||
} | ||
|
||
/** | ||
* The name of the RouteHandler. Must be unique across route handlers. | ||
*/ | ||
public String name() { | ||
return this.name; | ||
} | ||
} |
Oops, something went wrong.