[ 
https://issues.apache.org/jira/browse/CXF-7457?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Freeman Yue Fang updated CXF-7457:
----------------------------------
    Fix Version/s: 3.6.14
                   4.2.5
                   4.1.10

> 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: JAX-RS
>    Affects Versions: 3.1.11
>            Reporter: Michael Decker
>            Assignee: Freeman Yue Fang
>            Priority: Major
>             Fix For: 3.6.14, 4.2.5, 4.1.10
>
>         Attachments: CXF-7454.tar
>
>
> 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
(v10.3.26#10030026)

Reply via email to