Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaving some {template} in builder URI with UriBuilder

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?

like image 907
yves amsellem Avatar asked May 28 '11 09:05

yves amsellem


People also ask

What is UriBuilder in c#?

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.

What is URI Template variable?

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.

What is UriBuilder in Java?

public abstract class UriBuilder extends Object. URI template-aware utility class for building URIs from their components.


1 Answers

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.

like image 176
robert_difalco Avatar answered Sep 28 '22 11:09

robert_difalco