As mention earlier here, Juneau serializers have sophisticated support for transforming relative URIs to absolute form.
The following example shows a REST method that returns a list of URIs of various forms:
| @Rest(
| uriAuthority="http://foo.com:123",
| uriContext="/myContext"
| )
| public class MyResource {
|
| @RestGet
| public URI[] getURIs() {
| return new URI[] {
| URI.create("http://www.apache.org/f1a"),
| URI.create("/f1b"),
| URI.create("/f1c/x/y"),
| URI.create("f1d"),
| URI.create("f1e/x/y"),
| URI.create(""),
| URI.create("context:/f2a/x"),
| URI.create("context:/f2b"),
| URI.create("context:/"),
| URI.create("context:/.."),
| URI.create("servlet:/f3a/x"),
| URI.create("servlet:/f3b"),
| URI.create("servlet:/"),
| URI.create("servlet:/.."),
| URI.create("request:/f4a/x"),
| URI.create("request:/f4b"),
| URI.create("request:/"),
| URI.create("request:/..")
| };
| }
| }
When requested as JSON, it produces the following result:
| {
| f1a:'http://www.apache.org/f1a',
| f1b:'http://foo.com:123/f1b',
| f1c:'http://foo.com:123/f1c/x/y',
| f1d:'http://foo.com:123/myContext/myServlet/f1d',
| f1e:'http://foo.com:123/myContext/myServlet/f1e/x/y',
| f1f:'http://foo.com:123/myContext/myServlet',
| f2a:'http://foo.com:123/myContext/f2a/x',
| f2b:'http://foo.com:123/myContext/f2b',
| f2c:'http://foo.com:123/myContext',
| f2d:'http://foo.com:123',
| f3a:'http://foo.com:123/myContext/myServlet/f3a/x',
| f3b:'http://foo.com:123/myContext/myServlet/f3b',
| f3c:'http://foo.com:123/myContext/myServlet',
| f3d:'http://foo.com:123/myContext',
| f4a:'http://foo.com:123/myContext/myServlet/myPath/f4a/x',
| f4b:'http://foo.com:123/myContext/myServlet/myPath/f4b',
| f4c:'http://foo.com:123/myContext/myServlet/myPath',
| f4d:'http://foo.com:123/myContext/myServlet'
| }
URI resolution is controlled by the following settings:
- {@link oajr.RestContext.Builder}
- {@link oajr.RestContext.Builder#uriAuthority(String) uriAuthority(String)}
- {@link oajr.RestContext.Builder#uriContext(String) uriContext(String)}
- {@link oajr.RestContext.Builder#uriRelativity(UriRelativity) uriRelativity(UriRelativity)}
- {@link oajr.RestContext.Builder#uriResolution(UriResolution) uriResolution(UriResolution)}
URIs are resolved by both regular and part serializers.