From 34b935ae57bd513db77327074534cdf8f5dd02e7 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 10 Oct 2018 17:28:07 +0100 Subject: [PATCH] Improve `getRestHandlerWrapper` JavaDocs (#34376) Questions on how to work with `ActionPlugin#getRestHandlerWrapper()` come up in discuss forums all the time. This change adds an example to the javadoc how this method should/could be used. --- .../org/elasticsearch/plugins/ActionPlugin.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/plugins/ActionPlugin.java b/server/src/main/java/org/elasticsearch/plugins/ActionPlugin.java index 54d9ade581e..c0d94c3f000 100644 --- a/server/src/main/java/org/elasticsearch/plugins/ActionPlugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/ActionPlugin.java @@ -103,6 +103,22 @@ public interface ActionPlugin { /** * Returns a function used to wrap each rest request before handling the request. + * The returned {@link UnaryOperator} is called for every incoming rest request and receives + * the original rest handler as it's input. This allows adding arbitrary functionality around + * rest request handlers to do for instance logging or authentication. + * A simple example of how to only allow GET request is here: + *
+     * {@code
+     *    UnaryOperator getRestHandlerWrapper(ThreadContext threadContext) {
+     *      return originalHandler -> (RestHandler) (request, channel, client) -> {
+     *        if (request.method() != Method.GET) {
+     *          throw new IllegalStateException("only GET requests are allowed");
+     *        }
+     *        originalHandler.handleRequest(request, channel, client);
+     *      };
+     *    }
+     * }
+     * 
* * Note: Only one installed plugin may implement a rest wrapper. */