javajakarta-eejersey

How to let UriBuilder build an URI with decoded hash character?


I try to generate following uri

//host:port/name/#/name/name

with jersey URI Builder. The Problem is that the uri builder decode the hash character.

Does anyone how to build the given URI?

Thats what I have:

final URI build = uriInfo.getBaseUriBuilder().path("..").path("#").path("/clients/asd/").build();

Solution

  • # is not a valid character in a URI path; # and what follows it is actually a URI fragment.

    What you need to do is therefore:

    final URI build = uriInfo.getBaseUriBuilder().path("..")
        .fragment("/clients/asd/").build();
    

    (note: I don't use Jersey, actually; I looked up the javadoc here, as I suppose this is the same)