juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject juneau git commit: RestContext refactor.
Date Mon, 01 Jan 2018 19:12:43 GMT
Repository: juneau
Updated Branches:
  refs/heads/master f5eccb628 -> 81b4bba84


RestContext refactor.

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

Branch: refs/heads/master
Commit: 81b4bba84a49aef7125b4f08756fde225da42ebc
Parents: f5eccb6
Author: JamesBognar <jamesbognar@apache.org>
Authored: Mon Jan 1 14:12:39 2018 -0500
Committer: JamesBognar <jamesbognar@apache.org>
Committed: Mon Jan 1 14:12:39 2018 -0500

----------------------------------------------------------------------
 .../org/apache/juneau/rest/RestContext.java     | 145 +++++++++----------
 .../apache/juneau/rest/RestContextBuilder.java  |   4 +-
 .../juneau/rest/annotation/RestResource.java    |   3 -
 3 files changed, 73 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/juneau/blob/81b4bba8/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 64c041e..54eff02 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
@@ -760,55 +760,81 @@ public final class RestContext extends BeanContext {
 		super(builder.getPropertyStore());
 		
 		RestException _initException = null;
-		ServletContext servletContext = builder.servletContext;
-
-		this.resource = builder.resource;
-		this.builder = builder;
-		this.parentContext = builder.parentContext;
 		
-		PropertyStore ps = getPropertyStore();
+		try {
+			ServletContext servletContext = builder.servletContext;
 
-		contextPath = nullIfEmpty(getProperty(REST_contextPath, String.class, null));
-		allowHeaderParams = getProperty(REST_allowHeaderParams, boolean.class, true);
-		allowBodyParam = getProperty(REST_allowBodyParam, boolean.class, true);
-		allowedMethodParams = Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(StringUtils.split(getProperty(REST_allowedMethodParams,
String.class, "HEAD,OPTIONS")))));
-		renderResponseStackTraces = getProperty(REST_renderResponseStackTraces, boolean.class,
false);
-		useStackTraceHashes = getProperty(REST_useStackTraceHashes, boolean.class, true);
-		defaultCharset = getProperty(REST_defaultCharset, String.class, "utf-8");
-		maxInput = getProperty(REST_maxInput, long.class, 100_000_000l);
-		clientVersionHeader = getProperty(REST_clientVersionHeader, String.class, "X-Client-Version");
-
-		converters = getInstanceArrayProperty(REST_converters, resource, RestConverter.class, new
RestConverter[0], true, ps);
-		guards = getInstanceArrayProperty(REST_guards, resource, RestGuard.class, new RestGuard[0],
true, ps);
-		responseHandlers = getInstanceArrayProperty(REST_responseHandlers, resource, ResponseHandler.class,
new ResponseHandler[0], true, ps);
-
-		Map<Class<?>,RestParam> _paramResolvers = new HashMap<>();
-		for (RestParam rp : getInstanceArrayProperty(REST_paramResolvers, RestParam.class, new
RestParam[0], true, ps)) 
-			_paramResolvers.put(rp.forClass(), rp);
-		paramResolvers = Collections.unmodifiableMap(_paramResolvers);
-		
-		Map<String,String> _defaultRequestHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
-		_defaultRequestHeaders.putAll(getMapProperty(REST_defaultRequestHeaders, String.class));
-		defaultRequestHeaders = Collections.unmodifiableMap(new LinkedHashMap<>(_defaultRequestHeaders));
-		
-		defaultResponseHeaders = getMapProperty(REST_defaultResponseHeaders, String.class);
-		
-		logger = getInstanceProperty(REST_logger, resource, RestLogger.class, RestLogger.NoOp.class,
false);
+			this.resource = builder.resource;
+			this.builder = builder;
+			this.parentContext = builder.parentContext;
+			
+			PropertyStore ps = getPropertyStore();
+
+			contextPath = nullIfEmpty(getProperty(REST_contextPath, String.class, null));
+			allowHeaderParams = getProperty(REST_allowHeaderParams, boolean.class, true);
+			allowBodyParam = getProperty(REST_allowBodyParam, boolean.class, true);
+			allowedMethodParams = Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(StringUtils.split(getProperty(REST_allowedMethodParams,
String.class, "HEAD,OPTIONS")))));
+			renderResponseStackTraces = getProperty(REST_renderResponseStackTraces, boolean.class,
false);
+			useStackTraceHashes = getProperty(REST_useStackTraceHashes, boolean.class, true);
+			defaultCharset = getProperty(REST_defaultCharset, String.class, "utf-8");
+			maxInput = getProperty(REST_maxInput, long.class, 100_000_000l);
+			clientVersionHeader = getProperty(REST_clientVersionHeader, String.class, "X-Client-Version");
+
+			converters = getInstanceArrayProperty(REST_converters, resource, RestConverter.class,
new RestConverter[0], true, ps);
+			guards = getInstanceArrayProperty(REST_guards, resource, RestGuard.class, new RestGuard[0],
true, ps);
+			responseHandlers = getInstanceArrayProperty(REST_responseHandlers, resource, ResponseHandler.class,
new ResponseHandler[0], true, ps);
+
+			Map<Class<?>,RestParam> _paramResolvers = new HashMap<>();
+			for (RestParam rp : getInstanceArrayProperty(REST_paramResolvers, RestParam.class, new
RestParam[0], true, ps)) 
+				_paramResolvers.put(rp.forClass(), rp);
+			paramResolvers = Collections.unmodifiableMap(_paramResolvers);
+			
+			Map<String,String> _defaultRequestHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+			_defaultRequestHeaders.putAll(getMapProperty(REST_defaultRequestHeaders, String.class));
+			defaultRequestHeaders = Collections.unmodifiableMap(new LinkedHashMap<>(_defaultRequestHeaders));
+			
+			defaultResponseHeaders = getMapProperty(REST_defaultResponseHeaders, String.class);
+			
+			logger = getInstanceProperty(REST_logger, resource, RestLogger.class, RestLogger.NoOp.class,
false);
+
+			varResolver = builder.varResolverBuilder
+				.vars(
+					FileVar.class, 
+					LocalizationVar.class, 
+					RequestAttributeVar.class, 
+					RequestFormDataVar.class, 
+					RequestHeaderVar.class, 
+					RequestPathVar.class, 
+					RequestQueryVar.class, 
+					RequestVar.class,
+					RestInfoVar.class,
+					SerializedRequestAttrVar.class, 
+					ServletInitParamVar.class, 
+					UrlVar.class, 
+					UrlEncodeVar.class, 
+					WidgetVar.class
+				)
+				.build()
+			;
 
