Skip to content

Commit

Permalink
Change uri to path in RestRequest handling
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Sep 30, 2022
1 parent a9033cb commit ca71302
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/opensearch/sdk/ExtensionRestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public interface ExtensionRestHandler {
* Handles REST Requests forwarded from OpenSearch for a configured route on an extension.
* Parameter contains components of the {@link RestRequest} received from a user.
* This method corresponds to the {@link BaseRestHandler#prepareRequest} method.
* As in that method, consumed parameters must be tracked and returned in the response.
*
* @param request a REST request object for a request to be forwarded to extensions
* @return An {@link ExtensionRestResponse} to the request.
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/opensearch/sdk/ExtensionRestPathRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class ExtensionRestPathRegistry {
* Register a REST handler to handle a method and route in this extension's path registry.
*
* @param method The method to register.
* @param uri The URI to register. May include named wildcards.
* @param path The path to register. May include named wildcards.
* @param extensionRestHandler The RestHandler to handle this route
*/
public void registerHandler(Method method, String uri, ExtensionRestHandler extensionRestHandler) {
String restPath = restPathToString(method, uri);
public void registerHandler(Method method, String path, ExtensionRestHandler extensionRestHandler) {
String restPath = restPathToString(method, path);
pathTrie.insert(restPath, extensionRestHandler);
registeredPaths.add(restPath);
}
Expand All @@ -41,11 +41,11 @@ public void registerHandler(Method method, String uri, ExtensionRestHandler exte
* Get the registered REST handler for the specified method and URI.
*
* @param method the registered method.
* @param uri the registered URI.
* @param path the registered path.
* @return The REST handler registered to handle this method and URI combination if found, null otherwise.
*/
public ExtensionRestHandler getHandler(Method method, String uri) {
return pathTrie.retrieve(restPathToString(method, uri));
public ExtensionRestHandler getHandler(Method method, String path) {
return pathTrie.retrieve(restPathToString(method, path));
}

/**
Expand All @@ -58,13 +58,13 @@ public List<String> getRegisteredPaths() {
}

/**
* Converts a REST method and URI to a string.
* Converts a REST method and path to a space delimited string to be used as a map lookup key.
*
* @param method the method.
* @param uri the URI.
* @return A string appending the method and URI.
* @param path the path.
* @return A string appending the method and path.
*/
public static String restPathToString(Method method, String uri) {
return method.name() + " " + uri;
public static String restPathToString(Method method, String path) {
return method.name() + " " + path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public class ExtensionsRestRequestHandler {
*/
public RestExecuteOnExtensionResponse handleRestExecuteOnExtensionRequest(ExtensionRestRequest request) {

ExtensionRestHandler restHandler = extensionRestPathRegistry.getHandler(request.method(), request.uri());
ExtensionRestHandler restHandler = extensionRestPathRegistry.getHandler(request.method(), request.path());
if (restHandler == null) {
return new RestExecuteOnExtensionResponse(
RestStatus.NOT_FOUND,
"No handler for " + ExtensionRestPathRegistry.restPathToString(request.method(), request.uri())
"No handler for " + ExtensionRestPathRegistry.restPathToString(request.method(), request.path())
);
}

Expand Down

0 comments on commit ca71302

Please sign in to comment.