This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new f495e69 Context API refactoring.
f495e69 is described below
commit f495e69bb84c2912f755a1c003145bce713d098c
Author: JamesBognar <[email protected]>
AuthorDate: Sun Aug 22 14:33:12 2021 -0400
Context API refactoring.
---
.../apache/juneau/rest/RestOperationContext.java | 44 ++----------
.../juneau/rest/RestOperationContextBuilder.java | 18 +++--
.../rest/annotation/RestDeleteAnnotation.java | 2 +-
.../juneau/rest/annotation/RestGetAnnotation.java | 2 +-
.../juneau/rest/annotation/RestOpAnnotation.java | 2 +-
.../juneau/rest/annotation/RestPostAnnotation.java | 2 +-
.../juneau/rest/annotation/RestPutAnnotation.java | 2 +-
.../juneau/rest/annotation/Rest_Debug_Test.java | 78 +++++++++++-----------
8 files changed, 64 insertions(+), 86 deletions(-)
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
index 6157d64..f44c4bb 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
@@ -83,42 +83,6 @@ public class RestOperationContext extends BeanContext
implements Comparable<Rest
static final String PREFIX = "RestOperationContext";
/**
- * Configuration property: Debug mode.
- *
- * <h5 class='section'>Property:</h5>
- * <ul class='spaced-list'>
- * <li><b>ID:</b> {@link
org.apache.juneau.rest.RestOperationContext#RESTOP_debug RESTOP_debug}
- * <li><b>Name:</b> <js>"RestOperationContext.debug.s"</js>
- * <li><b>Data type:</b> {@link org.apache.juneau.Enablement}
- * <li><b>System property:</b> <c>RestOperationContext.debug</c>
- * <li><b>Environment variable:</b>
<c>RESTOPERATIONCONTEXT_DEBUG</c>
- * <li><b>Default:</b> <jk>null</jk>
- * <li><b>Session property:</b> <jk>false</jk>
- * <li><b>Annotations:</b>
- * <ul>
- * <li class='ja'>{@link
org.apache.juneau.rest.annotation.RestOp#debug()}
- * </ul>
- * <li><b>Methods:</b>
- * <ul>
- * <li class='jm'>{@link
org.apache.juneau.rest.RestOperationContextBuilder#debug(Enablement)}
- * </ul>
- * </ul>
- *
- * <h5 class='section'>Description:</h5>
- * <p>
- * Enables the following:
- * <ul class='spaced-list'>
- * <li>
- * HTTP request/response bodies are cached in memory for
logging purposes.
- * </ul>
- *
- * <ul class='seealso'>
- * <li class='jf'>{@link RestContext#REST_debug}
- * </ul>
- */
- public static final String RESTOP_debug = PREFIX + ".debug.s";
-
- /**
* Configuration property: Default form data.
*
* <h5 class='section'>Property:</h5>
@@ -451,6 +415,7 @@ public class RestOperationContext extends BeanContext
implements Comparable<Rest
private final Map<Class<?>,ResponsePartMeta> bodyPartMetas = new
ConcurrentHashMap<>();
private final ResponseBeanMeta responseMeta;
private final int hierarchyDepth;
+ private final DebugEnablement debug;
/**
* Creator.
@@ -476,6 +441,11 @@ public class RestOperationContext extends BeanContext
implements Comparable<Rest
context = builder.restContext;
method = builder.restMethod;
+ if (builder.debug == null)
+ debug = context.getDebugEnablement();
+ else
+ debug =
DebugEnablement.create().enable(builder.debug, "*").build();
+
ContextProperties cp = getContextProperties();
methodInvoker = new MethodInvoker(method,
context.getMethodExecStats(method));
@@ -1626,7 +1596,7 @@ public class RestOperationContext extends BeanContext
implements Comparable<Rest
call.logger(callLogger);
- call.debug(context.getDebugEnablement().isDebug(this,
call.getRequest()));
+ call.debug(debug.isDebug(this, call.getRequest()));
Object[] args = new Object[opArgs.length];
for (int i = 0; i < opArgs.length; i++) {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContextBuilder.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContextBuilder.java
index d14ba7a..05c6c59 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContextBuilder.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContextBuilder.java
@@ -42,8 +42,8 @@ public class RestOperationContextBuilder extends
BeanContextBuilder {
RestContext restContext;
Method restMethod;
- String httpMethod;
- String clientVersion;
+ String httpMethod, clientVersion;
+ Enablement debug;
private BeanStore beanStore;
@@ -202,17 +202,25 @@ public class RestOperationContextBuilder extends
BeanContextBuilder {
}
/**
- * <i><l>RestOperationContext</l> configuration property: </i>
Debug mode.
+ * Debug mode.
*
* <p>
- * Enables debugging on this method.
+ * Enables the following:
+ * <ul class='spaced-list'>
+ * <li>
+ * HTTP request/response bodies are cached in memory for
logging purposes.
+ * </ul>
+ *
+ * <p>
+ * If not sppecified, the debug enablement is inherited from the class
context.
*
* @param value The new value for this setting.
* @return This object (for method chaining).
*/
@FluentSetter
public RestOperationContextBuilder debug(Enablement value) {
- return set(RESTOP_debug, value);
+ debug = value;
+ return this;
}
/**
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestDeleteAnnotation.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestDeleteAnnotation.java
index fb46419..21c4a39 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestDeleteAnnotation.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestDeleteAnnotation.java
@@ -471,7 +471,7 @@ public class RestDeleteAnnotation {
b.setIfNotEmpty(RESTOP_path, a.value());
cdStream(a.rolesDeclared()).forEach(x ->
b.addTo(REST_rolesDeclared, x));
b.addToIfNotEmpty(REST_roleGuard,
string(a.roleGuard()));
- b.setIfNotEmpty(RESTOP_debug, string(a.debug()));
+
value(a.debug()).map(Enablement::fromString).ifPresent(x -> b.debug(x));
}
}
}
\ No newline at end of file
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestGetAnnotation.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestGetAnnotation.java
index 2b9c136..c292327 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestGetAnnotation.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestGetAnnotation.java
@@ -527,7 +527,7 @@ public class RestGetAnnotation {
b.setIfNotEmpty(RESTOP_path, a.value());
cdStream(a.rolesDeclared()).forEach(x ->
b.addTo(REST_rolesDeclared, x));
b.addToIfNotEmpty(REST_roleGuard,
string(a.roleGuard()));
- b.setIfNotEmpty(RESTOP_debug, string(a.debug()));
+
value(a.debug()).map(Enablement::fromString).ifPresent(x -> b.debug(x));
}
}
}
\ No newline at end of file
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestOpAnnotation.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestOpAnnotation.java
index d62a61d..6cd38d9 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestOpAnnotation.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestOpAnnotation.java
@@ -633,7 +633,7 @@ public class RestOpAnnotation {
b.addToIfNotEmpty(REST_roleGuard,
string(a.roleGuard()));
value(a.method()).ifPresent(x -> b.httpMethod(x));
- b.setIfNotEmpty(RESTOP_debug, string(a.debug()));
+
value(a.debug()).map(Enablement::fromString).ifPresent(x -> b.debug(x));
String v = StringUtils.trim(string(a.value()));
if (v != null) {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestPostAnnotation.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestPostAnnotation.java
index 593b26d..348251c 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestPostAnnotation.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestPostAnnotation.java
@@ -617,7 +617,7 @@ public class RestPostAnnotation {
b.setIfNotEmpty(RESTOP_path, a.value());
cdStream(a.rolesDeclared()).forEach(x ->
b.addTo(REST_rolesDeclared, x));
b.addToIfNotEmpty(REST_roleGuard,
string(a.roleGuard()));
- b.setIfNotEmpty(RESTOP_debug, string(a.debug()));
+
value(a.debug()).map(Enablement::fromString).ifPresent(x -> b.debug(x));
}
}
}
\ No newline at end of file
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestPutAnnotation.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestPutAnnotation.java
index 7c33d93..8b72ff7 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestPutAnnotation.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestPutAnnotation.java
@@ -617,7 +617,7 @@ public class RestPutAnnotation {
b.setIfNotEmpty(RESTOP_path, a.value());
cdStream(a.rolesDeclared()).forEach(x ->
b.addTo(REST_rolesDeclared, x));
b.addToIfNotEmpty(REST_roleGuard,
string(a.roleGuard()));
- b.setIfNotEmpty(RESTOP_debug, string(a.debug()));
+
value(a.debug()).map(Enablement::fromString).ifPresent(x -> b.debug(x));
}
}
}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_Debug_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_Debug_Test.java
index d023920..64f92c6 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_Debug_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_Debug_Test.java
@@ -751,14 +751,14 @@ public class Rest_Debug_Test {
assertNotLogged();
c1d.get("/b4").run().assertBody().is("false");
assertNotLogged();
- c1.get("/b5").run().assertBody().is("false");
- assertNotLogged();
- c1d.get("/b5").run().assertBody().is("false");
- assertNotLogged();
+ c1.get("/b5").run().assertBody().is("true");
+ assertLogged();
+ c1d.get("/b5").run().assertBody().is("true");
+ assertLogged();
c1.get("/b6").run().assertBody().is("false");
assertNotLogged();
- c1d.get("/b6").run().assertBody().is("false");
- assertNotLogged();
+ c1d.get("/b6").run().assertBody().is("true");
+ assertLogged();
c1.get("/c1").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c1");
@@ -772,16 +772,16 @@ public class Rest_Debug_Test {
assertLogged("[200] HTTP GET /c3");
c1d.get("/c3").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c3");
- c1.get("/c4").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /c4");
- c1d.get("/c4").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /c4");
+ c1.get("/c4").run().assertBody().is("false");
+ assertNotLogged();
+ c1d.get("/c4").run().assertBody().is("false");
+ assertNotLogged();
c1.get("/c5").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c5");
c1d.get("/c5").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c5");
- c1.get("/c6").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /c6");
+ c1.get("/c6").run().assertBody().is("false");
+ assertNotLogged();
c1d.get("/c6").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c6");
@@ -799,10 +799,10 @@ public class Rest_Debug_Test {
assertLogged("[200] HTTP GET /d3");
c1.get("/d4").run().assertBody().is("false");
assertNotLogged();
- c1d.get("/d4").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /d4");
- c1.get("/d5").run().assertBody().is("false");
+ c1d.get("/d4").run().assertBody().is("false");
assertNotLogged();
+ c1.get("/d5").run().assertBody().is("true");
+ assertLogged("[200] HTTP GET /d5");
c1d.get("/d5").run().assertBody().is("true");
assertLogged("[200] HTTP GET /d5");
c1.get("/d6").run().assertBody().is("false");
@@ -824,10 +824,10 @@ public class Rest_Debug_Test {
assertLogged("[200] HTTP GET /e3");
c1.get("/e4").run().assertBody().is("false");
assertNotLogged();
- c1d.get("/e4").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /e4");
- c1.get("/e5").run().assertBody().is("false");
+ c1d.get("/e4").run().assertBody().is("false");
assertNotLogged();
+ c1.get("/e5").run().assertBody().is("true");
+ assertLogged("[200] HTTP GET /e5");
c1d.get("/e5").run().assertBody().is("true");
assertLogged("[200] HTTP GET /e5");
c1.get("/e6").run().assertBody().is("false");
@@ -1085,14 +1085,14 @@ public class Rest_Debug_Test {
assertNotLogged();
c2d.get("/b4").run().assertBody().is("false");
assertNotLogged();
- c2.get("/b5").run().assertBody().is("false");
- assertNotLogged();
- c2d.get("/b5").run().assertBody().is("false");
- assertNotLogged();
+ c2.get("/b5").run().assertBody().is("true");
+ assertLogged();
+ c2d.get("/b5").run().assertBody().is("true");
+ assertLogged();
c2.get("/b6").run().assertBody().is("false");
assertNotLogged();
- c2d.get("/b6").run().assertBody().is("false");
- assertNotLogged();
+ c2d.get("/b6").run().assertBody().is("true");
+ assertLogged();
c2.get("/c1").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c1");
@@ -1106,16 +1106,16 @@ public class Rest_Debug_Test {
assertLogged("[200] HTTP GET /c3");
c2d.get("/c3").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c3");
- c2.get("/c4").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /c4");
- c2d.get("/c4").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /c4");
+ c2.get("/c4").run().assertBody().is("false");
+ assertNotLogged();
+ c2d.get("/c4").run().assertBody().is("false");
+ assertNotLogged();
c2.get("/c5").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c5");
c2d.get("/c5").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c5");
- c2.get("/c6").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /c6");
+ c2.get("/c6").run().assertBody().is("false");
+ assertNotLogged();
c2d.get("/c6").run().assertBody().is("true");
assertLogged("[200] HTTP GET /c6");
@@ -1133,10 +1133,10 @@ public class Rest_Debug_Test {
assertLogged("[200] HTTP GET /d3");
c2.get("/d4").run().assertBody().is("false");
assertNotLogged();
- c2d.get("/d4").run().assertBody().is("true");
- assertLogged("[200] HTTP GET /d4");
- c2.get("/d5").run().assertBody().is("false");
+ c2d.get("/d4").run().assertBody().is("false");
assertNotLogged();
+ c2.get("/d5").run().assertBody().is("true");
+ assertLogged("[200] HTTP GET /d5");
c2d.get("/d5").run().assertBody().is("true");
assertLogged("[200] HTTP GET /d5");
c2.get("/d6").run().assertBody().is("false");
@@ -1156,16 +1156,16 @@ public class Rest_Debug_Test {
assertLogged();
c2d.get("/e3").run().assertBody().is("true");
assertLogged();
- c2.get("/e4").run().assertBody().is("true");
- assertLogged();
- c2d.get("/e4").run().assertBody().is("true");
- assertLogged();
+ c2.get("/e4").run().assertBody().is("false");
+ assertNotLogged();
+ c2d.get("/e4").run().assertBody().is("false");
+ assertNotLogged();
c2.get("/e5").run().assertBody().is("true");
assertLogged();
c2d.get("/e5").run().assertBody().is("true");
assertLogged();
- c2.get("/e6").run().assertBody().is("true");
- assertLogged();
+ c2.get("/e6").run().assertBody().is("false");
+ assertNotLogged();
c2d.get("/e6").run().assertBody().is("true");
assertLogged();