Skip to content

Commit 6a9fb11

Browse files
committed
Improve path matching in RESTEasy Reactive for ambiguous path templates
This solves further problems in case when the paths are spread over multiple resource classes. Improves earlier PR: #47386
1 parent 0a38fa7 commit 6a9fb11

File tree

2 files changed

+28
-15
lines changed
  • independent-projects/resteasy-reactive/server

2 files changed

+28
-15
lines changed

independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/mapping/RequestMapper.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,21 @@ public RequestMatch<T> continueMatching(String path, RequestMatch<T> lastMatch)
7272
return null;
7373
}
7474

75-
var initialMatches = requestPaths.match(path).get(0);
76-
var result = mapFromPathMatcher(path, initialMatches, 0);
77-
if (result != null) {
78-
int idx = nextMatchStartingIndex(initialMatches, lastMatch);
79-
return mapFromPathMatcher(path, initialMatches, idx);
75+
var initialMatchesList = requestPaths.match(path);
76+
for (var initialMatches: initialMatchesList) {
77+
var result = mapFromPathMatcher(path, initialMatches, 0);
78+
if (result != null) {
79+
int idx = nextMatchStartingIndex(initialMatches, lastMatch);
80+
RequestMatch<T> match = mapFromPathMatcher(path, initialMatches, idx);
81+
if (match != null) {
82+
return match;
83+
}
84+
}
8085
}
8186

8287
// the following code is meant to handle cases like https://github.com/quarkusio/quarkus/issues/30667
83-
initialMatches = requestPaths.defaultMatch(path);
84-
result = mapFromPathMatcher(path, initialMatches, 0);
88+
var initialMatches = requestPaths.defaultMatch(path);
89+
var result = mapFromPathMatcher(path, initialMatches, 0);
8590
if (result != null) {
8691
int idx = nextMatchStartingIndex(initialMatches, lastMatch);
8792
return mapFromPathMatcher(path, initialMatches, idx);
@@ -105,7 +110,7 @@ private int nextMatchStartingIndex(PathMatcher.PathMatch<ArrayList<RequestPath<T
105110
}
106111
}
107112

108-
return -1;
113+
return 0;
109114
}
110115

111116
@SuppressWarnings({ "rawtypes", "unchecked" })

independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/matching/PathParamOverlapTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class PathParamOverlapTest {
2525
@Override
2626
public JavaArchive get() {
2727
return ShrinkWrap.create(JavaArchive.class)
28-
.addClasses(TestResource.class);
28+
.addClasses(TestResource.class, AnotherResource.class);
2929
}
3030
});
3131

@@ -82,15 +82,11 @@ public void test() {
8282
.then()
8383
.statusCode(200)
8484
.body(equalTo("Foo bar_value"));
85-
}
8685

87-
// TODO: remove this test before commit
88-
@Test
89-
public void test2() {
90-
get("/hello/foo/bar_value")
86+
get("/hello/foo/bar/foo/bar")
9187
.then()
9288
.statusCode(200)
93-
.body(equalTo("Foo bar_value"));
89+
.body(equalTo("FooBarFooBar"));
9490
}
9591

9692
@Path("/hello")
@@ -122,4 +118,16 @@ public String fooBar(@RestPath String param) {
122118
}
123119

124120
}
121+
122+
/**
123+
* This is to also test paths spread over multiple resource classes.
124+
*/
125+
@Path("/hello/foo/bar")
126+
public static class AnotherResource {
127+
@GET
128+
@Path("/foo/bar")
129+
public String fooBarFooBar() {
130+
return "FooBarFooBar";
131+
}
132+
}
125133
}

0 commit comments

Comments
 (0)