users@jsr311.java.net

Re: Difference between UriBuilder.buildFromEncoded and UriBuilder.build

From: Sergey Beryozkin <sberyozk_at_progress.com>
Date: Thu, 12 Mar 2009 13:17:20 -0000

I've used wrong URI string values containing spaces in examples, please assume such values has been added using
UriBuilder.path(String) or UriBuilder.queryParam() methods. There's also a typo so here're revised examples


assertEquals("http://bar/foo%20%252B+%2520%252?q=+%252B%2B%2520"
                   UriBuilder.fromUri("http://bar/").path("foo %2B+%20%2").queryParam("q", " %2B+%20").build()).toString());

assertEquals("http://bar/foo%20%2B+%20%252?q=+%2B%2B%20"
                    UriBuilder.fromUri("http://bar/).path("foo %2B+%20%2").queryParam("q", "
%2B+%20").buildfromEncoded().toString());

I'd also to check that encoded %2B ('+') are retained in the encoded form after buildfromEncoded(). '+' are untouched in the path
segments while converted to %2B in queries, finally ' ' is replaced with '+' in queries

Cheers, Sergey



> Hi,
>
> Few more questions about UriBuilder.buildFromEncoded().
>
> Basically, affer reading the JavaDocs again, my understanding is that the only difference between UriBuilder.buildFromEncoded()
> and UriBuilder.build() is that in the latter case every character is encoded (except for the reserved path segment characters),
> while with the former everything is also encoded with the exception of percent-encoded values left untouched.
>
> Is it a correct interpretation ?
>
> Here're 2 examples to verify if I'm getting it right :
>
> assertEquals("http://bar/foo%20%252B+%2520%252?q=+%252B%2B%2520"
> UriBuilder.fromUri("http://bar/foo %2B+%20%2?q= %2B+%20").build(),toString());
>
> assertEquals("http://bar/foo%20%2B+%20%252?q= +%2B%2B%20"
> UriBuilder.fromUri("http://bar/foo %2B+%20%2?q= %2B+%20").buildfromEncoded(),toString());
>
> Is it correct?
> thanks, Sergey
>