title: MultivaluedMap in RESTEasy and square brackets
body: <p>I'm building something of a relay server, using JAX-RS. I need to be able to extract any query parameters from a GET request and then re-wrap them into another request, to pass along to another server. I'm unfamiliar with <code>MultivaluedMap</code>, but I just figured out what is happening. The <code>UriInfo</code> class's <code>getQueryParameters</code> method returns a <code>MultivaluedMap&lt;String, String&gt;</code>. What bit me, unexpectedly, is that the values of each parameter are <code>List</code> values, even though they purport to be <code>String</code> values (by the way I read the JavaDoc).</p>
  <p>In other words, if I have a key-value pair of <code>foo=bar</code>, in the URL query string, when I extract the parameter, it comes out as <code>foo=[bar]</code>. This totally throws me for a loop (a 500 Server Error, actually) when I try to re-wrap the parameter and send it along to the other server.</p>
  <p>Is there another way to handle unpacking the query string from a Request, and then re-packing it for another Request? I'm including some code to illustrate my issue:</p>
  <pre><code>@GET
  @Path(&quot;parameters&quot;)
  public Response showParameters(@Context UriInfo uriInfo) {
      
      MultivaluedMap&lt;String, String&gt; parameters = uriInfo.getQueryParameters();
      
      StringBuffer sb = new StringBuffer();
      
      sb.append(&quot;&lt;h4&gt;Parameters:&lt;/h4&gt;&quot;);
      if (parameters != null) {
          sb.append(&quot;&lt;ul&gt;&quot;);
          Iterator it = parameters.keySet().iterator();
          while (it.hasNext()) {
              String key = (String)it.next();
              sb.append(&quot;&lt;li&gt;&quot;)
                  .append(key)
                  .append(&quot;: &quot;)
                  .append(parameters.get(key))
                  .append(&quot;&lt;/li&gt;&quot;);
          }
          sb.append(&quot;&lt;/ul&gt;&quot;);
      }
      else {
          sb.append(&quot;&lt;p&gt;None&lt;/p&gt;&quot;);   
      }
      
      return Response.ok(sb.toString()).build();
  }
  </code></pre>
  <p>So, in summary, what gets printed out from the code above, if the request has query parameters, is something like this:</p>
  <p><strong>Parameters:</strong></p>
  <ul>
  <li>key1: [value1]</li>
  <li>key2: [value2]</li>
  <li>key3: [value3]</li>
  </ul>
  <p>Is there another way to unpack/re-pack, and maybe avoid this whole issue altogether? Thanks.</p>
  <h2>Complete answer</h2>
  <p>@Jack deserves credit for pointing me in the right direction, and I am marking <a href="https://stackoverflow.com/a/24833458/155167">his answer</a> as correct, but here is what I got working.</p>
  <pre><code>    Client client = ClientBuilder.newClient();
      
      // Assume instance variable providing URI (without query string).
      WebTarget target = client.target(theRequestUri);
      
      // Instance variable uriInfo.
      MultivaluedMap&lt;String, String&gt; parameters = uriInfo.getQueryParameters();
      
      if (parameters != null &amp;&amp; parameters.size() &gt; 0) {
          Iterator it = parameters.keySet().iterator();
          String key = null;
          StringTokenizer st = null;
          
          while (it.hasNext()) {
              key = (String)it.next();
              
              // RESTEasy API is quirky, here. It wraps the values in square 
              // brackets; moreover, each value is separated by a comma and  
              // padded by a space as well. ([one, two, three, etc])
              
              st = new StringTokenizer(parameters.get(key).toString(), &quot;[,]&quot;);
              while (st.hasMoreTokens()) {
                  target = target.queryParam(key, st.nextToken().trim());
              }
          }
      }
      
      // Instance method: getContentType.
      Response response = target.request().accept(getContentType()).get();
  </code></pre>