Is this the expected behavior of UriBuilder?

This is what I do (JAX-RS 1.0, Jersey 1.11):

import javax.ws.rs.core.UriBuilder; System.out.println(UriBuilder.fromPath("/").queryParam("x", "%40").build()); System.out.println(UriBuilder.fromPath("/").queryParam("x", "100%").build()); 

Expected:

 /?x=%2540 /?x=100%25 

But the actual conclusion:

 /?x=%40 /?x=100%25 

What's happening? What is a workaround, if so, how should UriBuilder ?

+4
source share
2 answers

I am surprised, but here is how it works:

 UriBuilder.fromUri("/").queryParam("x", "{value}").build(/* any text */); 
+2
source

The problem may be that there is an additional method for creating URIs from encoded strings:

From Javadocs: build (): "All characters"% "in string values ​​will be encoded. The state of the builder does not change"

buildFromEncoded (): "All% characters in string values ​​that are not followed by two hexadecimal numbers will be encoded."

URIBuilder.buildFromEncoded() : http://jsr311.java.net/nonav/javadoc/javax/ws/rs/core/UriBuilder.html#buildFromEncoded%28java.lang.Object...%29 ?

hope this helped

0
source

Source: https://habr.com/ru/post/1393294/


All Articles