I have the following filter in jersey 2.23 running in tomcat 7.0.69:
@PreMatching
@Priority(Priorities.HEADER_DECORATOR)
public class TestFilter implements ContainerRequestFilter {
@Context
HttpServletRequest req;
@Override
public void filter(ContainerRequestContext conReqCtx) throws IOException {
UriBuilder b = conReqCtx.getUriInfo().getRequestUriBuilder();
b.replaceQueryParam("a", "c");
conReqCtx.setRequestUri(b.build());
}
}
The filter replaces the value of the query param "a" with the value "c".
The controller looks like:
@Context
HttpServletRequest req;
@GET
@Path("/PathToController")
public Response get(@QueryParam("a") String val) {
System.out.println("Context query string: " + req.getQueryString());
System.out.println("Query param value:" + val);
...
}
I then make a request: http://localhost:8080/PathToController?a=b
I expect the output to be:
Context query string: a=c
Query param value: c
However, the output is:
Context query string: a=b
Query param value: c
So my filter modified the query param that is parsed using @QueryParam
, but it is not changing the injected context. Shouldn't the injected context also be modified by a PreMatching filter?