Author: remy.maucherat(a)jboss.com
Date: 2009-10-11 13:55:58 -0400 (Sun, 11 Oct 2009)
New Revision: 1192
Modified:
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
trunk/java/org/apache/catalina/core/LocalStrings.properties
trunk/java/org/apache/catalina/core/StandardWrapperFacade.java
trunk/java/org/apache/tomcat/util/http/fileupload/DefaultFileItemFactory.java
trunk/java/org/apache/tomcat/util/http/fileupload/DiskFileUpload.java
Log:
- Add error conditions for the registrations.
- Move around some fixmes.
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-10-10 01:01:00 UTC (rev
1191)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-10-11 17:55:58 UTC (rev
1192)
@@ -66,6 +66,7 @@
import javax.security.auth.Subject;
import javax.servlet.AsyncContext;
+import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
@@ -2414,6 +2415,9 @@
public void setTimeout(int timeout) {
coyoteRequest.action(ActionCode.ACTION_EVENT_TIMEOUT, timeout);
}
+ public void setTimeout0(int timeout) {
+ setTimeout(timeout);
+ }
public void resume() {
@@ -2789,8 +2793,7 @@
fu.setSizeMax(config.getMaxRequestSize());
}
if (config.getMaxFileSize() > 0) {
- // FIXME: Unimplemented per file max size
- //fu.setSizeFileMax(config.getMaxFileSize());
+ fu.setFileSizeMax(config.getMaxFileSize());
}
parts = new HashMap<String, Part>();
@@ -3005,25 +3008,24 @@
public AsyncContext startAsync(ServletRequest servletRequest,
ServletResponse servletResponse) throws IllegalStateException {
- /* TODO
- * <p>This method clears the list of {@link AsyncListener} instances
- * (if any) that were registered with the AsyncContext returned by the
- * previous call to one of the startAsync methods, after calling each
- * AsyncListener at its {@link AsyncListener#onStartAsync onStartAsync}
- * method.
- */
- int timeout = (asyncTimeout > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)
asyncTimeout;
- if (timeout <= 0) {
- timeout = Integer.MAX_VALUE;
- }
if (CHECK_ASYNC && !isAsyncSupported()) {
throw new
IllegalStateException(sm.getString("coyoteRequest.noAsync"));
}
// FIXME: if (asyncContext != null && !processing) { throw ISE }
+ LinkedHashMap<AsyncListener, AsyncListenerRegistration> localAsyncListeners
= asyncListeners;
+ asyncListeners = new LinkedHashMap<AsyncListener,
AsyncListenerRegistration>();
+ for (AsyncListenerRegistration registration : localAsyncListeners.values()) {
+ AsyncListener asyncListener = registration.getListener();
+ AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
registration.getRequest(), registration.getResponse());
+ try {
+ asyncListener.onStartAsync(asyncEvent);
+ } catch (IOException e) {
+ // FIXME: error reporting ? throw new IllegalStateException(e);
+ }
+ }
if (response.isClosed()) {
throw new
IllegalStateException(sm.getString("coyoteRequest.closed"));
}
- setTimeout(timeout);
if (asyncContext == null) {
asyncContext = new AsyncContextImpl();
eventMode = true;
@@ -3286,6 +3288,11 @@
public void setTimeout(long timeout) {
asyncTimeout = timeout;
+ int realTimeout = (asyncTimeout > Integer.MAX_VALUE) ? Integer.MAX_VALUE :
(int) asyncTimeout;
+ if (realTimeout <= 0) {
+ realTimeout = Integer.MAX_VALUE;
+ }
+ setTimeout0(realTimeout);
}
}
Modified: trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 2009-10-10 01:01:00
UTC (rev 1191)
+++ trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 2009-10-11 17:55:58
UTC (rev 1192)
@@ -266,15 +266,20 @@
public boolean addMappingForServletNames(EnumSet<DispatcherType>
dispatcherTypes,
boolean isMatchAfter, String... servletNames) {
if (context.isInitialized()) {
- throw new
IllegalStateException(sm.getString("filterRegistration.addFilterMapping.ise",
context.getPath()));
+ throw new
IllegalStateException(sm.getString("filterRegistration.ise",
context.getPath()));
}
+ if (servletNames == null || servletNames.length == 0) {
+ throw new
IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
FilterMap filterMap = new FilterMap();
for (String servletName : servletNames) {
filterMap.addServletName(servletName);
}
filterMap.setFilterName(filterDef.getFilterName());
- for (DispatcherType dispatcherType: dispatcherTypes) {
- filterMap.setDispatcher(dispatcherType.name());
+ if (dispatcherTypes != null) {
+ for (DispatcherType dispatcherType: dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType.name());
+ }
}
if (isMatchAfter) {
context.addFilterMap(filterMap);
@@ -289,15 +294,20 @@
EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... urlPatterns) {
if (context.isInitialized()) {
- throw new
IllegalStateException(sm.getString("filterRegistration.addFilterMapping.ise",
context.getPath()));
+ throw new
IllegalStateException(sm.getString("filterRegistration.ise",
context.getPath()));
}
+ if (urlPatterns == null || urlPatterns.length == 0) {
+ throw new
IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
FilterMap filterMap = new FilterMap();
for (String urlPattern : urlPatterns) {
filterMap.addURLPattern(urlPattern);
}
filterMap.setFilterName(filterDef.getFilterName());
- for (DispatcherType dispatcherType: dispatcherTypes) {
- filterMap.setDispatcher(dispatcherType.name());
+ if (dispatcherTypes != null) {
+ for (DispatcherType dispatcherType: dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType.name());
+ }
}
if (isMatchAfter) {
context.addFilterMap(filterMap);
@@ -347,6 +357,9 @@
public void setAsyncSupported(boolean asyncSupported) {
+ if (context.isInitialized()) {
+ throw new
IllegalStateException(sm.getString("filterRegistration.ise",
context.getPath()));
+ }
filterDef.setAsyncSupported(asyncSupported);
context.addFilterDef(filterDef);
}
@@ -359,6 +372,12 @@
public boolean setInitParameter(String name, String value) {
+ if (context.isInitialized()) {
+ throw new
IllegalStateException(sm.getString("filterRegistration.ise",
context.getPath()));
+ }
+ if (name == null || value == null) {
+ throw new
IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
if (filterDef.getInitParameter(name) != null) {
return false;
}
@@ -369,6 +388,12 @@
public Set<String> setInitParameters(Map<String, String> initParameters)
{
+ if (context.isInitialized()) {
+ throw new
IllegalStateException(sm.getString("filterRegistration.ise",
context.getPath()));
+ }
+ if (initParameters == null) {
+ throw new
IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
Set<String> conflicts = new HashSet<String>();
Iterator<String> parameterNames = initParameters.keySet().iterator();
while (parameterNames.hasNext()) {
@@ -376,7 +401,11 @@
if (filterDef.getInitParameter(parameterName) != null) {
conflicts.add(parameterName);
} else {
- filterDef.addInitParameter(parameterName,
initParameters.get(parameterName));
+ String value = initParameters.get(parameterName);
+ if (value == null) {
+ throw new
IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
+ filterDef.addInitParameter(parameterName, value);
}
}
context.addFilterDef(filterDef);
Modified: trunk/java/org/apache/catalina/core/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-10-10 01:01:00 UTC
(rev 1191)
+++ trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-10-11 17:55:58 UTC
(rev 1192)
@@ -233,5 +233,7 @@
defaultInstanceManager.privilegedFilter=Filter of class {0} is privileged and cannot be
loaded by this web application
defaultInstanceManager.restrictedListenersResources="Restricted listeners property
file not found
-filterRegistration.addFilterMapping.ise=Filter mappings can not be added to context {0}
at this time. See SRV.4.4.
-servletRegistration.addServletMapping.ise=Servlet mappings can not be added to context
{0} at this time. See SRV.4.4.
+filterRegistration.ise=Context {0} has already been initialized.
+filterRegistration.iae=Illegal null or empty argument specified
+servletRegistration.ise=Context {0} has already been initialized.
+servletRegistration.iae=Illegal null or empty argument specified
Modified: trunk/java/org/apache/catalina/core/StandardWrapperFacade.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardWrapperFacade.java 2009-10-10 01:01:00 UTC
(rev 1191)
+++ trunk/java/org/apache/catalina/core/StandardWrapperFacade.java 2009-10-11 17:55:58 UTC
(rev 1192)
@@ -156,15 +156,16 @@
Set<String> conflicts = new HashSet<String>();
if (((Context) wrapper.getParent()).isInitialized()) {
throw new IllegalStateException(sm.getString
- ("servletRegistration.addServletMapping.ise", ((Context)
wrapper.getParent()).getPath()));
+ ("servletRegistration.ise", ((Context)
wrapper.getParent()).getPath()));
}
- if (urlPatterns != null) {
- for (int i = 0; i < urlPatterns.length; i++) {
- if (((Context) wrapper.getParent()).findServletMapping(urlPatterns[i]) !=
null) {
- conflicts.add(urlPatterns[i]);
- } else {
- ((Context) wrapper.getParent()).addServletMapping(urlPatterns[i],
wrapper.getName());
- }
+ if (urlPatterns == null || urlPatterns.length == 0) {
+ throw new
IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
+ for (String urlPattern : urlPatterns) {
+ if (((Context) wrapper.getParent()).findServletMapping(urlPattern) != null)
{
+ conflicts.add(urlPattern);
+ } else {
+ ((Context) wrapper.getParent()).addServletMapping(urlPattern,
wrapper.getName());
}
}
return conflicts;
@@ -172,6 +173,10 @@
public void setAsyncSupported(boolean asyncSupported) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context)
wrapper.getParent()).getPath()));
+ }
wrapper.setAsyncSupported(asyncSupported);
}
@@ -182,12 +187,30 @@
public boolean setInitParameter(String name, String value) {
- wrapper.addInitParameter(name, value);
- return true;
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context)
wrapper.getParent()).getPath()));
+ }
+ if (name == null || value == null) {
+ throw new
IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
+ if (wrapper.findInitParameter(name) == null) {
+ wrapper.addInitParameter(name, value);
+ return true;
+ } else {
+ return false;
+ }
}
public Set<String> setInitParameters(Map<String, String> initParameters)
{
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context)
wrapper.getParent()).getPath()));
+ }
+ if (initParameters == null) {
+ throw new
IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
Set<String> conflicts = new HashSet<String>();
Iterator<String> parameterNames = initParameters.keySet().iterator();
while (parameterNames.hasNext()) {
@@ -195,7 +218,11 @@
if (wrapper.findInitParameter(parameterName) != null) {
conflicts.add(parameterName);
} else {
- wrapper.addInitParameter(parameterName,
initParameters.get(parameterName));
+ String value = initParameters.get(parameterName);
+ if (value == null) {
+ throw new
IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
+ wrapper.addInitParameter(parameterName, value);
}
}
return conflicts;
@@ -203,6 +230,10 @@
public void setLoadOnStartup(int loadOnStartup) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context)
wrapper.getParent()).getPath()));
+ }
wrapper.setLoadOnStartup(loadOnStartup);
}
@@ -242,14 +273,35 @@
}
public void setRunAsRole(String roleName) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context)
wrapper.getParent()).getPath()));
+ }
+ if (roleName == null) {
+ throw new
IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
wrapper.setRunAs(roleName);
}
public void setServletSecurity(ServletSecurityElement servletSecurity) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context)
wrapper.getParent()).getPath()));
+ }
+ if (servletSecurity == null) {
+ throw new
IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
wrapper.setServletSecurity(servletSecurity);
}
public void setMultipartConfig(MultipartConfigElement multipartConfig) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context)
wrapper.getParent()).getPath()));
+ }
+ if (multipartConfig == null) {
+ throw new
IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
Multipart multipart = new Multipart();
multipart.setLocation(multipartConfig.getLocation());
multipart.setMaxFileSize(multipartConfig.getMaxFileSize());
Modified: trunk/java/org/apache/tomcat/util/http/fileupload/DefaultFileItemFactory.java
===================================================================
---
trunk/java/org/apache/tomcat/util/http/fileupload/DefaultFileItemFactory.java 2009-10-10
01:01:00 UTC (rev 1191)
+++
trunk/java/org/apache/tomcat/util/http/fileupload/DefaultFileItemFactory.java 2009-10-11
17:55:58 UTC (rev 1192)
@@ -56,6 +56,12 @@
public static final int DEFAULT_SIZE_THRESHOLD = 10240;
+ /**
+ * The default max size for a file.
+ */
+ public static final int DEFAULT_FILE_SIZE_MAX = -1;
+
+
// ----------------------------------------------------- Instance Variables
@@ -71,6 +77,12 @@
private int sizeThreshold = DEFAULT_SIZE_THRESHOLD;
+ /**
+ * The max file size.
+ */
+ private long fileSizeMax = DEFAULT_FILE_SIZE_MAX;
+
+
// ----------------------------------------------------------- Constructors
@@ -161,6 +173,32 @@
}
+ /**
+ * Returns the max size of a file.
+ *
+ * @return The size, in bytes.
+ *
+ * @see #setFileSizeMax(int)
+ */
+ public long getFileSizeMax()
+ {
+ return fileSizeMax;
+ }
+
+
+ /**
+ * Sets the max size of a file.
+ *
+ * @param fileSizeMax The size, in bytes.
+ *
+ * @see #getSizeThreshold()
+ */
+ public void setFileSizeMax(long fileSizeMax)
+ {
+ this.fileSizeMax = fileSizeMax;
+ }
+
+
// --------------------------------------------------------- Public Methods
/**
@@ -185,6 +223,7 @@
Map<String, String> headers
)
{
+ // FIXME: Add file size max
return new DefaultFileItem(fieldName, contentType,
isFormField, fileName, headers, sizeThreshold, repository);
}
Modified: trunk/java/org/apache/tomcat/util/http/fileupload/DiskFileUpload.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/fileupload/DiskFileUpload.java 2009-10-10
01:01:00 UTC (rev 1191)
+++ trunk/java/org/apache/tomcat/util/http/fileupload/DiskFileUpload.java 2009-10-11
17:55:58 UTC (rev 1192)
@@ -171,6 +171,32 @@
}
+ /**
+ * Returns the max size of a file.
+ *
+ * @return The size, in bytes.
+ *
+ * @see #setFileSizeMax(long)
+ */
+ public long getFileSizeMax()
+ {
+ return fileItemFactory.getFileSizeMax();
+ }
+
+
+ /**
+ * Sets the max size of a file.
+ *
+ * @param fileSizeMax The size, in bytes.
+ *
+ * @see #getSizeThreshold()
+ */
+ public void setFileSizeMax(long fileSizeMax)
+ {
+ fileItemFactory.setFileSizeMax(fileSizeMax);
+ }
+
+
// --------------------------------------------------------- Public methods