Add support for the MultipartConfig annotation
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 3 Dec 2009 15:25:54 +0000 (15:25 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 3 Dec 2009 15:25:54 +0000 (15:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@886814 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/Wrapper.java
java/org/apache/catalina/connector/Request.java
java/org/apache/catalina/core/StandardWrapper.java
java/org/apache/catalina/startup/WebXml.java

index 465924e..bd68437 100644 (file)
@@ -340,12 +340,12 @@ public interface Wrapper extends Container {
      * multi-part configuration has been defined, then <code>null</code> will be
      * returned.
      */
-    public MultipartConfigElement getMultipartConfig();
+    public MultipartConfigElement getMultipartConfigElement();
     
     
     /**
      * Set the multi-part configuration for the associated servlet. To clear the
      * multi-part configuration specify <code>null</code> as the new value.
      */
-    public void setMultipartConfig(MultipartConfigElement multipartConfig);
+    public void setMultipartConfigElement(MultipartConfigElement multipartConfig);
 }
index 743655e..47f481a 100644 (file)
@@ -2393,12 +2393,19 @@ public class Request
     public Collection<Part> getParts() throws IOException, IllegalStateException,
             ServletException {
         
-        MultipartConfigElement mce = getWrapper().getMultipartConfig();
+        MultipartConfigElement mce = getWrapper().getMultipartConfigElement();
         if (mce == null) {
             return Collections.emptyList();
         }
         
-        File location = new File(mce.getLocation());
+        File location;
+        String locationStr = mce.getLocation();
+        if (locationStr == null || locationStr.length() == 0) {
+            location = ((File) context.getServletContext().getAttribute(
+                    ServletContext.TEMPDIR));
+        } else {
+            location = new File(locationStr);
+        }
         
         if (!location.isAbsolute() || !location.isDirectory()) {
             throw new IOException(
index 1ab5b02..90435d6 100644 (file)
@@ -44,6 +44,7 @@ import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.SingleThreadModel;
 import javax.servlet.UnavailableException;
+import javax.servlet.annotation.MultipartConfig;
 
 import org.apache.catalina.Container;
 import org.apache.catalina.ContainerServlet;
@@ -258,7 +259,7 @@ public class StandardWrapper
     /**
      * Multipart config
      */
-    protected MultipartConfigElement multipartConfig = null;
+    protected MultipartConfigElement multipartConfigElement = null;
 
     /**
      * Static class array used when the SecurityManager is turned on and 
@@ -1052,6 +1053,15 @@ public class StandardWrapper
                     (sm.getString("standardWrapper.instantiate", actualClass), e);
             }
 
+            if (multipartConfigElement == null) {
+                MultipartConfig annotation =
+                        servlet.getClass().getAnnotation(MultipartConfig.class);
+                if (annotation != null) {
+                    multipartConfigElement =
+                            new MultipartConfigElement(annotation);
+                }
+            }
+
             // Special handling for ContainerServlet instances
             if ((servlet instanceof ContainerServlet) &&
                   (isContainerProvidedServlet(actualClass) ||
@@ -1483,12 +1493,13 @@ public class StandardWrapper
         return classLoadTime;
     }
 
-    public MultipartConfigElement getMultipartConfig() {
-        return multipartConfig;
+    public MultipartConfigElement getMultipartConfigElement() {
+        return multipartConfigElement;
     }
 
-    public void setMultipartConfig(MultipartConfigElement multipartConfig) {
-        this.multipartConfig = multipartConfig;
+    public void setMultipartConfigElement(
+            MultipartConfigElement multipartConfigElement) {
+        this.multipartConfigElement = multipartConfigElement;
     }
 
     // -------------------------------------------------------- Package Methods
index 8ace5ff..e59e7ab 100644 (file)
@@ -568,23 +568,18 @@ public class WebXml {
             wrapper.setServletClass(servlet.getServletClass());
             MultipartDef multipartdef = servlet.getMultipartDef();
             if (multipartdef != null) {
-                String location = multipartdef.getLocation();
-                if (location == null || location.length() == 0) {
-                    location = ((File) context.getServletContext().getAttribute(
-                            ServletContext.TEMPDIR)).getAbsolutePath();
-                }
                 if (multipartdef.getMaxFileSize() != null &&
                         multipartdef.getMaxRequestSize()!= null &&
                         multipartdef.getFileSizeThreshold() != null) {
-                    wrapper.setMultipartConfig(new MultipartConfigElement(
-                            location,
+                    wrapper.setMultipartConfigElement(new MultipartConfigElement(
+                            multipartdef.getLocation(),
                             Long.parseLong(multipartdef.getMaxFileSize()),
                             Long.parseLong(multipartdef.getMaxRequestSize()),
                             Integer.parseInt(
                                     multipartdef.getFileSizeThreshold())));
                 } else {
-                    wrapper.setMultipartConfig(new MultipartConfigElement(
-                            location));
+                    wrapper.setMultipartConfigElement(new MultipartConfigElement(
+                            multipartdef.getLocation()));
                 }
             }
             context.addChild(wrapper);