[
https://issues.apache.org/jira/browse/CXF-7457?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18136184#comment-18136184
]
Freeman Yue Fang commented on CXF-7457:
---------------------------------------
This issue still matters now, I can reproduce it with CXF 4.2.4/4.1.9
> 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
> Assignee: Freeman Yue Fang
> Priority: Major
> 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)