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.
This commit is contained in:
Simon Willnauer 2018-10-10 17:28:07 +01:00 committed by GitHub
parent 4b7257d971
commit 34b935ae57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -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:
* <pre>
* {@code
* UnaryOperator<RestHandler> 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);
* };
* }
* }
* </pre>
*
* Note: Only one installed plugin may implement a rest wrapper.
*/