Repository: incubator-juneau Updated Branches: refs/heads/master d9e2e24d9 -> 0a00ed8a0
Add name() annotation attribute to RestServlet method annotations. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/0a00ed8a Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/0a00ed8a Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/0a00ed8a Branch: refs/heads/master Commit: 0a00ed8a02049480fa5f74a19d354543955936ab Parents: d9e2e24 Author: JamesBognar <[email protected]> Authored: Sun Jun 11 13:38:46 2017 -0400 Committer: JamesBognar <[email protected]> Committed: Sun Jun 11 13:38:46 2017 -0400 ---------------------------------------------------------------------- .../java/org/apache/juneau/internal/StringUtils.java | 13 +++++++++++++ juneau-core/src/main/javadoc/overview.html | 9 +++++++++ .../main/java/org/apache/juneau/rest/CallMethod.java | 7 ++++--- .../main/java/org/apache/juneau/rest/RestContext.java | 6 +++--- .../java/org/apache/juneau/rest/RestParamDefaults.java | 11 ++++++----- .../org/apache/juneau/rest/RestServletDefault.java | 2 +- .../org/apache/juneau/rest/annotation/FormData.java | 11 +++++++++-- .../org/apache/juneau/rest/annotation/HasFormData.java | 11 +++++++++-- .../org/apache/juneau/rest/annotation/HasQuery.java | 11 +++++++++-- .../java/org/apache/juneau/rest/annotation/Header.java | 9 ++++++++- .../java/org/apache/juneau/rest/annotation/Path.java | 9 ++++++++- .../java/org/apache/juneau/rest/annotation/Query.java | 11 +++++++++-- 12 files changed, 88 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-core/src/main/java/org/apache/juneau/internal/StringUtils.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/internal/StringUtils.java b/juneau-core/src/main/java/org/apache/juneau/internal/StringUtils.java index 61bacb0..22b444b 100644 --- a/juneau-core/src/main/java/org/apache/juneau/internal/StringUtils.java +++ b/juneau-core/src/main/java/org/apache/juneau/internal/StringUtils.java @@ -1512,4 +1512,17 @@ public final class StringUtils { throw new RuntimeException(e); } } + + /** + * Returns the first non-null, non-empty string in the list. + * + * @param s The strings to test. + * @return The first non-empty string in the list, or <jk>null</jk> if they were all <jk>null</jk> or empty. + */ + public static String firstNonEmpty(String...s) { + for (String ss : s) + if (! isEmpty(ss)) + return ss; + return null; + } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-core/src/main/javadoc/overview.html ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/javadoc/overview.html b/juneau-core/src/main/javadoc/overview.html index 68386e1..458a70f 100644 --- a/juneau-core/src/main/javadoc/overview.html +++ b/juneau-core/src/main/javadoc/overview.html @@ -6498,6 +6498,15 @@ <li><code>devops.css</code> cleaned up. <li>Removed a bunch of URL-related methods from {@link org.apache.juneau.rest.RestRequest}. These all have equivalents in {@link org.apache.juneau.rest.RestRequest#getUriContext()}. + <li>New annotation attributes: + <ul> + <li>{@link org.apache.juneau.rest.annotation.Query#name() @Query.name()} + <li>{@link org.apache.juneau.rest.annotation.FormData#name() @FormData.name()} + <li>{@link org.apache.juneau.rest.annotation.Header#name() @Header.name()} + <li>{@link org.apache.juneau.rest.annotation.Path#name() @Path.name()} + <li>{@link org.apache.juneau.rest.annotation.HasQuery#name() @HasQuery.name()} + <li>{@link org.apache.juneau.rest.annotation.HasFormData#name() @HasFormData.name()} + </ul> </ul> <h6 class='topic'>org.apache.juneau.rest.client</h6> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/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 0a9ad22..aae0586 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,6 +16,7 @@ import static javax.servlet.http.HttpServletResponse.*; import static org.apache.juneau.dto.swagger.SwaggerBuilder.*; import static org.apache.juneau.html.HtmlDocSerializerContext.*; import static org.apache.juneau.internal.ClassUtils.*; +import static org.apache.juneau.internal.StringUtils.*; import static org.apache.juneau.internal.Utils.*; import static org.apache.juneau.rest.RestContext.*; import static org.apache.juneau.rest.annotation.Inherit.*; @@ -331,15 +332,15 @@ class CallMethod implements Comparable<CallMethod> { if (a instanceof Header) { Header h = (Header)a; if (! h.def().isEmpty()) - defaultRequestHeaders.put(h.value(), h.def()); + defaultRequestHeaders.put(firstNonEmpty(h.name(), h.value()), h.def()); } else if (a instanceof Query) { Query q = (Query)a; if (! q.def().isEmpty()) - defaultQuery.put(q.value(), q.def()); + defaultQuery.put(firstNonEmpty(q.name(), q.value()), q.def()); } else if (a instanceof FormData) { FormData f = (FormData)a; if (! f.def().isEmpty()) - defaultFormData.put(f.value(), f.def()); + defaultFormData.put(firstNonEmpty(f.name(), f.value()), f.def()); } } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/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 2422599..feadcdc 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 @@ -1493,9 +1493,9 @@ public final class RestContext extends Context { if (a instanceof Path) p = (Path)a; - String name = (p == null ? "" : p.value()); + String name = (p == null ? "" : firstNonEmpty(p.name(), p.value())); - if (name.isEmpty()) { + if (isEmpty(name)) { int idx = attrIndex++; String[] vars = pathPattern.getVars(); if (vars.length <= idx) @@ -1507,7 +1507,7 @@ public final class RestContext extends Context { if (isNumeric(vars[j]) && vars[j].equals(idxs)) name = vars[j]; - if (name.isEmpty()) + if (isEmpty(name)) name = pathPattern.getVars()[idx]; } rp[i] = new RestParamDefaults.PathParameterObject(name, t); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java index dafc17e..03f4239 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestParamDefaults.java @@ -12,6 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.rest; +import static org.apache.juneau.internal.StringUtils.*; import static org.apache.juneau.rest.RestParamType.*; import java.io.*; @@ -559,7 +560,7 @@ class RestParamDefaults { static final class HeaderObject extends RestParam { protected HeaderObject(Header a, Type type) { - super(HEADER, a.value(), type); + super(HEADER, firstNonEmpty(a.name(), a.value()), type); } @Override /* RestParam */ @@ -586,7 +587,7 @@ class RestParamDefaults { private final boolean multiPart, plainParams; protected FormDataObject(Method method, FormData a, Type type, boolean methodPlainParams) throws ServletException { - super(FORMDATA, a.value(), type); + super(FORMDATA, firstNonEmpty(a.name(), a.value()), type); if (a.multipart() && ! isCollection(type)) throw new RestServletException("Use of multipart flag on @FormData parameter that's not an array or Collection on method ''{0}''", method); this.multiPart = a.multipart(); @@ -608,7 +609,7 @@ class RestParamDefaults { private final boolean multiPart, plainParams; protected QueryObject(Method method, Query a, Type type, boolean methodPlainParams) throws ServletException { - super(QUERY, a.value(), type); + super(QUERY, firstNonEmpty(a.name(), a.value()), type); if (a.multipart() && ! isCollection(type)) throw new RestServletException("Use of multipart flag on @Query parameter that's not an array or Collection on method ''{0}''", method); this.multiPart = a.multipart(); @@ -629,7 +630,7 @@ class RestParamDefaults { static final class HasFormDataObject extends RestParam { protected HasFormDataObject(Method method, HasFormData a, Type type) throws ServletException { - super(FORMDATA, a.value(), type); + super(FORMDATA, firstNonEmpty(a.name(), a.value()), type); if (type != Boolean.class && type != boolean.class) throw new RestServletException("Use of @HasForm annotation on parameter that is not a boolean on method ''{0}''", method); } @@ -644,7 +645,7 @@ class RestParamDefaults { static final class HasQueryObject extends RestParam { protected HasQueryObject(Method method, HasQuery a, Type type) throws ServletException { - super(QUERY, a.value(), type); + super(QUERY, firstNonEmpty(a.name(), a.value()), type); if (type != Boolean.class && type != boolean.class) throw new RestServletException("Use of @HasQuery annotation on parameter that is not a boolean on method ''{0}''", method); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java index c2c0d29..fe3450c 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java @@ -184,7 +184,7 @@ import org.apache.juneau.xml.*; }, stylesheet="styles/juneau.css", htmldoc=@HtmlDoc( - branding="<img src='$U{servlet:/htdocs/juneau.png}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'>" + branding="<a href='http://juneau.apache.org'><img src='$U{servlet:/htdocs/juneau.png}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'></a>" ), favicon="htdocs/juneau.png", staticFiles="{htdocs:'htdocs'}" http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java index bc453aa..56187b0 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java @@ -60,9 +60,16 @@ import org.apache.juneau.rest.*; public @interface FormData { /** - * URL parameter name. + * FORM parameter name. */ - String value(); + String name() default ""; + + /** + * A synonym for {@link #name()}. + * <p> + * Allows you to use shortened notation if you're only specifying the name. + */ + String value() default ""; /** * Specify <jk>true</jk> if using multi-part parameters to represent collections and arrays. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasFormData.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasFormData.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasFormData.java index 085d7e9..a68030a 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasFormData.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasFormData.java @@ -88,7 +88,14 @@ import org.apache.juneau.rest.*; public @interface HasFormData { /** - * URL parameter name. + * FORM parameter name. */ - String value(); + String name() default ""; + + /** + * A synonym for {@link #name()}. + * <p> + * Allows you to use shortened notation if you're only specifying the name. + */ + String value() default ""; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasQuery.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasQuery.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasQuery.java index 19f4469..f1bf5ee 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasQuery.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/HasQuery.java @@ -53,7 +53,14 @@ import org.apache.juneau.rest.*; public @interface HasQuery { /** - * URL parameter name. + * URL query parameter name. */ - String value(); + String name() default ""; + + /** + * A synonym for {@link #name()}. + * <p> + * Allows you to use shortened notation if you're only specifying the name. + */ + String value() default ""; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Header.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Header.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Header.java index 876fbf3..8f98d50 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Header.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Header.java @@ -48,7 +48,14 @@ public @interface Header { /** * HTTP header name. */ - String value(); + String name() default ""; + + /** + * A synonym for {@link #name()}. + * <p> + * Allows you to use shortened notation if you're only specifying the name. + */ + String value() default ""; /** * The default value for this header if it's not present in the request. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Path.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Path.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Path.java index d3c5c89..5385109 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Path.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Path.java @@ -73,9 +73,16 @@ import java.lang.annotation.*; public @interface Path { /** - * URL variable name. + * URL path variable name. * <p> * Optional if the attributes are specified in the same order as in the URL path pattern. */ + String name() default ""; + + /** + * A synonym for {@link #name()}. + * <p> + * Allows you to use shortened notation if you're only specifying the name. + */ String value() default ""; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/0a00ed8a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java index d8e3414..cf952a6 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java @@ -56,9 +56,16 @@ import org.apache.juneau.rest.*; public @interface Query { /** - * URL parameter name. + * URL query parameter name. */ - String value(); + String name() default ""; + + /** + * A synonym for {@link #name()}. + * <p> + * Allows you to use shortened notation if you're only specifying the name. + */ + String value() default ""; /** * Specify <jk>true</jk> if using multi-part parameters to represent collections and arrays.
