juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject juneau git commit: Improve efficiency of RestMethod initialization.
Date Sat, 06 Jan 2018 04:03:57 GMT
Repository: juneau
Updated Branches:
  refs/heads/master 96fae4f98 -> 8574ebab3


Improve efficiency of RestMethod initialization.

Project: http://git-wip-us.apache.org/repos/asf/juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/juneau/commit/8574ebab
Tree: http://git-wip-us.apache.org/repos/asf/juneau/tree/8574ebab
Diff: http://git-wip-us.apache.org/repos/asf/juneau/diff/8574ebab

Branch: refs/heads/master
Commit: 8574ebab313380d9d7a8cafc9fbfac2db6e03e8f
Parents: 96fae4f
Author: JamesBognar <jamesbognar@apache.org>
Authored: Fri Jan 5 23:03:53 2018 -0500
Committer: JamesBognar <jamesbognar@apache.org>
Committed: Fri Jan 5 23:03:53 2018 -0500

----------------------------------------------------------------------
 .../org/apache/juneau/rest/RestJavaMethod.java  | 30 +++++-----
 .../org/apache/juneau/rest/RestRequest.java     | 60 +++++++-------------
 2 files changed, 39 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/juneau/blob/8574ebab/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java
index e172e69..6d35555 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestJavaMethod.java
@@ -45,7 +45,6 @@ import org.apache.juneau.utils.*;
  * Represents a single Java servlet/resource method annotated with {@link RestMethod @RestMethod}.
  */
 class RestJavaMethod implements Comparable<RestJavaMethod>  {
-	private final java.lang.reflect.Method method;
 	private final String httpMethod;
 	private final UrlPathPattern pathPattern;
 	private final RestParam[] params;
@@ -53,24 +52,30 @@ class RestJavaMethod implements Comparable<RestJavaMethod>  {
 	private final RestMatcher[] optionalMatchers;
 	private final RestMatcher[] requiredMatchers;
 	private final RestConverter[] converters;
-	private final SerializerGroup serializers;
-	private final ParserGroup parsers;
-	private final EncoderGroup encoders;
-	private final HttpPartParser partParser;
 	private final HttpPartSerializer partSerializer;
 	private final ObjectMap properties;
-	private final Map<String,Object> defaultRequestHeaders, defaultQuery, defaultFormData;
-	private final String defaultCharset;
-	private final long maxInput;
 	private final boolean deprecated;
 	private final String description, tags, summary, externalDocs;
 	private final Integer priority;
 	private final org.apache.juneau.rest.annotation.Parameter[] parameters;
 	private final Response[] responses;
 	private final RestContext context;
-	private final BeanContext beanContext;
-	private final Map<String,Widget> widgets;
-	private final List<MediaType> supportedAcceptTypes, supportedContentTypes;
+	final java.lang.reflect.Method method;
+	final SerializerGroup serializers;
+	final ParserGroup parsers;
+	final EncoderGroup encoders;
+	final HttpPartParser partParser;
+	final Map<String,Object> 
+		defaultRequestHeaders,
+		defaultQuery,
+		defaultFormData;
+	final String defaultCharset;
+	final long maxInput;
+	final BeanContext beanContext;
+	final Map<String,Widget> widgets;
+	final List<MediaType> 
+		supportedAcceptTypes,
+		supportedContentTypes;
 
 	RestJavaMethod(Object servlet, java.lang.reflect.Method method, RestContext context) throws
RestServletException {
 		Builder b = new Builder(servlet, method, context);
@@ -793,8 +798,7 @@ class RestJavaMethod implements Comparable<RestJavaMethod>  {
 
 		ObjectMap requestProperties = new ResolvingObjectMap(req.getVarResolverSession()).setInner(properties);
 
-		req.init(method, requestProperties, defaultRequestHeaders, defaultQuery, defaultFormData,
defaultCharset,
-			maxInput, serializers, parsers, partParser, beanContext, encoders, widgets, supportedAcceptTypes,
supportedContentTypes);
+		req.init(this, requestProperties);
 		res.init(requestProperties, defaultCharset, serializers, partSerializer, encoders);
 
 		// Class-level guards

http://git-wip-us.apache.org/repos/asf/juneau/blob/8574ebab/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 226b100..d8f5ad3 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
@@ -74,29 +74,24 @@ import org.apache.juneau.utils.*;
 public final class RestRequest extends HttpServletRequestWrapper {
 
 	private final RestContext context;
+	private RestJavaMethod restJavaMethod;
 
 	private final String method;
 	private RequestBody body;
 	private Method javaMethod;
 	private ObjectMap properties;
-	private SerializerGroup serializerGroup;
-	private ParserGroup parserGroup;
 	private final boolean debug;
-	private HttpPartParser partParser;
 	private BeanSession beanSession;
 	private VarResolverSession varSession;
 	private final RequestQuery queryParams;
 	private RequestFormData formData;
-	private Map<String,Object> defFormData;
 	private RequestPathMatch pathParams;
 	private boolean isPost;
 	private UriContext uriContext;
-	private String charset, defaultCharset;
+	private String charset;
 	private RequestHeaders headers;
 	private ConfigFile cf;
 	private Swagger swagger, fileSwagger;
-	private Map<String,Widget> widgets;
-	private List<MediaType> supportedContentTypes, supportedAcceptTypes;
 
 	/**
 	 * Constructor.
@@ -160,40 +155,29 @@ public final class RestRequest extends HttpServletRequestWrapper {
 	/*
 	 * Called from RestServlet after a match has been made but before the guard or method invocation.
 	 */
-	final void init(Method javaMethod, ObjectMap properties, Map<String,Object> defHeader,
-			Map<String,Object> defQuery, Map<String,Object> defFormData, String defaultCharset,
long maxInput,
-			SerializerGroup mSerializers, ParserGroup mParsers, HttpPartParser mUrlEncodingParser,
-			BeanContext beanContext, EncoderGroup encoders, Map<String,Widget> widgets, List<MediaType>
supportedAcceptTypes, 
-			List<MediaType> supportedContentTypes) {
-		this.javaMethod = javaMethod;
+	final void init(RestJavaMethod rjm, ObjectMap properties) {
+		this.restJavaMethod = rjm;
+		this.javaMethod = rjm.method;
 		this.properties = properties;
-		this.partParser = mUrlEncodingParser;
-		this.beanSession = beanContext.createSession();
+		this.beanSession = rjm.beanContext.createSession();
 		this.pathParams
-			.setParser(partParser)
+			.setParser(rjm.partParser)
 			.setBeanSession(beanSession);
 		this.queryParams
-			.addDefault(defQuery)
-			.setParser(partParser)
+			.addDefault(rjm.defaultQuery)
+			.setParser(rjm.partParser)
 			.setBeanSession(beanSession);
 		this.headers
-			.addDefault(defHeader)
+			.addDefault(rjm.defaultRequestHeaders)
 			.addDefault(context.getDefaultRequestHeaders())
-			.setParser(partParser)
+			.setParser(rjm.partParser)
 			.setBeanSession(beanSession);
 		this.body
-			.setEncoders(encoders)
-			.setParsers(mParsers)
+			.setEncoders(rjm.encoders)
+			.setParsers(rjm.parsers)
 			.setHeaders(headers)
 			.setBeanSession(beanSession)
-			.setMaxInput(maxInput);
-		this.serializerGroup = mSerializers;
-		this.parserGroup = mParsers;
-		this.defaultCharset = defaultCharset;
-		this.defFormData = defFormData;
-		this.widgets = widgets;
-		this.supportedAcceptTypes = supportedAcceptTypes;
-		this.supportedContentTypes = supportedContentTypes;
+			.setMaxInput(rjm.maxInput);
 
 		String stylesheet = getQuery().getString("stylesheet");
 		if (stylesheet != null)
@@ -310,7 +294,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
 	 * @return The set of media types registered in the serializer group of this request.
 	 */
 	public List<MediaType> getSupportedAcceptTypes() {
-		return supportedAcceptTypes;
+		return restJavaMethod.supportedAcceptTypes;
 	}
 
 	/**
@@ -319,7 +303,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
 	 * @return The set of media types registered in the parser group of this request.
 	 */
 	public List<MediaType> getSupportedContentTypes() {
-		return supportedContentTypes;
+		return restJavaMethod.supportedContentTypes;
 	}
 
 	/**
@@ -346,7 +330,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
 					charset = h.substring(i+9).trim();
 			}
 			if (charset == null)
-				charset = defaultCharset;
+				charset = restJavaMethod.defaultCharset;
 			if (! Charset.isSupported(charset))
 				throw new RestException(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header ''Content-Type'':
''{0}''", h);
 		}
@@ -424,7 +408,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
 		try {
 			if (formData == null) {
 				formData = new RequestFormData();
-				formData.setParser(partParser).setBeanSession(beanSession);
+				formData.setParser(restJavaMethod.partParser).setBeanSession(beanSession);
 				if (! body.isLoaded()) {
 					formData.putAll(getParameterMap());
 				} else {
@@ -435,7 +419,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
 					}
 				}
 			}
-			formData.addDefault(defFormData);
+			formData.addDefault(restJavaMethod.defaultFormData);
 			return formData;
 		} catch (Exception e) {
 			throw new RestException(SC_INTERNAL_SERVER_ERROR, e);
@@ -712,7 +696,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
 	 * @return The serializers associated with this request.
 	 */
 	public SerializerGroup getSerializerGroup() {
-		return serializerGroup;
+		return restJavaMethod.serializers;
 	}
 
 	/**
@@ -721,7 +705,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
 	 * @return The parsers associated with this request.
 	 */
 	public ParserGroup getParserGroup() {
-		return parserGroup;
+		return restJavaMethod.parsers;
 	}
 
 
@@ -954,7 +938,7 @@ public final class RestRequest extends HttpServletRequestWrapper {
 	 * 	Never <jk>null</jk>.
 	 */
 	public Map<String,Widget> getWidgets() {
-		return widgets;
+		return restJavaMethod.widgets;
 	}
 
 	/**


Mime
View raw message