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 RestResponse initialization.
Date Sat, 06 Jan 2018 04:13:27 GMT
Repository: juneau
Updated Branches:
  refs/heads/master 8574ebab3 -> 5d827126e


Improve efficiency of RestResponse initialization.

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

Branch: refs/heads/master
Commit: 5d827126e6a9ceebc21770c984097d460e53a64c
Parents: 8574eba
Author: JamesBognar <jamesbognar@apache.org>
Authored: Fri Jan 5 23:13:24 2018 -0500
Committer: JamesBognar <jamesbognar@apache.org>
Committed: Fri Jan 5 23:13:24 2018 -0500

----------------------------------------------------------------------
 .../org/apache/juneau/rest/RestJavaMethod.java  |  4 +--
 .../org/apache/juneau/rest/RestResponse.java    | 27 +++++++++-----------
 2 files changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/juneau/blob/5d827126/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 6d35555..194df12 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
@@ -52,7 +52,6 @@ class RestJavaMethod implements Comparable<RestJavaMethod>  {
 	private final RestMatcher[] optionalMatchers;
 	private final RestMatcher[] requiredMatchers;
 	private final RestConverter[] converters;
-	private final HttpPartSerializer partSerializer;
 	private final ObjectMap properties;
 	private final boolean deprecated;
 	private final String description, tags, summary, externalDocs;
@@ -64,6 +63,7 @@ class RestJavaMethod implements Comparable<RestJavaMethod>  {
 	final SerializerGroup serializers;
 	final ParserGroup parsers;
 	final EncoderGroup encoders;
+	final HttpPartSerializer partSerializer;
 	final HttpPartParser partParser;
 	final Map<String,Object> 
 		defaultRequestHeaders,
@@ -799,7 +799,7 @@ class RestJavaMethod implements Comparable<RestJavaMethod>  {
 		ObjectMap requestProperties = new ResolvingObjectMap(req.getVarResolverSession()).setInner(properties);
 
 		req.init(this, requestProperties);
-		res.init(requestProperties, defaultCharset, serializers, partSerializer, encoders);
+		res.init(this, requestProperties);
 
 		// Class-level guards
 		for (RestGuard guard : context.getGuards())

http://git-wip-us.apache.org/repos/asf/juneau/blob/5d827126/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
index 310d910..15d58da 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
@@ -53,12 +53,10 @@ import org.apache.juneau.serializer.*;
 public final class RestResponse extends HttpServletResponseWrapper {
 
 	private final RestRequest request;
+	private RestJavaMethod restJavaMethod;
 	private Object output;                       // The POJO being sent to the output.
 	private boolean isNullOutput;                // The output is null (as opposed to not being
set at all)
 	private ObjectMap properties;                // Response properties
-	SerializerGroup serializerGroup;
-	HttpPartSerializer partSerializer;
-	private EncoderGroup encoders;
 	private ServletOutputStream os;
 	private PrintWriter w;
 	private HtmlDocBuilder htmlDocBuilder;
@@ -89,22 +87,20 @@ public final class RestResponse extends HttpServletResponseWrapper {
 	/*
 	 * Called from RestServlet after a match has been made but before the guard or method invocation.
 	 */
-	final void init(ObjectMap properties, String defaultCharset, SerializerGroup mSerializers,
HttpPartSerializer partSerializer, EncoderGroup encoders) {
+	final void init(RestJavaMethod rjm, ObjectMap properties) {
+		this.restJavaMethod = rjm;
 		this.properties = properties;
-		this.serializerGroup = mSerializers;
-		this.partSerializer = partSerializer;
-		this.encoders = encoders;
 
 		// Find acceptable charset
 		String h = request.getHeader("accept-charset");
 		String charset = null;
 		if (h == null)
-			charset = defaultCharset;
+			charset = rjm.defaultCharset;
 		else for (MediaTypeRange r : MediaTypeRange.parse(h)) {
 			if (r.getQValue() > 0) {
 				MediaType mt = r.getMediaType();
 				if (mt.getType().equals("*"))
-					charset = defaultCharset;
+					charset = rjm.defaultCharset;
 				else if (Charset.isSupported(mt.getType()))
 					charset = mt.getType();
 				if (charset != null)
@@ -123,7 +119,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
 	 * @return The serializer group for the response.
 	 */
 	public SerializerGroup getSerializerGroup() {
-		return serializerGroup;
+		return restJavaMethod.serializers;
 	}
 
 	/**
@@ -132,7 +128,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
 	 * @return The set of media types registered in the parser group of this request.
 	 */
 	public List<MediaType> getSupportedMediaTypes() {
-		return serializerGroup.getSupportedMediaTypes();
+		return restJavaMethod.supportedAcceptTypes;
 	}
 
 	/**
@@ -143,7 +139,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
 	 * @throws RestServletException
 	 */
 	public List<String> getSupportedEncodings() throws RestServletException {
-		return encoders.getSupportedEncodings();
+		return restJavaMethod.encoders.getSupportedEncodings();
 	}
 
 	/**
@@ -270,10 +266,11 @@ public final class RestResponse extends HttpServletResponseWrapper {
 	public ServletOutputStream getNegotiatedOutputStream() throws IOException {
 		if (os == null) {
 			Encoder encoder = null;
-
+			EncoderGroup encoders = restJavaMethod.encoders;
+			
 			String ae = request.getHeader("Accept-Encoding");
 			if (! (ae == null || ae.isEmpty())) {
-				EncoderMatch match = encoders != null ? encoders.getEncoderMatch(ae) : null;
+				EncoderMatch match = encoders.getEncoderMatch(ae);
 				if (match == null) {
 					// Identity should always match unless "identity;q=0" or "*;q=0" is specified.
 					if (ae.matches(".*(identity|\\*)\\s*;\\s*q\\s*=\\s*(0(?!\\.)|0\\.0).*")) {
@@ -432,7 +429,7 @@ public final class RestResponse extends HttpServletResponseWrapper {
 	 * @return The HTTP-part serializer associated with this response.
 	 */
 	public HttpPartSerializer getPartSerializer() {
-		return partSerializer;
+		return restJavaMethod.partSerializer;
 	}
 
 	@Override /* ServletResponse */


Mime
View raw message