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 2019/05/29 21:02:29 UTC
[juneau] branch master updated: RestMethodContext refactor.
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 edbb1e3 RestMethodContext refactor.
edbb1e3 is described below
commit edbb1e36a0333991b5699c685ca3a6b86a4cceb3
Author: JamesBognar <ja...@apache.org>
AuthorDate: Wed May 29 17:02:10 2019 -0400
RestMethodContext refactor.
---
.../src/main/java/org/apache/juneau/Context.java | 2 +-
.../java/org/apache/juneau/rest/RestContext.java | 6 ++++--
.../org/apache/juneau/rest/RestMethodContext.java | 22 ++++++++++++++--------
.../juneau/rest/RestMethodContextBuilder.java | 16 +++++++---------
.../rest/annotation/RestMethodConfigApply.java | 6 ++++++
5 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
index d251165..54e20e1 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/Context.java
@@ -510,7 +510,7 @@ public abstract class Context {
}
@Override /* Object */
- public final boolean equals(Object o) {
+ public boolean equals(Object o) {
// Context objects are considered equal if they're the same class and have the same set of properties.
if (o == null)
return false;
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 e803aea..b8e7f95 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
@@ -3398,7 +3398,8 @@ public final class RestContext extends BeanContext {
if (mi.isNotPublic())
throw new RestServletException("@RestMethod method {0}.{1} must be defined as public.", resourceClass.getName(), mi.getSimpleName());
- RestMethodContext sm = new RestMethodContext(resource, mi.inner(), this);
+ RestMethodContextBuilder rmcb = new RestMethodContextBuilder(resource, mi.inner(), this);
+ RestMethodContext sm = new RestMethodContext(rmcb);
String httpMethod = sm.getHttpMethod();
// RRPC is a special case where a method returns an interface that we
@@ -3411,7 +3412,8 @@ public final class RestContext extends BeanContext {
if (rim.getMethodsByPath().isEmpty())
throw new RestException(SC_INTERNAL_SERVER_ERROR, "Method {0} returns an interface {1} that doesn't define any remote methods.", mi.getSignature(), interfaceClass.getFullName());
- sm = new RestMethodContext(resource, mi.inner(), this) {
+ RestMethodContextBuilder smb = new RestMethodContextBuilder(resource, mi.inner(), this);
+ sm = new RestMethodContext(smb) {
@Override
int invoke(String pathInfo, RestRequest req, RestResponse res) throws Throwable {
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
index cfa4763..0a9f416 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
@@ -17,6 +17,7 @@ import static org.apache.juneau.internal.ClassUtils.*;
import static org.apache.juneau.internal.CollectionUtils.*;
import static org.apache.juneau.internal.ObjectUtils.*;
import static org.apache.juneau.httppart.HttpPartType.*;
+import static org.apache.juneau.rest.RestContext.*;
import java.lang.reflect.*;
import java.util.*;
@@ -30,6 +31,7 @@ import org.apache.juneau.http.*;
import org.apache.juneau.http.annotation.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.httppart.bean.*;
+import org.apache.juneau.internal.*;
import org.apache.juneau.jsonschema.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.reflect.*;
@@ -43,7 +45,7 @@ import org.apache.juneau.svl.*;
/**
* Represents a single Java servlet/resource method annotated with {@link RestMethod @RestMethod}.
*/
-public class RestMethodContext implements Comparable<RestMethodContext> {
+public class RestMethodContext extends BeanContext implements Comparable<RestMethodContext> {
private final String httpMethod;
private final UrlPathPattern pathPattern;
final RestMethodParam[] methodParams;
@@ -80,12 +82,18 @@ public class RestMethodContext implements Comparable<RestMethodContext> {
final Map<Class<?>,ResponsePartMeta> bodyPartMetas = new ConcurrentHashMap<>();
final ResponseBeanMeta responseMeta;
- RestMethodContext(Object servlet, java.lang.reflect.Method method, RestContext context) throws RestServletException {
- RestMethodContextBuilder b = new RestMethodContextBuilder(servlet, method, context);
- this.context = context;
- this.method = method;
- this.info = MethodInfo.of(method);
+ RestMethodContext(RestMethodContextBuilder b) {
+ super(b.getPropertyStore());
+
+ this.context = b.context;
+ this.method = b.method;
this.httpMethod = b.httpMethod;
+
+ this.info = MethodInfo.of(method);
+
+ defaultCharset = getProperty(REST_defaultCharset, String.class, context.getDefaultCharset());
+ maxInput = StringUtils.parseLongWithSuffix(getProperty(REST_maxInput, String.class, String.valueOf(context.getMaxInput())));
+
this.pathPattern = b.pathPattern;
this.methodParams = b.methodParams;
this.guards = b.guards;
@@ -104,8 +112,6 @@ public class RestMethodContext implements Comparable<RestMethodContext> {
this.defaultRequestHeaders = b.defaultRequestHeaders;
this.defaultQuery = b.defaultQuery;
this.defaultFormData = b.defaultFormData;
- this.defaultCharset = b.defaultCharset;
- this.maxInput = b.maxInput;
this.priority = b.priority;
this.supportedAcceptTypes = b.supportedAcceptTypes;
this.supportedContentTypes = b.supportedContentTypes;
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContextBuilder.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContextBuilder.java
index 972be19..d879101 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContextBuilder.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContextBuilder.java
@@ -44,7 +44,10 @@ import org.apache.juneau.svl.*;
*/
public class RestMethodContextBuilder extends BeanContextBuilder {
- String httpMethod, defaultCharset;
+ RestContext context;
+ java.lang.reflect.Method method;
+
+ String httpMethod;
UrlPathPattern pathPattern;
RestMethodParam[] methodParams;
RestGuard[] guards;
@@ -60,7 +63,6 @@ public class RestMethodContextBuilder extends BeanContextBuilder {
RestMethodProperties properties;
PropertyStore propertyStore;
Map<String,Object> defaultRequestHeaders, defaultQuery, defaultFormData;
- long maxInput;
Integer priority;
Map<String,Widget> widgets;
List<MediaType> supportedAcceptTypes, supportedContentTypes;
@@ -68,6 +70,9 @@ public class RestMethodContextBuilder extends BeanContextBuilder {
@SuppressWarnings("deprecation")
RestMethodContextBuilder(Object servlet, java.lang.reflect.Method method, RestContext context) throws RestServletException {
+ this.context = context;
+ this.method = method;
+
String sig = method.getDeclaringClass().getName() + '.' + method.getName();
MethodInfo mi = getMethodInfo(servlet.getClass(), method);
@@ -103,15 +108,8 @@ public class RestMethodContextBuilder extends BeanContextBuilder {
beanContext = context.getBeanContext();
encoders = context.getEncoders();
properties = new RestMethodProperties(context.getProperties());
- defaultCharset = context.getDefaultCharset();
- maxInput = context.getMaxInput();
AnnotationList configAnnotationList = hasConfigAnnotations ? mi.getAnnotationListParentFirst(ConfigAnnotationFilter.INSTANCE) : context.getConfigAnnotationList();
- if (! m.defaultCharset().isEmpty())
- defaultCharset = vr.resolve(m.defaultCharset());
- if (! m.maxInput().isEmpty())
- maxInput = StringUtils.parseLongWithSuffix(vr.resolve(m.maxInput()));
-
HtmlDocBuilder hdb = new HtmlDocBuilder(properties);
HtmlDoc hd = m.htmldoc();
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestMethodConfigApply.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestMethodConfigApply.java
index a5c1760..d57741f 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestMethodConfigApply.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestMethodConfigApply.java
@@ -37,6 +37,12 @@ public class RestMethodConfigApply extends ConfigApply<RestMethod> {
public void apply(AnnotationInfo<RestMethod> ai, PropertyStoreBuilder psb) {
RestMethod a = ai.getAnnotation();
+ if (! a.defaultCharset().isEmpty())
+ psb.set(REST_defaultCharset, string(a.defaultCharset()));
+
+ if (! a.maxInput().isEmpty())
+ psb.set(REST_maxInput, string(a.maxInput()));
+
if (! a.rolesDeclared().isEmpty())
psb.set(REST_rolesDeclared, string(a.rolesDeclared()));