Michael Decker created CXF-7457:
-----------------------------------

             Summary: ContainerRequestContextImpl.setRequestUri(URI) does not 
allow to remove all query parameters
                 Key: CXF-7457
                 URL: https://issues.apache.org/jira/browse/CXF-7457
             Project: CXF
          Issue Type: Bug
          Components: Core
    Affects Versions: 3.1.11
            Reporter: Michael Decker


If you call ContainerRequestContextImpl.setRequestUri(URI) you are able to 
update the URI, also the holded query parameters.

But if the new URI does not contain any query parameters, the already existing 
ones are not removed. If the new URI does contain at least one query parameter, 
all old ones will be removed.

    --- SNIP ---
protected void doSetRequestUri(URI requestUri) throws IllegalStateException {
...
    String query = requestUri.getRawQuery();
    if (query != null) { // <--- If new URI has no query, the old one will stay
        m.put(Message.QUERY_STRING, query);
    }
}
public void setRequestUri(URI baseUri, URI requestUri) throws 
IllegalStateException {
    doSetRequestUri(requestUri);
...
}
    --- SNAP ---

Perhaps there should be an "else { m.remove(Message.QUERY_STRING); }" statement.

The context was, that I tried to remove empty query parameters and failed, if 
none were left:
    --- SNIP ---
@PreMatching
public class CleanQueryParameterFilter implements ContainerRequestFilter {
  public void filter(ContainerRequestContext context) throws IOException {
    UriInfo uriInfo = context.getUriInfo();
    URI requestUri = uriInfo.getRequestUri();
    UriBuilder uriBuilder = UriBuilder.fromUri(requestUri);
    MultivaluedMap<String, String> queryParameters = 
uriInfo.getQueryParameters();
    // removing empty query parmeters
    ...
    // XXX Add always a pseudo query parameter
    uriBuilder.queryParam(KEY_PSEUDO, KEY_PSEUDO);
    
    URI build = uriBuilder.build();
    context.setRequestUri(build);
  }
}
    --- SNAP ---

I had also a look into the implementation of 
"org.glassfish.jersey.server.ContainerRequest" and 
"org.glassfish.jersey.server.internal.routing.UriRoutingContext". The parse the 
URI stored in ContainerRequest everytime, so I assume the update always works, 
even if all query parameter are removed.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to