Skip to content

UriInfo.getRequestUri loses query parameters if ContainerRequestContext.setRequestUri is called #49064

@stefanc-ro

Description

@stefanc-ro

Describe the bug

If a pre-matching ContainerRequestFilter updates the request URI via ContainerRequestContext.setRequestUri then UriInfo.getRequestUri does not contain the query parameters anymore.

Expected behavior

After an update UriInfo.getRequestUri should contain the query parameters based on the URI set by ContainerRequestContext.setRequestUri.

Actual behavior

The query parameters are extracted from the specified URI and stored internally but the URI which is returned by UriInfo.getRequestUri does not contain any query parameters (neither the old nor the new).

How to Reproduce?

Create a resource:

@Path("/hello")
public class GreetingResource {
    
    @Context
    UriInfo uriInfo;
    
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        System.out.println("URI inside resource: "+uriInfo.getRequestUri());
        System.out.println("Query parameters inside resource: "+uriInfo.getQueryParameters());
        
        return "Hello from Quarkus REST";
    }
}

Use a container request filter:

@Provider
@PreMatching
public class MyFilter implements ContainerRequestFilter {
    
    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        // Unmodified: "http://localhost:8080/hello.pdf?a=b&x=y"
        System.out.println("URI before filter update: "+requestContext.getUriInfo().getRequestUri());
        System.out.println("Query parameters before filter update: "+requestContext.getUriInfo().getQueryParameters());
        
        // update: cut out ".pdf" and remove "x=y"
        requestContext.setRequestUri(URI.create("http://localhost:8080/hello?a=b"));
        
        // Actual result:   "http://localhost:8080/hello"
        // Expected result: "http://localhost:8080/hello?a=b"
        System.out.println("URI after filter update: "+requestContext.getUriInfo().getRequestUri());
        System.out.println("Query parameters after filter update: "+requestContext.getUriInfo().getQueryParameters());
    }
}

Start with quarkus dev.
Use curl -X GET "http://localhost:8080/hello.pdf?a=b&x=y" to print the values.

Output of uname -a or ver

Microsoft Windows [Version 10.0.26100.3775]

Output of java -version

java 24.0.1 2025-04-15 Java(TM) SE Runtime Environment (build 24.0.1+9-30) Java HotSpot(TM) 64-Bit Server VM (build 24.0.1+9-30, mixed mode, sharing)

Quarkus version or git rev

3.24.4

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

Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)

Additional information

The issue seems to be caused by:

ResteasyReactiveRequestContext.getAbsoluteURI()

  1. It uses serverRequest().getRequestAbsoluteUri() if path is null (includes query parameters)
  2. It uses new URI(getScheme(), getAuthority(), path, null, null).toASCIIString() if path is not null (ignores query parameters)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions