[jax-rs-spec users] [jsr339-experts] UriBuilder, forward slashes, path and segments

From: Sergey Beryozkin <>
Date: Fri, 1 Jun 2012 11:26:14 +0100


I remember the lively thread we had awhile back about encoding "/"
passed to UriBuilder path and segment methods as if it was yesterday
when we talked about it :-), but I have to admit I've no idea what the
actual conclusion to it was, sorry :-)

I've just had a related query on the users list and I'm coming to the
conclusion that the encoding of "/" should be different depending on
when it is passed to UriBuilder, in case of path() methods:

1. UriBuilder.fromPath("").path("a/b").build()
    should produce "a/b" - as per the JavaDocs of path(...)

2. UriBuilder.fromPath("").path("{a}").build("a/b")
    should produce "a%2Fb"

The reason I think the 2nd variant should produce "a%2Fb" is because
producing "a/b" will be inconsistent with the fact the the matching
algorithm will not actually match "a/b" when we have @Path("{a}") and I
think it should kind of work both ways.

I'm not sure all will agree as one can imagine it can break some
existing code, but please imagine JAX-RS 2.0 Client code doing 1. above
and working against the endpoint with @Path("{a}") and then repeating 2.
and failing against the same endpoint

For segments, the forward slash has to be encoded all the time:

1. UriBuilder.fromPath("").segment("a/b").build()
    should produce "a%2Fb" - as per the JavaDocs of segment(...)

2. UriBuilder.fromPath("").segment("{a}").build("a/b")
    should produce "a%2Fb"

I do not see any ambiguity here