Repository: incubator-juneau Updated Branches: refs/heads/master d28634b0f -> c4952d2cf
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/FileSpaceResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/FileSpaceResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/FileSpaceResource.java index 9cdd5f4..6a32824 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/FileSpaceResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/FileSpaceResource.java @@ -16,6 +16,7 @@ import static org.apache.juneau.dto.html5.HtmlBuilder.*; import javax.servlet.http.*; +import org.apache.juneau.*; import org.apache.juneau.annotation.*; import org.apache.juneau.html.*; import org.apache.juneau.html.annotation.*; @@ -31,7 +32,7 @@ import org.apache.juneau.serializer.*; path="/fileSpace", title="Available file space resource", description="Shows how to use HtmlRender class to customize HTML output.", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/EnhancedHtmlResource.java'}" + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/EnhancedHtmlResource.java'}" ) public class FileSpaceResource extends Resource { private static final long serialVersionUID = 1L; @@ -59,7 +60,7 @@ public class FileSpaceResource extends Resource { this.available = available; } - @Html(link="drive/{drive}") + @Html(link="servlet:/{drive}") public String getDrive() { return drive; } @@ -123,11 +124,11 @@ public class FileSpaceResource extends Resource { @Override public Object getContent(SerializerSession session, FileSpaceStatus value) { - String resourceUri = session.getUriContext().getRootRelativeServletPath(); + UriResolver r = session.getUriResolver(); switch (value) { - case OK: return img().src(resourceUri + "/htdocs/ok.png"); - case WARNING: return img().src(resourceUri + "/htdocs/warning.png"); - default: return img().src(resourceUri + "/htdocs/severe.png"); + case OK: return img().src(r.resolve("servlet:/htdocs/ok.png")); + case WARNING: return img().src(r.resolve("servlet:/htdocs/warning.png")); + default: return img().src(r.resolve("servlet:/htdocs/severe.png")); } } } @@ -138,7 +139,7 @@ public class FileSpaceResource extends Resource { return fileSpaces; } - @RestMethod(name="GET", path="drive/{drive}") + @RestMethod(name="GET", path="{drive}") public FileSpace getFileSpaceMetric(String drive) throws RestException { for (FileSpace fc : fileSpaces) if (fc.drive.equals(drive)) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java index 935989b..49e9a06 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/HelloWorldResource.java @@ -23,7 +23,7 @@ import org.apache.juneau.rest.annotation.*; title="Hello World sample resource", description="Simplest possible resource", path="/helloWorld", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/HelloWorldResource.java'}" + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/HelloWorldResource.java'}" ) public class HelloWorldResource extends Resource { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java index d4a6c90..9e71264 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/JsonSchemaResource.java @@ -24,7 +24,7 @@ import org.apache.juneau.rest.annotation.*; messages="nls/JsonSchemaResource", title="Sample JSON-Schema document", description="Sample resource that shows how to generate JSON-Schema documents", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/JsonSchemaResource.java'}" + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/JsonSchemaResource.java'}" ) public class JsonSchemaResource extends ResourceJena { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java index 4aad593..f396cd8 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/MethodExampleResource.java @@ -26,7 +26,7 @@ import org.apache.juneau.rest.annotation.Method; @RestResource( path="/methodExample", messages="nls/MethodExampleResource", - pageLinks="{up:'$R{servletParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/MethodExampleResource.java'}" + pageLinks="{up:'servlet:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/MethodExampleResource.java'}" ) public class MethodExampleResource extends Resource { private static final long serialVersionUID = 1L; @@ -53,7 +53,7 @@ public class MethodExampleResource extends Resource { @PathRemainder String remainder, // Path remainder after pattern match. @Header("Accept-Language") String lang, // Headers. @Header("Accept") String accept, - @Header("DNT") int doNotTrack + @Header("DNT") Integer doNotTrack ) { // Send back a simple String response http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java index c8745f3..f8875ff 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java @@ -13,7 +13,6 @@ package org.apache.juneau.examples.rest; import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; import java.awt.image.*; import java.io.*; @@ -39,11 +38,7 @@ import org.apache.juneau.serializer.*; messages="nls/PhotosResource", title="Photo REST service", description="Sample resource that allows images to be uploaded and retrieved.", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/PhotosResource.java'}", - properties={ - // Resolve all relative URIs so that they're relative to this servlet! - @Property(name=SERIALIZER_relativeUriBase, value="$R{servletURI}"), - } + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/PhotosResource.java'}" ) public class PhotosResource extends Resource { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java index be993bd..84c7d7a 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java @@ -31,7 +31,7 @@ import org.apache.juneau.transforms.*; path="/echo", title="Request echo service", description="Echos the current HttpServletRequest object back to the browser.", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/RequestEchoResource.java'}", + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/RequestEchoResource.java'}", properties={ @Property(name=SERIALIZER_maxDepth, value="5"), @Property(name=SERIALIZER_detectRecursions, value="true") http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java index b581e18..dd8da66 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SampleRemoteableServlet.java @@ -29,7 +29,7 @@ import org.apache.juneau.rest.remoteable.*; messages="nls/SampleRemoteableServlet", title="Remoteable Service Proxy API", description="Sample class showing how to use remoteable proxies. The list below are exposed services that can be retrieved using RestClient.getProxyInterface(Class).", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SampleRemoteableServlet.java'}", + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SampleRemoteableServlet.java'}", properties={ // Allow us to use method=POST from a browser. @Property(name=REST_allowMethodParam, value="*") http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java index a089afc..78ad06b 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SqlQueryResource.java @@ -35,7 +35,7 @@ import org.apache.juneau.rest.annotation.Body; messages="nls/SqlQueryResource", title="SQL query service", description="Executes queries against the local derby '$C{SqlQueryResource/connectionUrl}' database", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SqlQueryResource.java'}" + pageLinks="{up:'request:/..',options:'servlet:/..',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SqlQueryResource.java'}" ) public class SqlQueryResource extends Resource { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java index d49fd09..4b494ac 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/SystemPropertiesResource.java @@ -28,14 +28,30 @@ import org.apache.juneau.rest.annotation.Body; @RestResource( path="/systemProperties", + + // Title and description that show up on HTML rendition page. + // Also used in Swagger doc. title="System properties resource", description="REST interface for performing CRUD operations on system properties.", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',form:'formPage',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SystemPropertiesResource.java'}", + + // Links on the HTML rendition page. + // "request:/..." URIs are relative to the request URI. + // "servlet:/..." URIs are relative to the servlet URI. + // "$C{...}" variables are pulled from the config file. + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',form:'servlet:/formPage',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/SystemPropertiesResource.java'}", + + // Properties that get applied to all serializers and parsers. properties={ + // Use single quotes. @Property(name=SERIALIZER_quoteChar, value="'") }, + + // Our stylesheet for the HTML rendition. stylesheet="styles/devops.css", + + // Support GZIP encoding on Accept-Encoding header. encoders=GzipEncoder.class, + contact="{name:'John Smith',email:'[email protected]'}", license="{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'}", version="2.0", http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java index 7c6a448..e3ac5bd 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TempDirResource.java @@ -30,7 +30,7 @@ import org.apache.juneau.utils.*; path="/tempDir", title="Temp Directory View Service", description="View and download files in the '$S{java.io.tmpdir}' directory.", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',upload:'upload',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/TempDirResource.java'}", + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',upload:'servlet:/upload',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/TempDirResource.java'}", properties={ @Property(name="rootDir", value="$S{java.io.tmpdir}"), @Property(name="allowViews", value="true"), http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java index bd53404..62920fb 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/TumblrParserResource.java @@ -24,7 +24,7 @@ import org.apache.juneau.rest.client.*; messages="nls/TumblrParserResource", title="Tumblr parser service", description="Specify a URL to a Tumblr blog and parse the results.", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/TumblrParserResource.java'}" + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/TumblrParserResource.java'}" ) public class TumblrParserResource extends Resource { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java index ec13b5e..06541ab 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/UrlEncodedFormResource.java @@ -32,7 +32,7 @@ import org.apache.juneau.transforms.*; messages="nls/UrlEncodedFormResource", title="Tumblr parser service", description="Specify a URL to a Tumblr blog and parse the results.", - pageLinks="{up:'$R{requestParentURI}',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/UrlEncodedFormResource.java'}" + pageLinks="{up:'request:/..',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/UrlEncodedFormResource.java'}" ) public class UrlEncodedFormResource extends Resource { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java index 5fed44f..d228173 100644 --- a/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java +++ b/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java @@ -36,23 +36,48 @@ import org.apache.juneau.utils.*; /** * Proof-of-concept resource that shows off the capabilities of working with POJO resources. - * Consists of an in-memory address book repository. + * <p> + * Consists of an in-memory address book repository wrapped in a REST API. */ @RestResource( path="/addressBook", messages="nls/AddressBookResource", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java'}", + + // Links on the HTML rendition page. + // "request:/..." URIs are relative to the request URI. + // "servlet:/..." URIs are relative to the servlet URI. + // "$C{...}" variables are pulled from the config file. + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java'}", + + // Properties that get applied to all serializers and parsers. properties={ + + // Allow INIT as a method parameter. @Property(name=REST_allowMethodParam, value="*"), - @Property(name=HTML_uriAnchorText, value=TO_STRING), + + // Use single quotes. @Property(name=SERIALIZER_quoteChar, value="'"), + + // Make RDF/XML readable. @Property(name=RDF_rdfxml_tab, value="5"), + + // Make RDF parsable by adding a root node. @Property(name=RDF_addRootProperty, value="true"), - // Resolve all relative URIs so that they're relative to this servlet! - @Property(name=SERIALIZER_relativeUriBase, value="$R{servletURI}"), + + // Make URIs absolute so that we can easily reference them on the client side. + @Property(name=SERIALIZER_uriResolution, value="ABSOLUTE"), + + // Make the anchor text on URLs be just the path relative to the servlet. + @Property(name=HTML_uriAnchorText, value="SERVLET_RELATIVE") }, + + // Our stylesheet for the HTML rendition. stylesheet="styles/devops.css", + + // Support GZIP encoding on Accept-Encoding header. encoders=GzipEncoder.class, + + // Swagger info. contact="{name:'John Smith',email:'[email protected]'}", license="{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'}", version="2.0", @@ -71,7 +96,7 @@ public class AddressBookResource extends ResourceJena { try { // Create the address book - addressBook = new AddressBook(java.net.URI.create("")); + addressBook = new AddressBook(java.net.URI.create("servlet:/")); // Initialize it with some contents. addressBook.init(); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-microservice/src/main/java/org/apache/juneau/microservice/Resource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/src/main/java/org/apache/juneau/microservice/Resource.java b/juneau-microservice/src/main/java/org/apache/juneau/microservice/Resource.java index bd57ece..0e32ebe 100755 --- a/juneau-microservice/src/main/java/org/apache/juneau/microservice/Resource.java +++ b/juneau-microservice/src/main/java/org/apache/juneau/microservice/Resource.java @@ -12,8 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.microservice; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - import org.apache.juneau.rest.*; import org.apache.juneau.rest.annotation.*; import org.apache.juneau.svl.vars.*; @@ -39,9 +37,7 @@ import org.apache.juneau.svl.vars.*; */ @SuppressWarnings("serial") @RestResource( - properties={ - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}") - }, + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS'}", config="$S{juneau.configFile}", stylesheet="$C{REST/stylesheet,styles/juneau.css}" ) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceGroup.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceGroup.java b/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceGroup.java index e02234b..8c66669 100755 --- a/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceGroup.java +++ b/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceGroup.java @@ -38,7 +38,7 @@ import org.apache.juneau.svl.vars.*; */ @SuppressWarnings("serial") @RestResource( - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}", + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS'}", config="$S{juneau.configFile}", stylesheet="$C{REST/stylesheet,styles/juneau.css}" ) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceJena.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceJena.java b/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceJena.java index 2eafb12..4d971c9 100755 --- a/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceJena.java +++ b/juneau-microservice/src/main/java/org/apache/juneau/microservice/ResourceJena.java @@ -20,7 +20,7 @@ import org.apache.juneau.rest.jena.*; */ @SuppressWarnings("serial") @RestResource( - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}", + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS'}", config="$S{juneau.configFile}", stylesheet="$C{REST/stylesheet,styles/juneau.css}" ) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java b/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java index 3d60bb9..2b2c99c 100755 --- a/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java +++ b/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/ConfigResource.java @@ -33,7 +33,7 @@ import org.apache.juneau.rest.annotation.Body; path="/config", title="Configuration", description="Contents of configuration file.", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS',edit:'edit'}" + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS',edit:'servlet:/edit'}" ) public class ConfigResource extends Resource { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java b/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java index 556dd98..8f67665 100755 --- a/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java +++ b/juneau-microservice/src/main/java/org/apache/juneau/microservice/resources/DirectoryResource.java @@ -57,7 +57,7 @@ import org.apache.juneau.utils.*; title="File System Explorer", description="Contents of $R{attribute.path}", messages="nls/DirectoryResource", - pageLinks="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}", + pageLinks="{up:'request:/..',options:'servlet:/?method=OPTIONS'}", properties={ @Property(name=HTML_uriAnchorText, value=PROPERTY_NAME), @Property(name=REST_allowMethodParam, value="*"), http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java index 76bec4f..463920a 100644 --- a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java +++ b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClientBuilder.java @@ -978,25 +978,36 @@ public class RestClientBuilder extends CoreObjectBuilder { } /** - * Sets the {@link SerializerContext#SERIALIZER_relativeUriBase} property on all serializers in this group. + * Sets the {@link SerializerContext#SERIALIZER_uriContext} property on all serializers in this group. * * @param value The new value for this property. * @return This object (for method chaining). - * @see SerializerContext#SERIALIZER_relativeUriBase + * @see SerializerContext#SERIALIZER_uriContext */ - public RestClientBuilder relativeUriBase(String value) { - return property(SERIALIZER_relativeUriBase, value); + public RestClientBuilder uriContext(UriContext value) { + return property(SERIALIZER_uriContext, value); } /** - * Sets the {@link SerializerContext#SERIALIZER_absolutePathUriBase} property on all serializers in this group. + * Sets the {@link SerializerContext#SERIALIZER_uriResolution} property on all serializers in this group. * * @param value The new value for this property. * @return This object (for method chaining). - * @see SerializerContext#SERIALIZER_absolutePathUriBase + * @see SerializerContext#SERIALIZER_uriResolution */ - public RestClientBuilder absolutePathUriBase(String value) { - return property(SERIALIZER_absolutePathUriBase, value); + public RestClientBuilder uriResolution(UriResolution value) { + return property(SERIALIZER_uriResolution, value); + } + + /** + * Sets the {@link SerializerContext#SERIALIZER_uriRelativity} property on all serializers in this group. + * + * @param value The new value for this property. + * @return This object (for method chaining). + * @see SerializerContext#SERIALIZER_uriRelativity + */ + public RestClientBuilder uriRelativity(UriRelativity value) { + return property(SERIALIZER_uriRelativity, value); } /** http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java b/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java index 5f5cc6a..caf0894 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/CallMethod.java @@ -16,7 +16,6 @@ import static javax.servlet.http.HttpServletResponse.*; import static org.apache.juneau.dto.swagger.SwaggerBuilder.*; import static org.apache.juneau.rest.RestContext.*; import static org.apache.juneau.rest.annotation.Inherit.*; -import static org.apache.juneau.serializer.SerializerContext.*; import java.lang.annotation.*; import java.lang.reflect.*; @@ -801,11 +800,6 @@ class CallMethod implements Comparable<CallMethod> { if ("header".equals(prefix)) return req.getHeader(remainder); } - if (k.equals(SERIALIZER_absolutePathUriBase)) { - int serverPort = req.getServerPort(); - String serverName = req.getServerName(); - return req.getScheme() + "://" + serverName + (serverPort == 80 || serverPort == 443 ? "" : ":" + serverPort); - } if (k.equals(REST_servletPath)) return req.getServletPath(); if (k.equals(REST_servletURI)) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java index a04c95e..3df4fea 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestConfig.java @@ -13,7 +13,6 @@ package org.apache.juneau.rest; import static org.apache.juneau.internal.ArrayUtils.*; -import static org.apache.juneau.serializer.SerializerContext.*; import java.io.*; import java.util.*; @@ -68,7 +67,7 @@ import org.apache.juneau.svl.vars.*; * that contains a snapshot of these settings. If you call <code><jk>super</jk>.init(RestServletConfig)<code> before * you modify this config object, you won't see the changes! */ -@SuppressWarnings("hiding") +@SuppressWarnings({"hiding"}) public class RestConfig implements ServletConfig { final ServletConfig inner; @@ -152,14 +151,6 @@ public class RestConfig implements ServletConfig { varResolverBuilder.contextObject(ConfigFileVar.SESSION_config, configFile); vr = varResolverBuilder.build(); - // Add our servlet URI to our properties. - ServletContext ctx = config.getServletContext(); - String ctxPath = ctx.getContextPath(); - // Workaround for bug in Jetty that causes context path to always end in "null". - if (ctxPath.endsWith("null")) - ctxPath = ctxPath.substring(0, ctxPath.length()-4); - properties.put(SERIALIZER_relativeUriBase, ctxPath); - // Add the servlet init parameters to our properties. for (Enumeration<String> ep = config.getInitParameterNames(); ep.hasMoreElements();) { String p = ep.nextElement(); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java index 60ebda4..1fd1523 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestContext.java @@ -746,7 +746,7 @@ public final class RestContext extends Context { * properties={ * <ja>@Property</ja>( * name=<jsf>HTMLDOC_links</jsf>, - * value=<js>"{up:'$R{requestParentURI}', options:'?method=OPTIONS', editLevel:'editLevel?logger=$R{attribute.name}'}"</js> + * value=<js>"{up:'$R{requestParentURI}', options:'servlet:/?method=OPTIONS', editLevel:'servlet:/editLevel?logger=$R{attribute.name}'}"</js> * ) * } * ) http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java index fd141e7..5739ca1 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestRequest.java @@ -463,12 +463,23 @@ public final class RestRequest extends HttpServletRequestWrapper { public UriContext getUriContext() { if (uriContext == null) { String authority = StringUtils.getAuthorityUri(super.getRequestURL().toString()); - uriContext = new UriContext(UriResolution.ROOT_RELATIVE, UriRelativity.RESOURCE, authority, super.getContextPath(), super.getServletPath(), super.getPathInfo()); + uriContext = new UriContext(authority, super.getContextPath(), super.getServletPath(), super.getPathInfo()); } return uriContext; } /** + * Returns a URI resolver that can be used to convert URIs to absolute or root-relative form.. + * + * @param resolution The URI resolution rule. + * @param relativity The relative URI relativity rule. + * @return The URI resolver for this request. + */ + public UriResolver getUriResolver(UriResolution resolution, UriRelativity relativity) { + return new UriResolver(resolution, relativity, getUriContext()); + } + + /** * Same as {@link HttpServletRequest#getPathInfo()} except returns the path undecoded. * * @return The undecoded portion of the URL after the resource URL path pattern match. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java index fee53d0..91af182 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java @@ -808,7 +808,7 @@ public @interface RestResource { * <p class='bcode'> * <ja>@RestResource</ja>( * properties={ - * <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>) + * <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'request:/..',options:'servlet:/?method=OPTIONS'}"</js>) * } * ) * <jk>public class</jk> MyResource <jk>extends</jk> RestServletDefault { @@ -824,6 +824,8 @@ public @interface RestResource { * <p> * This field can contain variables (e.g. <js>"$L{my.localized.variable}"</js>). * <p> + * This field can also use URIs of any support type in {@link UriResolver}. + * <p> * The programmatic equivalent to this annotation are the {@link RestConfig#setPageLinks(String)}/{@link RestResponse#setPageLinks(Object)} methods. */ String pageLinks() default ""; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/c4952d2c/juneau-rest/src/main/java/org/apache/juneau/rest/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/package.html b/juneau-rest/src/main/java/org/apache/juneau/rest/package.html index 83ec8a4..c98377b 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/package.html +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/package.html @@ -226,7 +226,7 @@ */</jd> <ja>@RestResource</ja>( messages=<js>"nls/HelloWorldResource"</js>, - pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> + pageLinks=<js>"{up:'request:/..',options:'servlet:/?method=OPTIONS'}"</js> ) <jk>public class</jk> HelloWorldResource <jk>extends</jk> Resource { @@ -2172,7 +2172,7 @@ messages=<js>"nls/UrlEncodedFormResource"</js>, title=<js>"URL-encoded Form Post Resource"</js>, description=<js>"Shows how form posts are converted into beans."</js>, - pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js> + pageLinks=<js>"{up:'request:/..',options:'servlet:/?method=OPTIONS'}"</js> ) <jk>public class</jk> UrlEncodedFormResource <jk>extends</jk> Resource { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -3076,15 +3076,6 @@ <li>Subclasses can use either {@link javax.servlet.http.HttpServlet#init(ServletConfig)} or {@link javax.servlet.http.HttpServlet#init()} for initialization just like any other servlet. - <li>The {@link org.apache.juneau.serializer.SerializerContext#SERIALIZER_relativeUriBase} property is automatically - set to the context root (e.g. <l>"/mycontextroot"</l>) of the web application during servlet initialization. - This value can be overridden through the {@link org.apache.juneau.rest.annotation.RestResource#properties() @RestResource.properties()} - or {@link org.apache.juneau.rest.annotation.RestMethod#properties() @RestMethod.properties()} annotations, or through - {@link org.apache.juneau.rest.RestResponse#setProperty(String, Object)}. - <li>The {@link org.apache.juneau.serializer.SerializerContext#SERIALIZER_absolutePathUriBase} property is automatically - set to the HTTP authority (e.g. <l>"https://myhost:9443"</l>) during each request. - This value can be overridden through the {@link org.apache.juneau.rest.annotation.RestMethod#properties() @RestMethod.properties()} annotations, - or through {@link org.apache.juneau.rest.RestResponse#setProperty(String, Object)}. <li>The <l>X-Response-Headers</l> header can be used to pass through header values into the response. The value should be a URL-encoded map of key-value pairs. For example, to add a <l>"Refresh: 1"</l> header to the response to auto-refresh a page, the following parameter @@ -3217,17 +3208,48 @@ <ja>@RestResource</ja>( path=<js>"/addressBook"</js>, messages=<js>"nls/AddressBookResource"</js>, - pageLinks=<js>"{up:'$R{requestParentURI}',options:'?method=OPTIONS'}"</js>, - properties={ - <ja>@Property</ja>(name=<jsf>REST_allowMethodParam</jsf>, value=<js>"*"</js>), - <ja>@Property</ja>(name=<jsf>HTML_uriAnchorText</jsf>, value=<jsf>TO_STRING</jsf>), - <ja>@Property</ja>(name=<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), - <ja>@Property</ja>(name=<jsf>RDF_rdfxml_tab</jsf>, value=<js>"5"</js>), - <ja>@Property</ja>(name=<jsf>RDF_addRootProperty</jsf>, value=<js>"true"</js>), - <jc>// Resolve all relative URIs so that they're relative to this servlet!</jc> - <ja>@Property</ja>(name=<jsf>SERIALIZER_relativeUriBase</jsf>, value=<js>"$R{servletURI}"</js>), - }, - encoders=GzipEncoder.<jk>class</jk> + + <jc>// Links on the HTML rendition page. + // "request:/..." URIs are relative to the request URI. + // "servlet:/..." URIs are relative to the servlet URI. + // "$C{...}" variables are pulled from the config file.</jc> + pageLinks=<js>"{up:'request:/..', options:'servlet:/?method=OPTIONS', source:'$C{Source/gitHub}/org/apache/juneau/examples/rest/addressbook/AddressBookResource.java'}"</js>, + + <jc>// Properties that get applied to all serializers and parsers.</jc> + properties={ + + <jc>// Allow INIT as a method parameter.</jc> + <ja>@Property</ja>(name=<jsf>REST_allowMethodParam</jsf>, value=<js>"*"</js>), + + <jc>// Use single quotes.</jc> + <ja>@Property</ja>(name=<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), + + <jc>// Make RDF/XML readable.</jc> + <ja>@Property</ja>(name=<jsf>RDF_rdfxml_tab</jsf>, value=<js>"5"</js>), + + <jc>// Make RDF parsable by adding a root node.</jc> + <ja>@Property</ja>(name=<jsf>RDF_addRootProperty</jsf>, value=<js>"true"</js>), + + <jc>// Make URIs absolute so that we can easily reference them on the client side.</jc> + <ja>@Property</ja>(name=<jsf>SERIALIZER_uriResolution</jsf>, value=<js>"ABSOLUTE"</js>) + + <jc>// Make the anchor text on URLs be just the path relative to the servlet.</jc> + <ja>@Property</ja>(name=<jsf>HTML_uriAnchorText</jsf>, value=<js>"SERVLET_RELATIVE"</js>) + }, + + <jc>// Our stylesheet for the HTML rendition.</jc> + stylesheet=<js>"styles/devops.css"</js>, + + <jc>// Support GZIP encoding on Accept-Encoding header.</jc> + encoders=GzipEncoder.<jk>class</jk>, + + <jc>// Swagger info.</jc> + contact=<js>"{name:'John Smith',email:'[email protected]'}"</js>, + license=<js>"{name:'Apache 2.0',url:'http://www.apache.org/licenses/LICENSE-2.0.html'}"</js>, + version=<js>"2.0"</js>, + termsOfService=<js>"You're on your own."</js>, + tags=<js>"[{name:'Java',description:'Java utility',externalDocs:{description:'Home page',url:'http://juneau.apache.org'}}]"</js>, + externalDocs=<js>"{description:'Home page',url:'http://juneau.apache.org'}"</js> ) <jk>public class</jk> AddressBookResource <jk>extends</jk> ResourceJena { <jk>private static final long</jk> <jsf>serialVersionUID</jsf> = 1L; @@ -3240,7 +3262,7 @@ <jk>try</jk> { <jc>// Create the address book</jc> - <jf>addressBook</jf> = <jk>new</jk> AddressBook(java.net.URI.create(<js>""</js>)); + <jf>addressBook</jf> = <jk>new</jk> AddressBook(java.net.URI.create(<js>"servlet:/"</js>)); <jc>// Add some people to our address book by default</jc> <jf>addressBook</jf>.createPerson(
