Repository: quarkusio/quarkus
Issue: Resteasy-reactive routing does not work for PathParam/RestPath when declared inside a bean @BeanParam when paths are shared across classes

### Describe the bug

Resteasy-reactive routing does not work for PathParam/RestPath when declared inside a bean @BeanParam when paths are shared across classes. It works when is not declared inside a @BeanParam. 

This behavior is stopping us from upgrading to resteasy reactive.

### Expected behavior

PathParam/RestPath should work when inside a @BeanParam.

### Actual behavior

_No response_

### How to Reproduce?

[code-with-quarkus 2.zip](https://github.com/quarkusio/quarkus/files/7381025/code-with-quarkus.2.zip)


### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

_No response_

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

_No response_

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

_No response_

### Additional information

_No response_

Changed files:
extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorBaseResource.java
independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java
extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorSubresource.java
extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java

diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java
index 020a3458cb1..b1dcf340346 100644
--- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java
+++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/ResourceLocatorTest.java
@@ -1,5 +1,8 @@
 package io.quarkus.resteasy.reactive.server.test.resource.basic;
 
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.is;
+
 import java.util.function.Supplier;
 
 import javax.ws.rs.client.Client;
@@ -144,4 +147,12 @@ public void testAnnotationFreeSubresource() throws Exception {
             Assertions.assertEquals("posted: hello!", response.readEntity(String.class));
         }
     }
+
+    @Test
+    @DisplayName("Test @BeanParam annotation in Subresources")
+    public void testBeanParamsInSubresource() {
+        given().get("/sub3/first/resources/subresource3?value=second")
+                .then()
+                .body(is("first and second"));
+    }
 }
diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorBaseResource.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorBaseResource.java
index a6b50a2c5bf..8b8d305ffd8 100644
--- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorBaseResource.java
+++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorBaseResource.java
@@ -46,4 +46,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
                 });
     }
 
+    @Path("sub3/{param}/resources")
+    public ResourceLocatorSubresource getSubresource() {
+        return new ResourceLocatorSubresource();
+    }
+
 }
diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorSubresource.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorSubresource.java
index 088fe7c7179..2f7563ecd5c 100644
--- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorSubresource.java
+++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/resource/basic/resource/ResourceLocatorSubresource.java
@@ -2,12 +2,15 @@
 
 import java.util.List;
 
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
 
 import org.jboss.logging.Logger;
+import org.jboss.resteasy.reactive.RestPath;
 import org.junit.jupiter.api.Assertions;
 
 public class ResourceLocatorSubresource {
@@ -52,4 +55,17 @@ public Object getSubresource2(@Context UriInfo uri) {
             LOG.debugv("   {0}", ancestor.getClass().getName());
         return new ResourceLocatorSubresource2();
     }
+
+    @GET
+    @Path("/subresource3")
+    public String getValueFromBeanParam(@BeanParam Params params) {
+        return params.param + " and " + params.value;
+    }
+
+    public static class Params {
+        @RestPath
+        String param;
+        @QueryParam("value")
+        String value;
+    }
 }
diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java
index 4ae1a747cd1..4be7fc383e9 100644
--- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java
+++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java
@@ -895,12 +895,20 @@ public String getPathParameter(String name, boolean encoded) {
         // this is a slower version than getPathParam, but we can't actually bake path indices inside
         // BeanParam classes (which use thismethod ) because they can be used by multiple resources that would have different
         // indices
-        Integer index = this.target.getPathParameterIndexes().get(name);
+        Integer index = target.getPathParameterIndexes().get(name);
+        String value;
+        if (index != null) {
+            value = getPathParam(index);
+        } else {
+            // Check previous resources if the path is not defined in the current target
+            value = getResourceLocatorPathParam(name);
+        }
+
         // It's possible to inject a path param that's not defined, return null in this case
-        String value = index != null ? getPathParam(index) : null;
         if (encoded && value != null) {
             return Encode.encodeQueryParam(value);
         }
+
         return value;
     }