Repository: incubator-juneau Updated Branches: refs/heads/master 26e67a40f -> d08110b10
Bug fixes. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/d08110b1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/d08110b1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/d08110b1 Branch: refs/heads/master Commit: d08110b10174a08562c6c43c55ad410f88c05b80 Parents: 26e67a4 Author: JamesBognar <[email protected]> Authored: Sat Jun 10 17:22:59 2017 -0400 Committer: JamesBognar <[email protected]> Committed: Sat Jun 10 17:22:59 2017 -0400 ---------------------------------------------------------------------- .../examples/rest/SystemPropertiesResource.java | 2 +- .../juneau/examples/rest/TempDirResource.java | 4 +- .../java/org/apache/juneau/rest/Redirect.java | 47 +++++++++----------- .../juneau/rest/labels/ResourceDescription.java | 1 + .../juneau/rest/response/RedirectHandler.java | 11 +---- 5 files changed, 27 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d08110b1/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 8cb01e5..1adb401 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 @@ -195,7 +195,7 @@ public class SystemPropertiesResource extends Resource { ) ) public Form getFormPage() { - return form().method("POST").action("formPagePost").children( + return form().method("POST").action("servlet:/formPagePost").children( h4("Set system property"), "Name: ", input("text").name("name"), br(), "Value: ", input("text").name("value"), br(), br(), http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d08110b1/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 f6f949d..672fd69 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 @@ -53,9 +53,9 @@ public class TempDirResource extends DirectoryResource { * [GET /upload] - Display the form entry page for uploading a file to the temp directory. */ @RestMethod(name="GET", path="/upload") - public Form getUploadForm(RestRequest req) { + public Form getUploadForm() { return - form().id("form").action(req.getServletURI() + "/upload").method("POST").enctype("multipart/form-data") + form().id("form").action("servlet:/upload").method("POST").enctype("multipart/form-data") .children( input().name("contents").type("file"), button("submit", "Submit") http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d08110b1/juneau-rest/src/main/java/org/apache/juneau/rest/Redirect.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/Redirect.java b/juneau-rest/src/main/java/org/apache/juneau/rest/Redirect.java index dfff199..e4d7f83 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/Redirect.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/Redirect.java @@ -15,7 +15,7 @@ package org.apache.juneau.rest; import java.net.*; import java.text.*; -import org.apache.juneau.serializer.*; +import org.apache.juneau.internal.*; import org.apache.juneau.urlencoding.*; /** @@ -67,14 +67,13 @@ import org.apache.juneau.urlencoding.*; public final class Redirect { private final int httpResponseCode; - private final String url; - private final Object[] args; + private final URI uri; /** * Redirect to the specified URL. * Relative paths are interpreted as relative to the servlet path. * - * @param url The URL to redirect to. + * @param uri The URL to redirect to. * <br>Can be any of the following: * <ul> * <li><code>URL</code> @@ -83,15 +82,15 @@ public final class Redirect { * </ul> * @param args Optional {@link MessageFormat}-style arguments. */ - public Redirect(Object url, Object...args) { - this(0, url, args); + public Redirect(Object uri, Object...args) { + this(0, uri, args); } /** * Convenience method for redirecting to instance of {@link URL} and {@link URI}. * Same as calling <code>toString()</code> on the object and using the other constructor. * - * @param url The URL to redirect to. + * @param uri The URL to redirect to. * <br>Can be any of the following: * <ul> * <li><code>URL</code> @@ -99,8 +98,8 @@ public final class Redirect { * <li><code>CharSequence</code> * </ul> */ - public Redirect(Object url) { - this(0, url, (Object[])null); + public Redirect(Object uri) { + this(0, uri, (Object[])null); } /** @@ -119,8 +118,12 @@ public final class Redirect { */ public Redirect(int httpResponseCode, Object url, Object...args) { this.httpResponseCode = httpResponseCode; - this.url = (url == null ? null : url.toString()); - this.args = args; + if (url == null) + url = ""; + if (args != null && args.length > 0) + this.uri = StringUtils.toURI(MessageFormat.format(url.toString(), args)); + else + this.uri = StringUtils.toURI(url); } /** @@ -131,26 +134,20 @@ public final class Redirect { } /** - * Calculates the URL to redirect to. + * Returns the response code passed in through the constructor. * - * @param s Use this serializer to encode arguments using the {@link UrlEncodingSerializer#serialize(PartType,Object)} method. - * @return The URL to redirect to. + * @return The response code passed in through the constructor, or <code>0</code> if response code wasn't specified. */ - public String toUrl(UrlEncodingSerializer s) { - if (url != null && args != null && args.length > 0) { - for (int i = 0; i < args.length; i++) - args[i] = s.serialize(PartType.PATH, args[i]); - return MessageFormat.format(url, args); - } - return url; + public int getHttpResponseCode() { + return httpResponseCode; } /** - * Returns the response code passed in through the constructor. + * Returns the URI to redirect to. * - * @return The response code passed in through the constructor, or <code>0</code> if response code wasn't specified. + * @return The URI to redirect to. */ - public int getHttpResponseCode() { - return httpResponseCode; + public URI getURI() { + return uri; } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d08110b1/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java index 3f642e4..994c3fb 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ResourceDescription.java @@ -60,6 +60,7 @@ public final class ResourceDescription extends NameDescription implements Compar return urlDecode(childPath.indexOf('/') == -1 ? childPath : childPath.substring(childPath.lastIndexOf('/')+1)); } + // TODO private static String calcHref(RestRequest req, String childPath) { return req.getServletURIBuilder().append('/').append(childPath).toString(); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d08110b1/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java index 0463e0e..7a22761 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java @@ -12,8 +12,6 @@ // *************************************************************************************************************************** package org.apache.juneau.rest.response; -import static org.apache.juneau.internal.StringUtils.*; - import java.io.*; import org.apache.juneau.rest.*; @@ -27,14 +25,7 @@ public final class RedirectHandler implements ResponseHandler { public boolean handle(RestRequest req, RestResponse res, Object output) throws IOException, RestException { if (output instanceof Redirect) { Redirect r = (Redirect)output; - String uri = r.toUrl(res.getUrlEncodingSerializer()); - if (isEmpty(uri)) - uri = req.getServletURI(); - else { - char c = (uri.length() > 0 ? uri.charAt(0) : 0); - if (c != '/' && uri.indexOf("://") == -1) - uri = req.getServletURIBuilder().append('/').append(uri).toString(); - } + String uri = req.getUriResolver().resolve(r.getURI()); int rc = r.getHttpResponseCode(); if (rc != 0) res.setStatus(rc); // TODO - This may get ignored by the call below.
