Revision: 809
http://stripes.svn.sourceforge.net/stripes/?rev=809&view=rev
Author: bengunter
Date: 2008-01-24 14:17:54 -0800 (Thu, 24 Jan 2008)
Log Message:
-----------
Fixed STS-491. If no wrapper is configured then DefaultMultipartWrapperFactory
tries Commons and then COS, using the first one to load successfully. Changes
were made to those two implementations to ensure they do not load if the
supporting library is not present on the classpath.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CommonsMultipartWrapper.java
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CosMultipartWrapper.java
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/DefaultMultipartWrapperFactory.java
Modified:
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CommonsMultipartWrapper.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CommonsMultipartWrapper.java
2008-01-24 20:37:12 UTC (rev 808)
+++
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CommonsMultipartWrapper.java
2008-01-24 22:17:54 UTC (rev 809)
@@ -46,6 +46,12 @@
*/
public class CommonsMultipartWrapper implements MultipartWrapper {
private static final Pattern WINDOWS_PATH_PREFIX_PATTERN =
Pattern.compile("(?i:^[A-Z]:\\\\)");
+
+ /** Ensure this class will not load unless Commons FileUpload is on the
classpath. */
+ static {
+ FileUploadException.class.getName();
+ }
+
private Map<String,FileItem> files = new HashMap<String,FileItem>();
private Map<String,String[]> parameters = new HashMap<String, String[]>();
private String charset;
Modified:
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CosMultipartWrapper.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CosMultipartWrapper.java
2008-01-24 20:37:12 UTC (rev 808)
+++
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CosMultipartWrapper.java
2008-01-24 22:17:54 UTC (rev 809)
@@ -42,6 +42,11 @@
private static Pattern EXCEPTION_PATTERN =
Pattern.compile("Posted content length of (\\d*) exceeds limit of
(\\d*)");
+ /** Ensure this class will not load unless COS is on the classpath. */
+ static {
+ MultipartRequest.class.getName();
+ }
+
private MultipartRequest multipart;
private String charset;
/**
Modified:
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/DefaultMultipartWrapperFactory.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/DefaultMultipartWrapperFactory.java
2008-01-24 20:37:12 UTC (rev 808)
+++
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/DefaultMultipartWrapperFactory.java
2008-01-24 22:17:54 UTC (rev 809)
@@ -38,9 +38,10 @@
/** The configuration key used to lookup the implementation of
MultipartWrapper. */
public static final String WRAPPER_CLASS_NAME = "MultipartWrapper.Class";
- /** The name of the MultipartWrapper class that will be used if no other
is specified. */
- public static final String DEFAULT_IMPLEMENTATION =
- "net.sourceforge.stripes.controller.multipart.CosMultipartWrapper";
+ /** The names of the MultipartWrapper classes that will be tried if no
other is specified. */
+ public static final String[] BUNDLED_IMPLEMENTATIONS = {
+
"net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper",
+ "net.sourceforge.stripes.controller.multipart.CosMultipartWrapper"
};
/** Key used to lookup the name of the maximum post size. */
public static final String MAX_POST = "FileUpload.MaximumPostSize";
@@ -64,14 +65,28 @@
public void init(Configuration config) throws Exception {
// Determine which class we're using
String type =
config.getBootstrapPropertyResolver().getProperty(WRAPPER_CLASS_NAME);
- if (type == null) type = DEFAULT_IMPLEMENTATION;
- try {
- this.multipartClass = (Class<? extends MultipartWrapper>)
Class.forName(type);
+ String[] candidates = type == null ? BUNDLED_IMPLEMENTATIONS : new
String[] { type };
+ for (String className : candidates) {
+ try {
+ this.multipartClass = ((Class<? extends MultipartWrapper>)
Class.forName(className));
+ break;
+ }
+ catch (Throwable t) {
+ log.debug(getClass().getSimpleName(), " not using ", className,
+ " because it failed to load. This likely means the
supporting ",
+ "file upload library is not present on the
classpath.");
+ }
}
- catch (ClassNotFoundException cnfe) {
- throw new StripesRuntimeException
- ("Could not find configured MultipartWrapper type '" +
type + "'.", cnfe);
+
+ // Log the name of the class we'll be using or a warning if none could
be loaded
+ if (this.multipartClass == null) {
+ log.warn("No ", MultipartWrapper.class.getSimpleName(),
+ " implementation could be loaded");
}
+ else {
+ log.info("Using ", this.multipartClass.getName(), " as ",
MultipartWrapper.class
+ .getSimpleName(), " implementation.");
+ }
// Figure out where the temp directory is, and store that info
File tempDir = (File)
config.getServletContext().getAttribute("javax.servlet.context.tempdir");
@@ -128,7 +143,7 @@
catch (FileUploadLimitExceededException fulee) { throw fulee; }
catch (Exception e) {
throw new StripesRuntimeException
- ("Could not construct a MultipartWrapper for the " +
"current request.", e);
+ ("Could not construct a MultipartWrapper for the current
request.", e);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development