package org.apache.catalina;
+import javax.servlet.MultipartConfigElement;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
public void unload() throws ServletException;
+ /**
+ * Get the multi-part configuration for the associated servlet. If no
+ * multi-part configuration has been defined, then <code>null</code> will be
+ * returned.
+ */
+ public MultipartConfigElement getMultipartConfig();
+
+
+ /**
+ * 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);
}
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.FilterChain;
+import javax.servlet.MultipartConfigElement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.tomcat.util.http.FastHttpDateFormat;
import org.apache.tomcat.util.http.Parameters;
import org.apache.tomcat.util.http.ServerCookie;
+import org.apache.tomcat.util.http.fileupload.FileUploadBase;
import org.apache.tomcat.util.http.mapper.MappingData;
import org.apache.tomcat.util.res.StringManager;
+import org.apache.tools.ant.util.CollectionUtils;
/**
public Collection<Part> getParts() throws IOException, IllegalStateException,
ServletException {
+
+ String contentType = getContentType();
+ if (contentType == null ||
+ !contentType.startsWith(FileUploadBase.MULTIPART_FORM_DATA)) {
+ return Collections.emptyList();
+ }
+
+ MultipartConfigElement mce = getWrapper().getMultipartConfig();
+ if (mce == null) {
+ return Collections.emptyList();
+ }
+
// TODO SERVLET3 - file upload
- return null;
+ return Collections.emptyList();
}
public Part getPart(String name) throws IOException, IllegalStateException,
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
+import javax.servlet.MultipartConfigElement;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
protected int classLoadTime=0;
/**
+ * Multipart config
+ */
+ protected MultipartConfigElement multipartConfig = null;
+
+ /**
* Static class array used when the SecurityManager is turned on and
* <code>Servlet.init</code> is invoked.
*/
return classLoadTime;
}
+ public MultipartConfigElement getMultipartConfig() {
+ return multipartConfig;
+ }
+
+ public void setMultipartConfig(MultipartConfigElement multipartConfig) {
+ this.multipartConfig = multipartConfig;
+ }
+
// -------------------------------------------------------- Package Methods
}
- private Long maxFileSize;
+ private String maxFileSize;
- public Long getMaxFileSize() {
+ public String getMaxFileSize() {
return maxFileSize;
}
- public void setMaxFileSize(Long maxFileSize) {
+ public void setMaxFileSize(String maxFileSize) {
this.maxFileSize = maxFileSize;
}
- private Long maxRequestSize;
+ private String maxRequestSize;
- public Long getMaxRequestSize() {
+ public String getMaxRequestSize() {
return maxRequestSize;
}
- public void setMaxRequestSize(Long maxRequestSize) {
+ public void setMaxRequestSize(String maxRequestSize) {
this.maxRequestSize = maxRequestSize;
}
- private Integer fileSizeThreshold;
+ private String fileSizeThreshold;
- public Integer getFileSizeThreshold() {
+ public String getFileSizeThreshold() {
return fileSizeThreshold;
}
- public void setFileSizeThreshold(Integer fileSizeThreshold) {
+ public void setFileSizeThreshold(String fileSizeThreshold) {
this.fileSizeThreshold = fileSizeThreshold;
}
-
+
// ---------------------------------------------------------- Object methods
@Override
/**
* The multipart configuration, if any, for this servlet
*/
- private MultipartDef multipartDef = new MultipartDef();
+ private MultipartDef multipartDef = null;
public MultipartDef getMultipartDef() {
return this.multipartDef;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import javax.servlet.http.Part;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
return buffer.toString();
}
- protected String upload(HttpServletRequest request) throws IOException {
+ protected String upload(HttpServletRequest request)
+ throws IOException, ServletException {
String message = "";
+ // TODO - Rewrite this to use the Servlet 3 file upload API
+ Part part = request.getPart("deployWar");
+
// Get the tempdir
File tempdir = (File) getServletContext().getAttribute
(ServletContext.TEMPDIR);
digester.addObjectCreate(fullPrefix + "/servlet/multipart-config",
"org.apache.catalina.deploy.MultipartDef");
digester.addSetNext(fullPrefix + "/servlet/multipart-config",
- "setMultipartConfig");
+ "setMultipartDef",
+ "org.apache.catalina.deploy.MultipartDef");
digester.addCallMethod(fullPrefix + "/servlet/multipart-config/location",
"setLocation", 0);
digester.addCallMethod(fullPrefix + "/servlet/multipart-config/max-file-size",
import java.util.Map;
import java.util.Set;
+import javax.servlet.MultipartConfigElement;
+
import org.apache.catalina.Context;
import org.apache.catalina.Wrapper;
import org.apache.catalina.deploy.ContextEjb;
roleRef.getName(), roleRef.getLink());
}
wrapper.setServletClass(servlet.getServletClass());
- // TODO SERVLET3 - Multipart config
+ MultipartDef multipartdef = servlet.getMultipartDef();
+ if (multipartdef != null) {
+ if (multipartdef.getMaxFileSize() != null &&
+ multipartdef.getMaxRequestSize()!= null &&
+ multipartdef.getFileSizeThreshold() != null) {
+ wrapper.setMultipartConfig(new MultipartConfigElement(
+ multipartdef.getLocation(),
+ Long.parseLong(multipartdef.getMaxFileSize()),
+ Long.parseLong(multipartdef.getMaxRequestSize()),
+ Integer.parseInt(
+ multipartdef.getFileSizeThreshold())));
+ } else {
+ wrapper.setMultipartConfig(new MultipartConfigElement(
+ multipartdef.getLocation()));
+ }
+ }
context.addChild(wrapper);
}
for (String pattern : servletMappings.keySet()) {
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- version="2.5">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
<display-name>Tomcat Manager Application</display-name>
<description>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
+ <multipart-config>
+ <!-- 50MB max -->
+ <max-file-size>52428800</max-file-size>
+ <max-request-size>52428800</max-request-size>
+ <file-size-threshold>0</file-size-threshold>
+ </multipart-config>
</servlet>
<servlet>
<servlet-name>Status</servlet-name>