Jersey UriBuilder can replace all the templates in a URI:
UriBuilder.fromResource(this.getClass()).path("{id}/{op}").build(12, "buy")
On the client side, it is exactly what we want ; On the server side, in some cases, we want to keep some templates unchanged (to inform the client that the URI depends on it, that it will have to fill it with values).
Building a URI without giving all template throws an exception. So, is there another way to leave some template unchanged?
UriBuilder(String, String, Int32, String, String) Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, path, and query string or fragment identifier. UriBuilder(Uri) Initializes a new instance of the UriBuilder class with the specified Uri instance.
A URI template is a URI-like String that contains variables enclosed by braces ( { , } ), which can be expanded to produce an actual URI. See expand(Map) , expand(Object[]) , and match(String) for example usages. Static inner class to parse URI template strings into a matching regular expression.
public abstract class UriBuilder extends Object. URI template-aware utility class for building URIs from their components.
I believe the proper way to do this is to call #toTemplate. This creates a template string. I believe that a URI that has unresolved template parameters is not valid. Here's an example:
UriBuilder.fromResource(this.getClass()).path("{id}/{op}").toTemplate();
This will preserve the template place holders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With