users@jersey.java.net

[Jersey] Re: UriBuilder does not properly encode query parameters?

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 22 Aug 2013 11:28:56 +0200

Hi Martynas,

I believe this is not a bug. The hash sign gets encoded,
so that it is not misinterpreted as query string end-delimiter,
otherwise leaving slashes intact is perfectly valid within query string.

To get what you want, you should be able to use something like:

builder.queryParam("mode", "http://client.graphity.org/ontology#TableMode".replaceAll("/","%2F")

~Jakub


On Aug 21, 2013, at 12:12 PM, Martynas Jusevičius <martynas_at_graphity.org> wrote:

> I'm using Jersey 1.16 by the way. Could this be a bug?
>
> On Wed, Aug 21, 2013 at 1:09 PM, Martynas Jusevičius
> <martynas_at_graphity.org> wrote:
>> Hey all,
>>
>> I'm passing URI as query parameter to UriBuilder:
>>
>> builder.queryParam("mode", "http://client.graphity.org/ontology#TableMode")
>>
>> I expect it to get fully URI-encoded, but what I get instead is
>>
>> &mode=http://client.graphity.org/ontology%23TableMode
>>
>> where slashes are left unencoded. I tried buildFromEncoded() as well,
>> but the result it the same.
>>
>> Why this weird behavior and how can I work around it?
>>
>> Martynas
>> graphityhq.com