You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2018/01/19 15:28:16 UTC
juneau git commit: Remove @Messages and @Properties.
Repository: juneau
Updated Branches:
refs/heads/master af355372e -> 07f39bb7c
Remove @Messages and @Properties.
Project: http://git-wip-us.apache.org/repos/asf/juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/juneau/commit/07f39bb7
Tree: http://git-wip-us.apache.org/repos/asf/juneau/tree/07f39bb7
Diff: http://git-wip-us.apache.org/repos/asf/juneau/diff/07f39bb7
Branch: refs/heads/master
Commit: 07f39bb7cb653bd74b064bd40cc0e770c4176920
Parents: af35537
Author: JamesBognar <ja...@apache.org>
Authored: Fri Jan 19 10:28:11 2018 -0500
Committer: JamesBognar <ja...@apache.org>
Committed: Fri Jan 19 10:28:11 2018 -0500
----------------------------------------------------------------------
juneau-doc/src/main/javadoc/overview.html | 13 +-
.../juneau/examples/rest/DirectoryResource.java | 3 +-
.../examples/rest/RequestEchoResource.java | 2 +-
.../microservice/resources/LogsResource.java | 5 +-
.../juneau/rest/test/InheritanceResource.java | 5 +-
.../juneau/rest/test/MessagesResource.java | 2 +-
.../apache/juneau/rest/test/NlsResource.java | 2 +-
.../juneau/rest/test/OnPostCallResource.java | 3 +-
.../juneau/rest/test/OnPreCallResource.java | 2 +-
.../apache/juneau/rest/RequestProperties.java | 24 +++
.../org/apache/juneau/rest/RestContext.java | 171 +++++++++++++++----
.../apache/juneau/rest/RestParamDefaults.java | 7 +-
.../org/apache/juneau/rest/RestRequest.java | 8 +
.../apache/juneau/rest/annotation/Messages.java | 51 ------
.../juneau/rest/annotation/Properties.java | 67 --------
.../juneau/rest/annotation/RestResource.java | 2 +-
.../java/org/apache/juneau/rest/package.html | 77 ++++-----
17 files changed, 221 insertions(+), 223 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-doc/src/main/javadoc/overview.html
----------------------------------------------------------------------
diff --git a/juneau-doc/src/main/javadoc/overview.html b/juneau-doc/src/main/javadoc/overview.html
index fee50e3..7cb929b 100644
--- a/juneau-doc/src/main/javadoc/overview.html
+++ b/juneau-doc/src/main/javadoc/overview.html
@@ -6373,8 +6373,8 @@
and {@link org.apache.juneau.rest.annotation.RestResource#pojoSwaps() @RestResource.pojoSwaps()}
annotations to set serializer transforms.
<li>
- Using the {@link org.apache.juneau.rest.annotation.Properties @Properties} annotation to set
- serializers properties programmatically on a request.
+ Simply passing in an {@link org.apache.juneau.ObjectMap} parameter on the Java method.
+ <br>This object map contains the modifiable properties on the request.
</ul>
<p>
The class is shown below:
@@ -6411,7 +6411,7 @@
<jd>/** GET request handler */</jd>
<ja>@RestMethod</ja>(name=<jsf>GET</jsf>, path=<js>"/*"</js>, converters={Queryable.<jk>class</jk>,Traversable.<jk>class</jk>})
- <jk>public</jk> HttpServletRequest doGet(RestRequest req, RestResponse res, <ja>@Properties</ja> ObjectMap properties) {
+ <jk>public</jk> HttpServletRequest doGet(RestRequest req, RestResponse res, ObjectMap properties) {
<jc>// Set the HtmlDocSerializer title programmatically.</jc>
res.setPageTitle(req.getPathInfo());
@@ -9362,6 +9362,11 @@
{@link org.apache.juneau.rest.RestLoggerDefault} and {@link org.apache.juneau.rest.RestLoggerNoOp}
<li>
<code>RestResourceResolverSimple</code> renamed to {@link org.apache.juneau.rest.RestResourceResolverDefault}
+ <li>
+ Eliminated the <code>@Messages</code> and <code>@Properties</code> REST java method parameter
+ annotations.
+ <br>These aren't needed anymore since you can just pass in <code>MessageBundle</code> and
+ <code>ObjectMap</code> as unannotated parameters.
</ul>
<h6 class='topic'>juneau-rest-client</h6>
@@ -13557,7 +13562,7 @@
</p>
<ul class='spaced-list'>
<li>
- New {@link org.apache.juneau.rest.annotation.Properties @Properties} REST method parameter annotation that can be used to get the runtime properties map through a parameter instead of through {@link org.apache.juneau.rest.RestResponse}.
+ New <code><del>@Properties</del></code> REST method parameter annotation that can be used to get the runtime properties map through a parameter instead of through {@link org.apache.juneau.rest.RestResponse}.
</li>
</ul>
</div>
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java
----------------------------------------------------------------------
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java
index fc16748..2d609a3 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/DirectoryResource.java
@@ -27,7 +27,6 @@ import org.apache.juneau.*;
import org.apache.juneau.microservice.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.annotation.Properties;
import org.apache.juneau.rest.converters.*;
import org.apache.juneau.rest.widget.*;
import org.apache.juneau.utils.*;
@@ -91,7 +90,7 @@ public class DirectoryResource extends Resource {
/** GET request handler */
@RestMethod(name=GET, path="/*", converters={Queryable.class})
- public Object doGet(RestRequest req, @Properties ObjectMap properties) throws Exception {
+ public Object doGet(RestRequest req, ObjectMap properties) throws Exception {
String pathInfo = req.getPathInfo();
File f = pathInfo == null ? rootDir : new File(rootDir.getAbsolutePath() + pathInfo);
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java
----------------------------------------------------------------------
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java
index 716a7ff..5974d96 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/RequestEchoResource.java
@@ -70,7 +70,7 @@ public class RequestEchoResource extends Resource {
/** GET request handler */
@RestMethod(name="*", path="/*", converters={Traversable.class,Queryable.class}, summary="Serializes the incoming HttpServletRequest object.")
- public HttpServletRequest doGet(RestRequest req, RestResponse res, @Properties ObjectMap properties) {
+ public HttpServletRequest doGet(RestRequest req, RestResponse res, ObjectMap properties) {
// Just echo the request back as the response.
return req;
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
index 173872b..e1d5f59 100755
--- a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
+++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/resources/LogsResource.java
@@ -30,7 +30,6 @@ import org.apache.juneau.ini.*;
import org.apache.juneau.microservice.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.annotation.Properties;
import org.apache.juneau.rest.converters.*;
import org.apache.juneau.transforms.*;
@@ -99,7 +98,7 @@ public class LogsResource extends Resource {
responses={@Response(200),@Response(404)}
)
)
- public Object getFileOrDirectory(RestRequest req, RestResponse res, @Properties ObjectMap properties, @PathRemainder String path) throws Exception {
+ public Object getFileOrDirectory(RestRequest req, RestResponse res, ObjectMap properties, @PathRemainder String path) throws Exception {
File f = getFile(path);
@@ -141,7 +140,7 @@ public class LogsResource extends Resource {
)
)
@SuppressWarnings("nls")
- public void viewFile(RestRequest req, RestResponse res, @PathRemainder String path, @Properties ObjectMap properties, @Query("highlight") boolean highlight, @Query("start") String start, @Query("end") String end, @Query("thread") String thread, @Query("loggers") String[] loggers, @Query("severity") String[] severity) throws Exception {
+ public void viewFile(RestRequest req, RestResponse res, @PathRemainder String path, ObjectMap properties, @Query("highlight") boolean highlight, @Query("start") String start, @Query("end") String end, @Query("thread") String thread, @Query("loggers") String[] loggers, @Query("severity") String[] severity) throws Exception {
File f = getFile(path);
if (f.isDirectory())
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java
index fd7d224..83ba10c 100644
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java
+++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/InheritanceResource.java
@@ -23,7 +23,6 @@ import org.apache.juneau.json.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.annotation.Properties;
import org.apache.juneau.serializer.*;
import org.apache.juneau.transform.*;
@@ -191,7 +190,7 @@ public class InheritanceResource extends RestServlet {
// Should show {p1:'v1',p2:'v2a',p3:'v3',p4:'v4'}
@RestMethod(name=GET, path="/test1")
- public ObjectMap test1(@Properties ObjectMap properties) {
+ public ObjectMap test1(ObjectMap properties) {
return transform(properties);
}
@@ -199,7 +198,7 @@ public class InheritanceResource extends RestServlet {
// Should show {p1:'x',p2:'x',p3:'x',p4:'x',p5:'x'} when override is true.
@RestMethod(name=GET, path="/test2",
properties={@Property(name="p4",value="v4a"), @Property(name="p5", value="v5")})
- public ObjectMap test2(@Properties ObjectMap properties, @HasQuery("override") boolean override) {
+ public ObjectMap test2(ObjectMap properties, @HasQuery("override") boolean override) {
if (override) {
properties.put("p1", "x");
properties.put("p2", "x");
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/MessagesResource.java
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/MessagesResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/MessagesResource.java
index 0233944..7ff4953 100644
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/MessagesResource.java
+++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/MessagesResource.java
@@ -40,7 +40,7 @@ public class MessagesResource extends RestServletDefault {
// Return contents of resource bundle.
//====================================================================================================
@RestMethod(name=GET, path="/test")
- public Object test(@Messages ResourceBundle nls) {
+ public Object test(ResourceBundle nls) {
return nls;
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/NlsResource.java
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/NlsResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/NlsResource.java
index 7fcd80c..e1fdf20 100644
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/NlsResource.java
+++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/NlsResource.java
@@ -115,7 +115,7 @@ public class NlsResource extends RestServletGroupDefault {
@RestMethod(
name=GET, path="/"
)
- public Object test3a(@Messages MessageBundle mb) {
+ public Object test3a(MessageBundle mb) {
return mb;
}
}
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPostCallResource.java
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPostCallResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPostCallResource.java
index 644b117..0192aae 100644
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPostCallResource.java
+++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPostCallResource.java
@@ -20,7 +20,6 @@ import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.annotation.Properties;
import org.apache.juneau.serializer.*;
import org.apache.juneau.utils.*;
@@ -100,7 +99,7 @@ public class OnPostCallResource extends RestServlet {
// Test2 - Properties overridden programmatically.
//====================================================================================================
@RestMethod(name=PUT, path="/testPropertiesOverriddenProgramatically")
- public String testPropertiesOverriddenProgramatically(RestRequest req, @Properties ObjectMap properties) throws Exception {
+ public String testPropertiesOverriddenProgramatically(RestRequest req, ObjectMap properties) throws Exception {
properties.put("p3", "pp3");
properties.put("p4", "pp4");
String accept = req.getHeader("Accept");
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPreCallResource.java
----------------------------------------------------------------------
diff --git a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPreCallResource.java b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPreCallResource.java
index eca7965..4ee6a94 100644
--- a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPreCallResource.java
+++ b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/OnPreCallResource.java
@@ -88,7 +88,7 @@ public class OnPreCallResource extends RestServlet {
// Properties overridden programmatically.
//====================================================================================================
@RestMethod(name=PUT, path="/testPropertiesOverriddenProgrammatically")
- public String testPropertiesOverriddenProgrammatically(RestRequest req, @Properties ObjectMap properties) throws Exception {
+ public String testPropertiesOverriddenProgrammatically(RestRequest req, ObjectMap properties) throws Exception {
properties.put("p3", "pp3");
properties.put("p4", "pp4");
return req.getBody().asType(String.class);
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestProperties.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestProperties.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestProperties.java
new file mode 100644
index 0000000..0d3890c
--- /dev/null
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestProperties.java
@@ -0,0 +1,24 @@
+// ***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
+// * with the License. You may obtain a copy of the License at *
+// * *
+// * http://www.apache.org/licenses/LICENSE-2.0 *
+// * *
+// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
+// * specific language governing permissions and limitations under the License. *
+// ***************************************************************************************************************************
+package org.apache.juneau.rest;
+
+import org.apache.juneau.*;
+
+/**
+ * TODO
+ *
+ */
+@SuppressWarnings("serial")
+public class RequestProperties extends ObjectMap {
+
+}
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index af7ac81..c034e71 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -40,7 +40,6 @@ import org.apache.juneau.internal.*;
import org.apache.juneau.json.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.annotation.Properties;
import org.apache.juneau.rest.converters.*;
import org.apache.juneau.rest.response.*;
import org.apache.juneau.rest.vars.*;
@@ -1242,10 +1241,58 @@ public final class RestContext extends BeanContext {
* Specifies the logger to use for logging.
*
* <p>
- * <h5 class='section'>Notes:</h5>
- * <ul class='spaced-list'>
- * <li>Property: {@link RestContext#REST_logger}
- * <li>The {@link RestLoggerDefault} logger can be used to provide basic error logging to the Java logger.
+ * Two implementations are provided by default:
+ * <ul>
+ * <li class='jc'>{@link RestLoggerDefault} - Default logging.
+ * <li class='jc'>{@link RestLoggerNoOp} - Logging disabled.
+ * </ul>
+ *
+ * <p>
+ * Loggers are accessible through the following:
+ * <ul>
+ * <li class='jm'>{@link RestContext#getLogger() RestContext.getLogger()}
+ * <li class='jm'>{@link RestRequest#getLogger() RestRequest.getLogger()}
+ * </ul>
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode'>
+ * <jc>// Our customized logger.</jc>
+ * <jk>public class</jk> MyRestLogger <jk>extends</jk> RestLoggerDefault {
+ *
+ * <ja>@Override</ja>
+ * <jk>public void</jk> log(Level level, Throwable cause, String msg, Object...args) {
+ * <jc>// Handle logging ourselves.</jc>
+ * }
+ * }
+ *
+ * <jc>// Registered via annotation resolving to a config file setting with default value.</jc>
+ * <ja>@RestResource</ja>(logger=MyRestLogger.<jk>class</jk>)
+ * <jk>public class</jk> MyResource {...}
+ *
+ * <jc>// Registered via builder passed in through resource constructor.</jc>
+ * <jk>public class</jk> MyResource {
+ * <jk>public</jk> MyResource(RestContextBuilder builder) <jk>throws</jk> Exception {
+ *
+ * <jc>// Using method on builder.</jc>
+ * builder.logger(MyRestLogger.<jk>class</jk>);
+ *
+ * <jc>// Same, but using property.</jc>
+ * builder.set(<jsf>REST_logger</jsf>, MyRestLogger.<jk>class</jk>);
+ * }
+ * }
+ *
+ * <jc>// Registered via builder passed in through init method.</jc>
+ * <jk>public class</jk> MyResource {
+ * <ja>@RestHook</ja>(<jsf>INIT</jsf>)
+ * <jk>public void</jk> init(RestContextBuilder builder) <jk>throws</jk> Exception {
+ * builder.logger(MyRestLogger.<jk>class</jk>);
+ * }
+ * }
+ * </p>
+ *
+ * <h5 class='section'>Documentation:</h5>
+ * <ul>
+ * <li><a class="doclink" href="package-summary.html#RestResources.Errors">org.apache.juneau.rest > Handling Errors and Logging</a>
* </ul>
*/
public static final String REST_logger = PREFIX + "logger.o";
@@ -1282,6 +1329,38 @@ public final class RestContext extends BeanContext {
* <js>'K'</js>, <js>'M'</js>, <js>'G'</js>.
* <li>A value of <js>"-1"</js> can be used to represent no limit.
* </ul>
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode'>
+ * <jc>// Defined via annotation resolving to a config file setting with default value.</jc>
+ * <ja>@RestResource</ja>(maxInput=<js>"$C{REST/maxInput,10M}"</js>)
+ * <jk>public class</jk> MyResource {
+ *
+ * <jc>// Override at the method level.</jc>
+ * <ja>@RestMethod</ja>(maxInput=<js>"10M"</js>)
+ * public Object myMethod() {...}
+ * }
+ *
+ * <jc>// Defined via builder passed in through resource constructor.</jc>
+ * <jk>public class</jk> MyResource {
+ * <jk>public</jk> MyResource(RestContextBuilder builder) <jk>throws</jk> Exception {
+ *
+ * <jc>// Using method on builder.</jc>
+ * builder.maxInput(<js>"10M"</js>);
+ *
+ * <jc>// Same, but using property.</jc>
+ * builder.set(<jsf>REST_maxInput</jsf>, <js>"10M"</js>);
+ * }
+ * }
+ *
+ * <jc>// Defined via builder passed in through init method.</jc>
+ * <jk>public class</jk> MyResource {
+ * <ja>@RestHook</ja>(<jsf>INIT</jsf>)
+ * <jk>public void</jk> init(RestContextBuilder builder) <jk>throws</jk> Exception {
+ * builder.maxInput(<js>"10M"</js>);
+ * }
+ * }
+ * </p>
*/
public static final String REST_maxInput = PREFIX + "maxInput.s";
@@ -1291,7 +1370,7 @@ public final class RestContext extends BeanContext {
* <h5 class='section'>Property:</h5>
* <ul>
* <li><b>Name:</b> <js>"RestContext.messages.lo"</js>
- * <li><b>Data type:</b> <code>List<MessageBundleLocation></code>
+ * <li><b>Data type:</b> <code>List<{@link MessageBundleLocation}></code>
* <li><b>Default:</b> <jk>null</jk>
* <li><b>Session-overridable:</b> <jk>false</jk>
* <li><b>Annotations:</b>
@@ -1313,8 +1392,8 @@ public final class RestContext extends BeanContext {
* <p>
* This annotation is used to provide localized messages for the following methods:
* <ul>
- * <li>{@link RestRequest#getMessage(String, Object...)}
- * <li>{@link RestContext#getMessages()}
+ * <li class='jm'>{@link RestRequest#getMessage(String, Object...)}
+ * <li class='jm'>{@link RestContext#getMessages() RestContext.getMessages()}
* </ul>
*
* <p>
@@ -1323,12 +1402,38 @@ public final class RestContext extends BeanContext {
* <p>
* The value can be a relative path like <js>"nls/Messages"</js>, indicating to look for the resource bundle
* <js>"com.foo.sample.nls.Messages"</js> if the resource class is in <js>"com.foo.sample"</js>, or it can be an
- * absolute path, like <js>"com.foo.sample.nls.Messages"</js>
+ * absolute path like <js>"com.foo.sample.nls.Messages"</js>
*
* <h5 class='section'>Notes:</h5>
* <ul class='spaced-list'>
- * <li>Mappings are cumulative from parent to child.
+ * <li>Mappings are cumulative from parent to child.
+ * <br>Therefore, you can find and retrieve messages up the parent hierarchy chain.
* </ul>
+ *
+ * <p class='bcode'>
+ * <jk>package</jk> org.apache.foo;
+ *
+ * <jc>// Resolve messages to org/apache/foo/nls/MyMessages.properties</jc>
+ * <ja>@RestResource</ja>(messages=<js>"nls/MyMessages"</js>)
+ * <jk>public class</jk> MyResource {...}
+ *
+ * <jc>// Resolve messages to org/apache/foo/nls/MyChildMessages.properties</jc>
+ * <ja>@RestResource</ja>(messages=<js>"nls/MyChildMessages"</js>)
+ * <jk>public class</jk> MyChildResource extends MyResource {
+ *
+ * public Object testMessages(MessageBundle messages) {
+ * }
+ *
+ public String getMessage(String key, Object...args) {
+ return context.getMessages().getString(getLocale(), key, args);
+ }
+
+ public MessageBundle getResourceBundle() {
+ return context.getMessages().getBundle(getLocale());
+ }
+ *
+ * }
+ * </p>
*/
public static final String REST_messages = PREFIX + "messages.lo";
@@ -2853,11 +2958,9 @@ public final class RestContext extends BeanContext {
* Returns the logger to use for this resource.
*
* <p>
- * The logger for a resource is defined via one of the following:
+ * The logger for a resource is defined through the following property:
* <ul>
- * <li class='ja'>{@link RestResource#logger() @RestResource.logger()}\
- * <li class='jm'>{@link RestContextBuilder#logger(Class)}
- * <li class='jm'>{@link RestContextBuilder#logger(RestLogger)}
+ * <li class='jf'>{@link RestContext#REST_logger}
* </ul>
*
* @return The logger to use for this resource. Never <jk>null</jk>.
@@ -3170,29 +3273,23 @@ public final class RestContext extends BeanContext {
rp[i] = RestParamDefaults.STANDARD_RESOLVERS.get(c);
}
- if (rp[i] == null) {
- for (Annotation a : pa[i]) {
- if (a instanceof Header)
- rp[i] = new RestParamDefaults.HeaderObject((Header)a, t, ps);
- else if (a instanceof FormData)
- rp[i] = new RestParamDefaults.FormDataObject(method, (FormData)a, t, ps);
- else if (a instanceof Query)
- rp[i] = new RestParamDefaults.QueryObject(method, (Query)a, t, ps);
- else if (a instanceof HasFormData)
- rp[i] = new RestParamDefaults.HasFormDataObject(method, (HasFormData)a, t);
- else if (a instanceof HasQuery)
- rp[i] = new RestParamDefaults.HasQueryObject(method, (HasQuery)a, t);
- else if (a instanceof Body)
- rp[i] = new RestParamDefaults.BodyObject(t);
- else if (a instanceof org.apache.juneau.rest.annotation.Method)
- rp[i] = new RestParamDefaults.MethodObject(method, t);
- else if (a instanceof PathRemainder)
- rp[i] = new RestParamDefaults.PathRemainderObject(method, t);
- else if (a instanceof Properties)
- rp[i] = new RestParamDefaults.PropsObject(method, t);
- else if (a instanceof Messages)
- rp[i] = new RestParamDefaults.MessageBundleObject();
- }
+ for (Annotation a : pa[i]) {
+ if (a instanceof Header)
+ rp[i] = new RestParamDefaults.HeaderObject((Header)a, t, ps);
+ else if (a instanceof FormData)
+ rp[i] = new RestParamDefaults.FormDataObject(method, (FormData)a, t, ps);
+ else if (a instanceof Query)
+ rp[i] = new RestParamDefaults.QueryObject(method, (Query)a, t, ps);
+ else if (a instanceof HasFormData)
+ rp[i] = new RestParamDefaults.HasFormDataObject(method, (HasFormData)a, t);
+ else if (a instanceof HasQuery)
+ rp[i] = new RestParamDefaults.HasQueryObject(method, (HasQuery)a, t);
+ else if (a instanceof Body)
+ rp[i] = new RestParamDefaults.BodyObject(t);
+ else if (a instanceof org.apache.juneau.rest.annotation.Method)
+ rp[i] = new RestParamDefaults.MethodObject(method, t);
+ else if (a instanceof PathRemainder)
+ rp[i] = new RestParamDefaults.PathRemainderObject(method, t);
}
if (rp[i] == null) {
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
index 633416c..5f9d52c 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestParamDefaults.java
@@ -110,6 +110,7 @@ class RestParamDefaults {
ConfigFileObject.class,
UriContextObject.class,
UriResolverObject.class,
+ PropsObject.class
};
for (Class<?> c : r) {
@@ -670,10 +671,8 @@ class RestParamDefaults {
static final class PropsObject extends RestParam {
- protected PropsObject(Method method, Type type) throws ServletException {
- super(OTHER, null, null);
- if (type != ObjectMap.class)
- throw new RestServletException("Use of @Properties annotation on parameter that is not an ObjectMap on method ''{0}''", method);
+ protected PropsObject() {
+ super(OTHER, null, ObjectMap.class);
}
@Override /* RestParam */
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
index 2354d36..2e4bc45 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
@@ -984,6 +984,14 @@ public final class RestRequest extends HttpServletRequestWrapper {
return sb.toString();
}
+ /**
+ * Shortcut for calling <code>getContext().getLogger()</code>.
+ *
+ * @return The logger associated with the resource context.
+ */
+ public RestLogger getLogger() {
+ return context.getLogger();
+ }
//--------------------------------------------------------------------------------
// Utility methods
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Messages.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Messages.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Messages.java
deleted file mode 100644
index 6bf6043..0000000
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Messages.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// ***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
-// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
-// * with the License. You may obtain a copy of the License at *
-// * *
-// * http://www.apache.org/licenses/LICENSE-2.0 *
-// * *
-// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
-// * specific language governing permissions and limitations under the License. *
-// ***************************************************************************************************************************
-package org.apache.juneau.rest.annotation;
-
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.*;
-
-import java.lang.annotation.*;
-import java.util.*;
-
-import org.apache.juneau.utils.*;
-
-/**
- * Annotation that can be applied to a parameter of a {@link RestMethod @RestMethod} annotated method to identify it as the
- * resource bundle for the request locale.
- *
- * <p>
- * Parameter type must be either {@link ResourceBundle} or {@link MessageBundle}.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode'>
- * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>)
- * <jk>public</jk> String doGet(<ja>@Messages</ja> ResourceBundle messages) {
- * <jk>return</jk> messages.getString(<js>"myLocalizedMessage"</js>);
- * }
- * </p>
- *
- * <p>
- * This is functionally equivalent to the following code...
- * <p class='bcode'>
- * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>)
- * <jk>public</jk> String doGet(RestRequest req) {
- * <jk>return</jk> req.getMessage(<js>"myLocalizedMessage"</js>);
- * }
- * </p>
- */
-@Documented
-@Target(PARAMETER)
-@Retention(RUNTIME)
-@Inherited
-public @interface Messages {}
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Properties.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Properties.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Properties.java
deleted file mode 100644
index 92d5049..0000000
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Properties.java
+++ /dev/null
@@ -1,67 +0,0 @@
-// ***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
-// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
-// * with the License. You may obtain a copy of the License at *
-// * *
-// * http://www.apache.org/licenses/LICENSE-2.0 *
-// * *
-// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
-// * specific language governing permissions and limitations under the License. *
-// ***************************************************************************************************************************
-package org.apache.juneau.rest.annotation;
-
-import static java.lang.annotation.ElementType.*;
-import static java.lang.annotation.RetentionPolicy.*;
-
-import java.lang.annotation.*;
-
-import org.apache.juneau.*;
-
-/**
- * Annotation that can be applied to a parameter of a {@link RestMethod @RestMethod} annotated method to identify the
- * request-duration properties object for the current request.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode'>
- * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>)
- * <jk>public Person</jk> doGetPerson(<ja>@Properties</ja> ObjectMap properties) {
- * properties.put(<jsf>HTMLDOC_title</jsf>, <js>"This is a person"</js>);
- * ...
- * }
- * </p>
- *
- * <p>
- * This is functionally equivalent to the following code...
- * <p class='bcode'>
- * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>)
- * <jk>public Person</jk> doGetPerson(RestResponse res) {
- * ObjectMap properties = res.getProperties();
- * properties.put(<jsf>HTMLDOC_title</jsf>, <js>"This is a person"</js>);
- * ...
- * }
- * </p>
- *
- * <p>
- * ...or this...
- * <p class='bcode'>
- * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>)
- * <jk>public Person</jk> doGetPerson(RestResponse res) {
- * res.setProperty(<jsf>HTMLDOC_title</jsf>, <js>"This is a person"</js>);
- * ...
- * }
- * </p>
- *
- * <p>
- * The parameter type can be one of the following:
- * <ul>
- * <li>{@link ObjectMap}
- * <li><code>Map<String,Object></code>
- * </ul>
- */
-@Documented
-@Target(PARAMETER)
-@Retention(RUNTIME)
-@Inherited
-public @interface Properties {}
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
index 46d8497..0025492 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
@@ -678,7 +678,7 @@ public @interface RestResource {
*
* <p>
* In some cases, properties can be overridden at runtime through the
- * {@link RestResponse#setProperty(String, Object)} method or through a {@link Properties @Properties} annotated
+ * {@link RestResponse#setProperty(String, Object)} method or through an {@link ObjectMap}
* method parameter.
*
* <p>
http://git-wip-us.apache.org/repos/asf/juneau/blob/07f39bb7/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/package.html
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/package.html b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/package.html
index 840dbbe..83637d7 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/package.html
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/package.html
@@ -94,7 +94,7 @@
<li><p><a class='doclink' href='#RestResources.Listeners'>Listener Methods</a></p>
<li><p><a class='doclink' href='#RestResources.Stylesheet'>Stylesheet</a></p>
<li><p><a class='doclink' href='#RestResources.Headers'>Default Headers</a></p>
- <li><p><a class='doclink' href='#RestResources.Errors'>Handling Errors / Logging</a></p>
+ <li><p><a class='doclink' href='#RestResources.Errors'>Handling Errors and Logging</a></p>
<li><p><a class='doclink' href='#RestResources.ConfigFile'>Configuration Files</a></p>
<li><p><a class='doclink' href='#RestResources.Inheritence'>Annotation Inheritance</a></p>
<li><p><a class='doclink' href='#RestResources.HttpStatusCodes'>HTTP Status Codes</a></p>
@@ -728,8 +728,6 @@
<li>{@link org.apache.juneau.rest.annotation.Method @Method} - The HTTP method name.
<li>{@link org.apache.juneau.rest.annotation.PathRemainder @PathRemainder} - The remainder value after path pattern match.
<li>{@link org.apache.juneau.rest.annotation.Body @Body} - The HTTP content parsed as a POJO.
- <li>{@link org.apache.juneau.rest.annotation.Messages @Messages} - The resource bundle for the servlet localized to the language on the request.
- <li>{@link org.apache.juneau.rest.annotation.Properties @Properties} - The serializer/parser/servlet properties so they can be read or altered on the request.
</ul>
</ul>
<p class='bcode'>
@@ -750,8 +748,8 @@
<ja>@Header</ja>(<js>"Accept-Language"</js>) String lang,
<ja>@Header</ja>(<js>"Accept"</js>) String accept,
<ja>@Header</ja>(<js>"DNT"</js>) <jk>int</jk> doNotTrack,
- <ja>@Properties</ja> ObjectMap properties,
- <ja>@Messages</ja> ResourceBundle nls
+ ObjectMap properties,
+ ResourceBundle nls
) {
<jc>// Do something with all of those</jc>
}
@@ -2117,12 +2115,12 @@
}
</p>
<p>
- The resource bundle can also be passed into the method by using the
- {@link org.apache.juneau.rest.annotation.Messages @Messages} annotation:
+ The resource bundle can also be passed into the method by simply specifying a parameter
+ of type <code>ResourceBundle</code>:
</p>
<p class='bcode'>
<ja>@RestMethod</ja>(name=<jsf>GET</jsf>)
- <jk>public</jk> String printLocalizedGreeting(<ja>@Messages</ja> ResourceBundle messages) {
+ <jk>public</jk> String printLocalizedGreeting(ResourceBundle messages) {
<jk>return</jk> messages.getString(<js>"greeting"</js>);
}
</p>
@@ -2673,26 +2671,12 @@
<!-- ======================================================================================================== -->
<a id="RestResources.Errors"></a>
- <h3 class='topic' onclick='toggle(this)'>4.20 - Handling Errors / Logging</h3>
+ <h3 class='topic' onclick='toggle(this)'>4.20 - Handling Errors and Logging</h3>
<div class='topic'>
<p>
- The following overridable methods are provided for handling errors on requests:
- </p>
- <ul class='doctree'>
- <li class='jac'>
- {@link org.apache.juneau.rest.RestCallHandler}
- <ul>
- <li class='jm'>
- {@link org.apache.juneau.rest.RestCallHandler#renderError(HttpServletRequest,HttpServletResponse,RestException) renderError(HttpServletRequest,HttpServletResponse,RestException)}
- <br>Method that produces the error message on the HTTP response.
- <li class='jm'>
- {@link org.apache.juneau.rest.RestCallHandler#handleNotFound(int,RestRequest,RestResponse) handleNotFound(int,RestRequest,RestResponse)}
- <br>Method that gets called when no method/path pattern match the incoming request.
- </ul>
- </li>
- </ul>
- <p>
- The following convenience methods are provided for logging:
+ The {@link org.apache.juneau.rest.RestContext#REST_logger} property allows you to configure
+ logging for your resource.
+ <br>The interface is shown below:
</p>
<ul class='doctree'>
<li class='jac'>
@@ -2703,7 +2687,7 @@
<li class='jm'>
{@link org.apache.juneau.rest.RestLogger#log(Level,Throwable,String,Object[]) log(Level,Throwable,String,Object[])}
<li class='jm'>
- {@link org.apache.juneau.rest.RestLogger#logObjects(Level,String,Object[]) logObject(Level,String,Object[])}
+ {@link org.apache.juneau.rest.RestLogger#logObjects(Level,String,Object[]) logObjects(Level,String,Object[])}
<li class='jm'>
{@link org.apache.juneau.rest.RestLogger#onError(HttpServletRequest,HttpServletResponse,RestException) onError(HttpServletRequest,HttpServletResponse,RestException)}
<br>Gets called when an error occurs on a request call.
@@ -2712,37 +2696,40 @@
</li>
</ul>
<p>
- The <l>logObjects()</l> method is particularly useful because it allows you to pass in POJOs as arguments
+ The {@link org.apache.juneau.rest.RestLogger#logObjects(Level,String,Object[]) logObjects()} method is particularly useful because it allows you to pass in POJOs as arguments
that serialized using {@link org.apache.juneau.json.JsonSerializer#DEFAULT_LAX_READABLE}, but only
if the message is actually logged.
</p>
<h6 class='figure'>Example:</h6>
<p class='bcode'>
- logObjects(<jsf>DEBUG</jsf>, <js>"Pojo contents:\n{0}"</js>, myPojo);
+ logger.logObjects(<jsf>DEBUG</jsf>, <js>"Pojo contents:\n{0}"</js>, myPojo);
</p>
<p>
- The Juneau framework uses the built-in Java Logging API for logging.
+ By default, the Juneau framework uses the built-in Java Logging API for logging.
+ <br>But you can define your own implementation to use any framework you wish.
</p>
<p>
- If your application makes use of Apache Commons Logging or some other logging API, you can override the
- {@link org.apache.juneau.rest.RestServlet#log(Level,String,Object[])} method to provide a bridge between
- the two frameworks.
+ The {@link org.apache.juneau.rest.RestLogger} instance is accessible via the following:
+ </p>
+ <ul>
+ <li class='jm'>{@link org.apache.juneau.rest.RestContext#getLogger()}
+ <li class='jm'>{@link org.apache.juneau.rest.RestRequest#getLogger()}
+ </ul>
+ <p>
+ In addition, the logger can be accessed by passing it as a parameter to your REST java method:
</p>
<p class='bcode'>
- <ja>@Override</ja> <jc>/* RestServlet */</jc>
- <jk>protected void</jk> log(Level level, Throwable cause, String msg, Object...args) {
- Log log = getApacheCommonsLog();
- <jk>if</jk> (level == Level.<jsf>SEVERE</jsf>)
- log.error(msg, cause, args);
- <jk>else if</jk> (level == Level.<jsf>WARNING</jsf>)
- log.warn(msg, cause, args);
- <jk>else if</jk> (level == Level.<jsf>INFO</jsf>)
- log.info(msg, cause, args);
- <jk>else</jk>
- log.debug(msg, cause, args);
- }
+ <ja>@RestMethod()</ja>
+ <jk>public</jk> Object doSomething(RestLogger logger) {...}
</p>
+ <p>
+ If your resource extends from {@link org.apache.juneau.rest.RestServlet}, you can also
+ use and override the following methods:
+ <ul>
+ <li class='jm'>{@link org.apache.juneau.rest.RestServlet#log(Level,String,Object...)}
+ <li class='jm'>{@link org.apache.juneau.rest.RestServlet#log(Level,Throwable,String,Object...)}
+ </ul>
</div>
<!-- ======================================================================================================== -->