88import org .jboss .resteasy .reactive .common .util .PathHelper ;
99import org .jboss .resteasy .reactive .server .core .Deployment ;
1010import org .jboss .resteasy .reactive .server .handlers .ClassRoutingHandler ;
11+ import org .jboss .resteasy .reactive .server .handlers .RestInitialHandler ;
1112import org .jboss .resteasy .reactive .server .mapping .RequestMapper ;
1213
1314import io .quarkus .runtime .RuntimeValue ;
@@ -54,24 +55,37 @@ private boolean shouldHandle(RoutingContext event) {
5455 public static void setTemplatePath (RoutingContext rc , Deployment deployment ) {
5556 // do what RestInitialHandler does
5657 var initMappers = new RequestMapper <>(deployment .getClassMappers ());
57- var requestMatch = initMappers .map (getPathWithoutPrefix (rc , deployment ));
58- if (requestMatch == null ) {
59- return ;
58+ var path = getPathWithoutPrefix (rc , deployment );
59+ var requestMatch = initMappers .map (path );
60+
61+ // try each class-level match until we find one whose method-level mapper also matches
62+ // this mirrors what ClassRoutingHandler does with restartWithNextInitialMatch()
63+ while (requestMatch != null ) {
64+ var templatePath = tryMatchTemplatePath (rc , requestMatch );
65+ if (templatePath != null ) {
66+ if (templatePath .endsWith ("/" )) {
67+ templatePath = templatePath .substring (0 , templatePath .length () - 1 );
68+ }
69+ setUrlPathTemplate (rc , templatePath );
70+ return ;
71+ }
72+ requestMatch = initMappers .continueMatching (path , requestMatch );
6073 }
74+ }
75+
76+ private static String tryMatchTemplatePath (RoutingContext rc ,
77+ RequestMapper .RequestMatch <RestInitialHandler .InitialMatch > requestMatch ) {
6178 var remaining = requestMatch .remaining .isEmpty () ? "/" : requestMatch .remaining ;
6279
6380 var serverRestHandlers = requestMatch .value .handlers ;
6481 if (serverRestHandlers == null || serverRestHandlers .length < 1 ) {
65- // nothing we can do
66- return ;
82+ return null ;
6783 }
6884 var firstHandler = serverRestHandlers [0 ];
69- if (!(firstHandler instanceof ClassRoutingHandler )) {
70- // nothing we can do
71- return ;
85+ if (!(firstHandler instanceof ClassRoutingHandler classRoutingHandler )) {
86+ return null ;
7287 }
7388
74- var classRoutingHandler = (ClassRoutingHandler ) firstHandler ;
7589 var mappers = classRoutingHandler .getMappers ();
7690
7791 var requestMethod = rc .request ().method ().name ();
@@ -86,8 +100,7 @@ public static void setTemplatePath(RoutingContext rc, Deployment deployment) {
86100 mapper = mappers .get (null );
87101 }
88102 if (mapper == null ) {
89- // can't match the path
90- return ;
103+ return null ;
91104 }
92105 }
93106 var target = mapper .map (remaining );
@@ -100,17 +113,11 @@ public static void setTemplatePath(RoutingContext rc, Deployment deployment) {
100113 }
101114
102115 if (target == null ) {
103- // can't match the path
104- return ;
116+ return null ;
105117 }
106118 }
107119
108- var templatePath = requestMatch .template .template + target .template .template ;
109- if (templatePath .endsWith ("/" )) {
110- templatePath = templatePath .substring (0 , templatePath .length () - 1 );
111- }
112-
113- setUrlPathTemplate (rc , templatePath );
120+ return requestMatch .template .template + target .template .template ;
114121 }
115122
116123 private static String getPathWithoutPrefix (RoutingContext rc , Deployment deployment ) {
0 commit comments