-		try {
-			this.resourceFinder = new ResourceFinder(resource.getClass());
+			configFile = builder.configFile.getResolving(this.varResolver);
+			
+			properties = builder.properties;
+			serializers = builder.serializers.apply(ps).add(properties).build();
+			parsers = builder.parsers.apply(ps).add(properties).build();
+			partSerializer = resolve(resource, HttpPartSerializer.class, builder.partSerializer, serializers.getPropertyStore());
+			partParser = resolve(resource, HttpPartParser.class, builder.partParser, parsers.getPropertyStore());
+			encoders = builder.encoders.build();
+			beanContext = BeanContext.create().apply(ps).add(properties).build();
+
+			mimetypesFileTypeMap = builder.mimeTypes;
+			
+			resourceFinder = new ResourceFinder(resource.getClass());
+
+			supportedContentTypes = getListProperty(REST_supportedContentTypes, MediaType.class, serializers.getSupportedMediaTypes());
+			supportedAcceptTypes = getListProperty(REST_supportedAcceptTypes, MediaType.class, parsers.getSupportedMediaTypes());
 
 			Builder b = new Builder(builder, ps);
-			this.varResolver = b.varResolver;
-			this.configFile = b.configFile;
-			this.properties = b.properties;
-			this.serializers = b.serializers;
-			this.parsers = b.parsers;
-			this.partSerializer = b.partSerializer;
-			this.partParser = b.partParser;
-			this.encoders = b.encoders;
-			this.beanContext = b.beanContext;
-			this.mimetypesFileTypeMap = b.mimetypesFileTypeMap;
 			this.staticFilesMap = Collections.unmodifiableMap(b.staticFilesMap);
 			this.staticFilesPrefixes = b.staticFilesPrefixes;
 			this.msgs = b.messageBundle;
@@ -816,9 +842,6 @@ public final class RestContext extends BeanContext {
 			this.fullPath = b.fullPath;
 			this.widgets = Collections.unmodifiableMap(b.widgets);
 
-			supportedContentTypes = getListProperty(REST_supportedContentTypes, MediaType.class, serializers.getSupportedMediaTypes());
-			supportedAcceptTypes = getListProperty(REST_supportedAcceptTypes, MediaType.class, parsers.getSupportedMediaTypes());
-
 			//----------------------------------------------------------------------------------------------------
 			// Initialize the child resources.
 			// Done after initializing fields above since we pass this object to the child resources.
@@ -1072,17 +1095,6 @@ public final class RestContext extends BeanContext {
 
 	private static final class Builder {
 
-		VarResolver varResolver;
-		ConfigFile configFile;
-		ObjectMap properties;
-		SerializerGroup serializers;
-		ParserGroup parsers;
-		HttpPartSerializer partSerializer;
-		HttpPartParser partParser;
-		EncoderGroup encoders;
-
-		BeanContext beanContext;
-		MimetypesFileTypeMap mimetypesFileTypeMap;
 		Map<String,String> staticFilesMap;
 		String[] staticFilesPrefixes;
 		MessageBundle messageBundle;
@@ -1095,14 +1107,6 @@ public final class RestContext extends BeanContext {
 			Object resource = rcb.resource;
 			
 			LinkedHashMap<Class<?>,RestResource> restResourceAnnotationsChildFirst = findAnnotationsMap(RestResource.class,
resource.getClass());
-
-			varResolver = rcb.varResolverBuilder
-				.vars(FileVar.class, LocalizationVar.class, RequestVar.class, SerializedRequestAttrVar.class,
ServletInitParamVar.class, UrlVar.class, UrlEncodeVar.class, WidgetVar.class)
-				.build()
-			;
-			
-			configFile = rcb.configFile.getResolving(this.varResolver);
-			properties = rcb.properties;
 			
 			// Find resource resource bundle location.
 			for (Map.Entry<Class<?>,RestResource> e : restResourceAnnotationsChildFirst.entrySet())
{
@@ -1119,15 +1123,6 @@ public final class RestContext extends BeanContext {
 			if (messageBundle == null)
 				messageBundle = new MessageBundle(resource.getClass(), "");
 			
-			serializers = rcb.serializers.apply(ps).add(properties).build();
-			parsers = rcb.parsers.apply(ps).add(properties).build();
-			partSerializer = resolve(resource, HttpPartSerializer.class, rcb.partSerializer, serializers.getPropertyStore());
-			partParser = resolve(resource, HttpPartParser.class, rcb.partParser, parsers.getPropertyStore());
-			encoders = rcb.encoders.build();
-			beanContext = BeanContext.create().apply(ps).add(properties).build();
-
-			mimetypesFileTypeMap = rcb.mimeTypes;
-
 			VarResolver vr = rcb.getVarResolverBuilder().build();
 
 			staticFilesMap = new LinkedHashMap<>();

http://git-wip-us.apache.org/repos/asf/juneau/blob/81b4bba8/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
----------------------------------------------------------------------
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
index bb2fd45..8a682fe 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
@@ -102,7 +102,9 @@ public class RestContextBuilder extends BeanContextBuilder implements
ServletCon
 
 	SerializerGroupBuilder serializers = SerializerGroup.create();
 	ParserGroupBuilder parsers = ParserGroup.create();
-	Object partSerializer = SimpleUonPartSerializer.class, partParser = UonPartParser.class;
+	Object 
+		partSerializer = SimpleUonPartSerializer.class, 
+		partParser = UonPartParser.class;
 	EncoderGroupBuilder encoders = EncoderGroup.create().append(IdentityEncoder.INSTANCE);
 
 	MimetypesFileTypeMap mimeTypes = new ExtendedMimetypesFileTypeMap();

http://git-wip-us.apache.org/repos/asf/juneau/blob/81b4bba8/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 b6335bd..a823e5b 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
@@ -706,9 +706,6 @@ public @interface RestResource {
 	 * 	<li>Annotation:  {@link RestResource#parserListener()} 
 	 * 	<li>Method: {@link RestContextBuilder#parserListener(Class)} 
 	 *	</ul>
-	 *
-	 * @param listener The listener to add to this config.
-	 * @return This object (for method chaining).
 	 */
 	Class<? extends ParserListener> parserListener() default ParserListener.Null.class;
 


Mime
View raw message