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 refactoring.
Date Fri, 05 Jan 2018 01:26:44 GMT
Repository: juneau
Updated Branches:
  refs/heads/master 9bb2cd718 -> 2225bc052


RestContext refactoring.

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

Branch: refs/heads/master
Commit: 2225bc0523adbca261f9cada046ca8908f3967ac
Parents: 9bb2cd7
Author: JamesBognar <jamesbognar@apache.org>
Authored: Thu Jan 4 20:26:40 2018 -0500
Committer: JamesBognar <jamesbognar@apache.org>
Committed: Thu Jan 4 20:26:40 2018 -0500

----------------------------------------------------------------------
 juneau-doc/src/main/javadoc/overview.html       |  7 ++
 .../org/apache/juneau/rest/RestContext.java     | 47 ++++++++++++-
 .../apache/juneau/rest/RestContextBuilder.java  | 69 ++++++++++++--------
 .../juneau/rest/annotation/RestResource.java    | 36 ++++++++++
 4 files changed, 131 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/juneau/blob/2225bc05/juneau-doc/src/main/javadoc/overview.html
----------------------------------------------------------------------
diff --git a/juneau-doc/src/main/javadoc/overview.html b/juneau-doc/src/main/javadoc/overview.html
index 3f56270..05de119 100644
--- a/juneau-doc/src/main/javadoc/overview.html
+++ b/juneau-doc/src/main/javadoc/overview.html
@@ -7995,6 +7995,8 @@
 					<li>{@link org.apache.juneau.rest.RestContext#REST_staticFileResponseHeaders REST_staticFileResponseHeaders}
 					<li>{@link org.apache.juneau.rest.RestContext#REST_classpathResourceFinder REST_classpathResourceFinder}
 					<li>{@link org.apache.juneau.rest.RestContext#REST_useClasspathResourceCaching
REST_useClasspathResourceCaching}
+					<li>{@link org.apache.juneau.rest.RestContext#REST_widgets REST_widgets}
+					<li>{@link org.apache.juneau.rest.RestContext#REST_mimeTypes REST_mimeTypes}
 				</ul>
 			<li>
 				Support for static files has been simplified and improved.
@@ -8063,6 +8065,11 @@
 						{@link org.apache.juneau.rest.RestRequest#getClasspathReaderResource(String) getClasspathReaderResource(String)}
 				</ul>
 			<li>
+				Changes to {@link org.apache.juneau.rest.annotation.RestResource}:
+				<ul>
+					<li>New {@link org.apache.juneau.rest.annotation.RestResource#mimeTypes() mimeTypes()}
annotation.
+				</ul>
+			<li>
 				Changes to {@link org.apache.juneau.rest.annotation.RestMethod}:
 				<ul>
 					<li>New {@link org.apache.juneau.rest.annotation.RestMethod#supportedAcceptTypes()
supportedAcceptTypes()} and

http://git-wip-us.apache.org/repos/asf/juneau/blob/2225bc05/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 bee4518..91145d9 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
@@ -1049,6 +1049,49 @@ public final class RestContext extends BeanContext {
 	 */
 	public static final String REST_widgets = PREFIX + "widgets.lo";
 	
+	/**
+	 * <b>Configuration property:</b>  MIME types. 
+	 *
+	 * <ul>
+	 * 	<li><b>Name:</b> <js>"RestContext.mimeTypes.ss"</js>
+	 * 	<li><b>Data type:</b> <code>Set&lt;String&gt;</code>
+	 * 	<li><b>Default:</b> empty list
+	 * 	<li><b>Session-overridable:</b> <jk>false</jk>
+	 * </ul>
+	 * 
+	 * <p>
+	 * Defines MIME-type file type mappings.
+	 * 
+	 * <p>
+	 * Used for specifying the content type on file resources retrieved through the following
methods:
+	 * <ul>
+	 * 	<li>{@link RestContext#resolveStaticFile(String)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String,boolean,MediaType)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String,boolean)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String)}
+	 * </ul>
+	 * 
+	 * <p>
+	 * This list appends to the existing list provided by {@link ExtendedMimetypesFileTypeMap}.
+	 * 
+	 * <h6 class='topic'>Notes:</h6>
+	 * <ul class='spaced-list'>
+	 * 	<li>Property:  {@link RestContext#REST_mimeTypes}
+	 * 	<li>Annotations: 
+	 * 		<ul>
+	 * 			<li>{@link RestResource#mimeTypes()} 
+	 * 		</ul>
+	 * 	<li>Methods: 
+	 * 		<ul>
+	 * 			<li>{@link RestContextBuilder#mimeTypes(String...)}
+	 * 		</ul>
+	 * 	<li>Values are .mime.types formatted entry string.
+	 * 		<br>Example: <js>"image/svg+xml svg"</js>
+	 * </ul>
+	 */
+	public static final String REST_mimeTypes = PREFIX + "mimeTypes.ss";
+
+	
 	//-------------------------------------------------------------------------------------------------------------------
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
@@ -1212,7 +1255,9 @@ public final class RestContext extends BeanContext {
 			encoders = builder.encoders.build();
 			beanContext = BeanContext.create().apply(ps).add(properties).build();
 
-			mimetypesFileTypeMap = builder.mimeTypes;
+			mimetypesFileTypeMap = new ExtendedMimetypesFileTypeMap();
+			for (String mimeType : getArrayProperty(REST_mimeTypes, String.class))
+				mimetypesFileTypeMap.addMimeTypes(mimeType);
 			
 			ClasspathResourceFinder rf = getInstanceProperty(REST_classpathResourceFinder, ClasspathResourceFinder.class,
ClasspathResourceFinderBasic.class);
 			boolean useClasspathResourceCaching = getProperty(REST_useClasspathResourceCaching, boolean.class,
true);

http://git-wip-us.apache.org/repos/asf/juneau/blob/2225bc05/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 4b9d602..f36e51e 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
@@ -22,7 +22,6 @@ import static org.apache.juneau.parser.Parser.*;
 import java.lang.reflect.Method;
 import java.util.*;
 
-import javax.activation.*;
 import javax.servlet.*;
 import javax.servlet.http.*;
 
@@ -89,6 +88,7 @@ public class RestContextBuilder extends BeanContextBuilder implements ServletCon
 	Class<?> resourceClass;
 	Object resource;
 	ServletContext servletContext;
+	RestContext parentContext;
 
 	//---------------------------------------------------------------------------
 	// The following fields are meant to be modifiable.
@@ -107,9 +107,7 @@ public class RestContextBuilder extends BeanContextBuilder implements
ServletCon
 		partParser = UonPartParser.class;
 	EncoderGroupBuilder encoders = EncoderGroup.create().append(IdentityEncoder.INSTANCE);
 
-	MimetypesFileTypeMap mimeTypes = new ExtendedMimetypesFileTypeMap();
 	List<Object> childResources = new ArrayList<>();
-	RestContext parentContext;
 	String path;
 	HtmlDocBuilder htmlDocBuilder;
 
@@ -248,6 +246,7 @@ public class RestContextBuilder extends BeanContextBuilder implements
ServletCon
 					defaultCharset(vr.resolve(r.defaultCharset()));
 				if (! r.maxInput().isEmpty())
 					maxInput(vr.resolve(r.maxInput()));
+				mimeTypes(resolveVars(vr, r.mimeTypes()));
 
 				HtmlDoc hd = r.htmldoc();
 				widgets(hd.widgets());
@@ -609,30 +608,6 @@ public class RestContextBuilder extends BeanContextBuilder implements
ServletCon
 	}
 
 	/**
-	 * Adds MIME-type definitions.
-	 *
-	 * <p>
-	 * These definitions are used in the following locations for setting the media type on responses:
-	 * <ul>
-	 * 	<li>{@link RestRequest#getClasspathReaderResource(String)}
-	 * 	<li>Static files resolved through {@link RestResource#staticFiles()}
-	 * </ul>
-	 *
-	 * <p>
-	 * Refer to {@link MimetypesFileTypeMap#addMimeTypes(String)} for an explanation of the
format.
-	 *
-	 * @param mimeTypes The MIME-types to add to this config.
-	 * @return This object (for method chaining).
-	 */
-	public RestContextBuilder mimeTypes(String...mimeTypes) {
-		if (this.mimeTypes == ExtendedMimetypesFileTypeMap.DEFAULT)
-			this.mimeTypes = new ExtendedMimetypesFileTypeMap();
-		for (String mimeType : mimeTypes)
-			this.mimeTypes.addMimeTypes(mimeType);
-		return this;
-	}
-
-	/**
 	 * Adds a child resource to this resource.
 	 *
 	 * <p>
@@ -2390,6 +2365,46 @@ public class RestContextBuilder extends BeanContextBuilder implements
ServletCon
 	}
 
 	/**
+	 * <b>Configuration property:</b>  MIME types. 
+	 *
+	 * <p>
+	 * Defines MIME-type file type mappings.
+	 * 
+	 * <p>
+	 * Used for specifying the content type on file resources retrieved through the following
methods:
+	 * <ul>
+	 * 	<li>{@link RestContext#resolveStaticFile(String)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String,boolean,MediaType)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String,boolean)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String)}
+	 * </ul>
+	 * 
+	 * <p>
+	 * This list appends to the existing list provided by {@link ExtendedMimetypesFileTypeMap}.
+	 * 
+	 * <h6 class='topic'>Notes:</h6>
+	 * <ul class='spaced-list'>
+	 * 	<li>Property:  {@link RestContext#REST_mimeTypes}
+	 * 	<li>Annotations: 
+	 * 		<ul>
+	 * 			<li>{@link RestResource#mimeTypes()} 
+	 * 		</ul>
+	 * 	<li>Methods: 
+	 * 		<ul>
+	 * 			<li>{@link RestContextBuilder#mimeTypes(String...)}
+	 * 		</ul>
+	 * 	<li>Values are .mime.types formatted entry string.
+	 * 		<br>Example: <js>"image/svg+xml svg"</js>
+	 * </ul>
+	 *
+	 * @param mimeTypes The MIME-types to add to this config.
+	 * @return This object (for method chaining).
+	 */
+	public RestContextBuilder mimeTypes(String...mimeTypes) {
+		return addTo(REST_mimeTypes, mimeTypes);
+	}
+
+	/**
 	 * <b>Configuration property:</b>  Serializer listener.
 	 * 
 	 * <p>

http://git-wip-us.apache.org/repos/asf/juneau/blob/2225bc05/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 6fa4ba8..6a55849 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
@@ -1276,4 +1276,40 @@ public @interface RestResource {
 	 *	</ul>
 	 */
 	String maxInput() default "";
+	
+	/**
+	 * <b>Configuration property:</b>  MIME types. 
+	 *
+	 * <p>
+	 * Defines MIME-type file type mappings.
+	 * 
+	 * <p>
+	 * Used for specifying the content type on file resources retrieved through the following
methods:
+	 * <ul>
+	 * 	<li>{@link RestContext#resolveStaticFile(String)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String,boolean,MediaType)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String,boolean)}
+	 * 	<li>{@link RestRequest#getClasspathReaderResource(String)}
+	 * </ul>
+	 * 
+	 * <p>
+	 * This list appends to the existing list provided by {@link ExtendedMimetypesFileTypeMap}.
+	 * 
+	 * <h6 class='topic'>Notes:</h6>
+	 * <ul class='spaced-list'>
+	 * 	<li>Property:  {@link RestContext#REST_mimeTypes}
+	 * 	<li>Annotations: 
+	 * 		<ul>
+	 * 			<li>{@link RestResource#mimeTypes()} 
+	 * 		</ul>
+	 * 	<li>Methods: 
+	 * 		<ul>
+	 * 			<li>{@link RestContextBuilder#mimeTypes(String...)}
+	 * 		</ul>
+	 * 	<li>Values are .mime.types formatted entry string.
+	 * 		<br>Example: <js>"image/svg+xml svg"</js>
+	 * 	<li>Can contain variables.
+	 * </ul>
+	 */
+	String[] mimeTypes() default {};
 }


Mime
View raw message