From 2d6cdd95c154c4fded117775a9e3fed11c871ac1 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Sun, 4 Aug 2019 11:04:31 -0400 Subject: [PATCH] UNDERTOW-1581: Fix RoutingHandler allMethodsMatcher validation Updates the allMethodsMatcher to lookup templates using the match method instead of get in order to normalize the input. Previously registration would throw an exception when routes were added for the same path template with different parameter names despite being equivalent. From https://github.com/undertow-io/undertow/pull/799 --- core/src/main/java/io/undertow/server/RoutingHandler.java | 6 +++--- .../io/undertow/server/handlers/RoutingHandlerTestCase.java | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/undertow/server/RoutingHandler.java b/core/src/main/java/io/undertow/server/RoutingHandler.java index e873b94b4..8603d0b6f 100644 --- a/core/src/main/java/io/undertow/server/RoutingHandler.java +++ b/core/src/main/java/io/undertow/server/RoutingHandler.java @@ -120,7 +120,7 @@ public synchronized RoutingHandler add(String method, String template, HttpHandl if (res == null) { matcher.add(template, res = new RoutingMatch()); } - if (allMethodsMatcher.get(template) == null) { + if (allMethodsMatcher.match(template) == null) { allMethodsMatcher.add(template, res); } res.defaultHandler = handler; @@ -152,7 +152,7 @@ public synchronized RoutingHandler add(String method, String template, Predicate if (res == null) { matcher.add(template, res = new RoutingMatch()); } - if (allMethodsMatcher.get(template) == null) { + if (allMethodsMatcher.match(template) == null) { allMethodsMatcher.add(template, res); } res.predicatedHandlers.add(new HandlerHolder(predicate, handler)); @@ -186,7 +186,7 @@ public synchronized RoutingHandler addAll(RoutingHandler routingHandler) { // If we use allMethodsMatcher.addAll() we can have duplicate // PathTemplates which we want to ignore here so it does not crash. for (PathTemplate template : entry.getValue().getPathTemplates()) { - if (allMethodsMatcher.get(template.getTemplateString()) == null) { + if (allMethodsMatcher.match(template.getTemplateString()) == null) { allMethodsMatcher.add(template, new RoutingMatch()); } } diff --git a/core/src/test/java/io/undertow/server/handlers/RoutingHandlerTestCase.java b/core/src/test/java/io/undertow/server/handlers/RoutingHandlerTestCase.java index 1ad0994f0..48eb89b79 100644 --- a/core/src/test/java/io/undertow/server/handlers/RoutingHandlerTestCase.java +++ b/core/src/test/java/io/undertow/server/handlers/RoutingHandlerTestCase.java @@ -126,6 +126,12 @@ public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.writeAsync("posted foo"); } }) + .add(HttpMethodNames.POST, "/foo/{baz}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + exchange.writeAsync("foo-path" + exchange.getQueryParameters().get("bar")); + } + }) .add(HttpMethodNames.GET, "/foo/{bar}", new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception {