Skip to content

Commit 1cad445

Browse files
committed
Improve getRestHandlerWrapper JavaDocs (elastic#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.
1 parent 3ac2b31 commit 1cad445

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

server/src/main/java/org/elasticsearch/plugins/ActionPlugin.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ default Collection<String> getTaskHeaders() {
103103

104104
/**
105105
* Returns a function used to wrap each rest request before handling the request.
106+
* The returned {@link UnaryOperator} is called for every incoming rest request and receives
107+
* the original rest handler as it's input. This allows adding arbitrary functionality around
108+
* rest request handlers to do for instance logging or authentication.
109+
* A simple example of how to only allow GET request is here:
110+
* <pre>
111+
* {@code
112+
* UnaryOperator<RestHandler> getRestHandlerWrapper(ThreadContext threadContext) {
113+
* return originalHandler -> (RestHandler) (request, channel, client) -> {
114+
* if (request.method() != Method.GET) {
115+
* throw new IllegalStateException("only GET requests are allowed");
116+
* }
117+
* originalHandler.handleRequest(request, channel, client);
118+
* };
119+
* }
120+
* }
121+
* </pre>
106122
*
107123
* Note: Only one installed plugin may implement a rest wrapper.
108124
*/

0 commit comments

Comments
 (0)