Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1308

ContainerRequestContext setRequestUri doesn't clear previous query parameters

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.0.17.Final
    • 3.0.16.Final
    • jaxrs
    • None
    • Hide

      As a workaround, you'd want to first clear the existing query parameters before calling setRequestUri, which is fortunately possible because UriInfo.getQueryParameters erroneously returns a mutable map. Be sure to clear both unencoded and encoded parameters:

      // Start workaround for this issue
      requestContext.getUriInfo().getQueryParameters(false).clear();
      requestContext.getUriInfo().getQueryParameters(true).clear();
      // end workaround
      requestContext.setRequestUri(newBaseUri, newRequestUri);
      
      Show
      As a workaround, you'd want to first clear the existing query parameters before calling setRequestUri , which is fortunately possible because UriInfo.getQueryParameters erroneously returns a mutable map. Be sure to clear both unencoded and encoded parameters: // Start workaround for this issue requestContext.getUriInfo().getQueryParameters( false ).clear(); requestContext.getUriInfo().getQueryParameters( true ).clear(); // end workaround requestContext.setRequestUri(newBaseUri, newRequestUri);

      As a followup to RESTEASY-1099, when calling setRequestUri, the current query parameters aren't cleared, and new query parameters are merged into existing ones.

      In my specific case (OAuth/OpenID Connect implementation, setRequestUri being called from a pre-matching filter to rewrite the URI depending on X-Forwarded-Proto), the problem is that having parameters appearing more than once is seen as an error (even if repeated with the same value). So my filter (see code snippet in RESTEASY-1099) is breaking my downstream resource by artificially duplicating the query parameters.

      Note that the workaround highlights another bug: UriInfo.getQueryParameters returns mutable maps.

              mstefank Martin Stefanko
              t.broyer Thomas Broyer (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: