|
65 | 65 | import java.io.IOException;
|
66 | 66 | import java.io.InputStream;
|
67 | 67 | import java.net.URI;
|
| 68 | +import java.util.ArrayList; |
68 | 69 | import java.util.HashMap;
|
69 | 70 | import java.util.HashSet;
|
70 | 71 | import java.util.Iterator;
|
@@ -107,7 +108,7 @@ public class RestController implements HttpServerTransport.Dispatcher {
|
107 | 108 | }
|
108 | 109 | }
|
109 | 110 |
|
110 |
| - private final PathTrie<MethodHandlers> handlers = new PathTrie<>(RestUtils.REST_DECODER); |
| 111 | + private final PathTrie<RestMethodHandlers> handlers = new PathTrie<>(RestUtils.REST_DECODER); |
111 | 112 |
|
112 | 113 | private final UnaryOperator<RestHandler> handlerWrapper;
|
113 | 114 |
|
@@ -144,6 +145,16 @@ public RestController(
|
144 | 145 | );
|
145 | 146 | }
|
146 | 147 |
|
| 148 | + /** |
| 149 | + * Returns an iterator over registered REST method handlers. |
| 150 | + * @return {@link Iterator} of {@link MethodHandlers} |
| 151 | + */ |
| 152 | + public Iterator<MethodHandlers> getAllHandlers() { |
| 153 | + List<MethodHandlers> methodHandlers = new ArrayList<>(); |
| 154 | + handlers.retrieveAll().forEachRemaining(methodHandlers::add); |
| 155 | + return methodHandlers.iterator(); |
| 156 | + } |
| 157 | + |
147 | 158 | /**
|
148 | 159 | * Registers a REST handler to be executed when the provided {@code method} and {@code path} match the request.
|
149 | 160 | *
|
@@ -221,7 +232,7 @@ protected void registerHandler(RestRequest.Method method, String path, RestHandl
|
221 | 232 | private void registerHandlerNoWrap(RestRequest.Method method, String path, RestHandler maybeWrappedHandler) {
|
222 | 233 | handlers.insertOrUpdate(
|
223 | 234 | path,
|
224 |
| - new MethodHandlers(path, maybeWrappedHandler, method), |
| 235 | + new RestMethodHandlers(path, maybeWrappedHandler, method), |
225 | 236 | (mHandlers, newMHandler) -> mHandlers.addMethods(maybeWrappedHandler, method)
|
226 | 237 | );
|
227 | 238 | }
|
@@ -392,10 +403,10 @@ private void tryAllHandlers(final RestRequest request, final RestChannel channel
|
392 | 403 | // Resolves the HTTP method and fails if the method is invalid
|
393 | 404 | requestMethod = request.method();
|
394 | 405 | // Loop through all possible handlers, attempting to dispatch the request
|
395 |
| - Iterator<MethodHandlers> allHandlers = getAllHandlers(request.params(), rawPath); |
| 406 | + Iterator<RestMethodHandlers> allHandlers = getAllRestMethodHandlers(request.params(), rawPath); |
396 | 407 | while (allHandlers.hasNext()) {
|
397 | 408 | final RestHandler handler;
|
398 |
| - final MethodHandlers handlers = allHandlers.next(); |
| 409 | + final RestMethodHandlers handlers = allHandlers.next(); |
399 | 410 | if (handlers == null) {
|
400 | 411 | handler = null;
|
401 | 412 | } else {
|
@@ -423,7 +434,7 @@ private void tryAllHandlers(final RestRequest request, final RestChannel channel
|
423 | 434 | handleBadRequest(uri, requestMethod, channel);
|
424 | 435 | }
|
425 | 436 |
|
426 |
| - Iterator<MethodHandlers> getAllHandlers(@Nullable Map<String, String> requestParamsRef, String rawPath) { |
| 437 | + Iterator<RestMethodHandlers> getAllRestMethodHandlers(@Nullable Map<String, String> requestParamsRef, String rawPath) { |
427 | 438 | final Supplier<Map<String, String>> paramsSupplier;
|
428 | 439 | if (requestParamsRef == null) {
|
429 | 440 | paramsSupplier = () -> null;
|
@@ -561,7 +572,7 @@ private boolean handleAuthenticateUser(final RestRequest request, final RestChan
|
561 | 572 | */
|
562 | 573 | private Set<RestRequest.Method> getValidHandlerMethodSet(String rawPath) {
|
563 | 574 | Set<RestRequest.Method> validMethods = new HashSet<>();
|
564 |
| - Iterator<MethodHandlers> allHandlers = getAllHandlers(null, rawPath); |
| 575 | + Iterator<RestMethodHandlers> allHandlers = getAllRestMethodHandlers(null, rawPath); |
565 | 576 | while (allHandlers.hasNext()) {
|
566 | 577 | final MethodHandlers methodHandlers = allHandlers.next();
|
567 | 578 | if (methodHandlers != null) {
|
|
0 commit comments