This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push: new 6e3551b Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63206 6e3551b is described below commit 6e3551b7ff2623ee89a179beeb63f62f2e8d6d37 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Mar 5 13:15:23 2019 +0000 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63206 Add createUploadTargets to Context # Conflicts: # java/org/apache/catalina/connector/LocalStrings.properties # Conflicts: # webapps/docs/changelog.xml --- java/org/apache/catalina/Context.java | 22 ++++++++++++++++++++++ .../catalina/connector/LocalStrings.properties | 2 ++ java/org/apache/catalina/connector/Request.java | 9 +++++++++ java/org/apache/catalina/core/StandardContext.java | 14 ++++++++++++++ .../org/apache/catalina/startup/FailedContext.java | 5 +++++ test/org/apache/tomcat/unittest/TesterContext.java | 5 +++++ webapps/docs/changelog.xml | 11 +++++++++++ webapps/docs/config/context.xml | 7 +++++++ 8 files changed, 75 insertions(+) diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index 1503b91..c4409d0 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -1765,4 +1765,26 @@ public interface Context extends Container { public void decrementInProgressAsyncCount(); + + + /** + * Configure whether Tomcat will attempt to create an upload target used by + * this web application if it does not exist when the web application + * attempts to use it. + * + * @param createUploadTargets {@code true} if Tomcat should attempt to + * create the upload target, otherwise {@code false} + */ + public void setCreateUploadTargets(boolean createUploadTargets); + + + /** + * Will Tomcat attempt to create an upload target used by this web + * application if it does not exist when the web application attempts to use + * it? + * + * @return {@code true} if Tomcat will attempt to create an upload target + * otherwise {@code false} + */ + public boolean getCreateUploadTargets(); } diff --git a/java/org/apache/catalina/connector/LocalStrings.properties b/java/org/apache/catalina/connector/LocalStrings.properties index 923824c..a6c8efe 100644 --- a/java/org/apache/catalina/connector/LocalStrings.properties +++ b/java/org/apache/catalina/connector/LocalStrings.properties @@ -73,6 +73,8 @@ coyoteRequest.postTooLarge=Parameters were not parsed because the size of the po coyoteRequest.chunkedPostTooLarge=Parameters were not parsed because the size of the posted data was too big. Because this request was a chunked request, it could not be processed further. Use the maxPostSize attribute of the connector to resolve this if the application should accept large POSTs. coyoteRequest.alreadyAuthenticated=This request has already been authenticated coyoteRequest.authenticate.ise=Cannot call authenticate() after the response has been committed +coyoteRequest.uploadCreate=Creating the temporary upload location [{0}] as it is required by the servlet [{1}] +coyoteRequest.uploadCreateFail=Failed to create the upload location [{0}] coyoteRequest.uploadLocationInvalid=The temporary upload location [{0}] is not valid coyoteRequest.sessionEndAccessFail=Exception triggered ending access to session while recycling request coyoteRequest.sendfileNotCanonical=Unable to determine canonical name of file [{0}] specified for use with sendfile diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java index 815daee..8a18bc9 100644 --- a/java/org/apache/catalina/connector/Request.java +++ b/java/org/apache/catalina/connector/Request.java @@ -2874,6 +2874,15 @@ implements HttpServletRequest { } } + if (!location.exists() && context.getCreateUploadTargets()) { + log.warn(sm.getString("coyoteRequest.uploadCreate", + location.getAbsolutePath(), getMappingData().wrapper.getName())); + if (!location.mkdirs()) { + log.warn(sm.getString("coyoteRequest.uploadCreateFail", + location.getAbsolutePath())); + } + } + if (!location.isDirectory()) { parameters.setParseFailedReason(FailReason.MULTIPART_CONFIG_INVALID); partsParseException = new IOException( diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 21addb4..0de8aad 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -950,10 +950,24 @@ public class StandardContext extends ContainerBase private final AtomicLong inProgressAsyncCount = new AtomicLong(0); + private boolean createUploadTargets = false; + // ----------------------------------------------------- Context Properties @Override + public void setCreateUploadTargets(boolean createUploadTargets) { + this.createUploadTargets = createUploadTargets; + } + + + @Override + public boolean getCreateUploadTargets() { + return createUploadTargets; + } + + + @Override public void incrementInProgressAsyncCount() { inProgressAsyncCount.incrementAndGet(); } diff --git a/java/org/apache/catalina/startup/FailedContext.java b/java/org/apache/catalina/startup/FailedContext.java index 7c52aed..2f08ee8 100644 --- a/java/org/apache/catalina/startup/FailedContext.java +++ b/java/org/apache/catalina/startup/FailedContext.java @@ -750,4 +750,9 @@ public class FailedContext extends LifecycleMBeanBase implements Context { public void incrementInProgressAsyncCount() { /* NO-OP */ } @Override public void decrementInProgressAsyncCount() { /* NO-OP */ } + + @Override + public void setCreateUploadTargets(boolean createUploadTargets) { /* NO-OP */} + @Override + public boolean getCreateUploadTargets() { return false; } } \ No newline at end of file diff --git a/test/org/apache/tomcat/unittest/TesterContext.java b/test/org/apache/tomcat/unittest/TesterContext.java index 6259eb0..1240c1a 100644 --- a/test/org/apache/tomcat/unittest/TesterContext.java +++ b/test/org/apache/tomcat/unittest/TesterContext.java @@ -1273,4 +1273,9 @@ public class TesterContext implements Context { public void incrementInProgressAsyncCount() { /* NO-OP */ } @Override public void decrementInProgressAsyncCount() { /* NO-OP */ } + + @Override + public void setCreateUploadTargets(boolean createUploadTargets) { /* NO-OP */} + @Override + public boolean getCreateUploadTargets() { return false; } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 825f041..50b06f5 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -59,6 +59,17 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 7.0.94 (violetagg)"> + <subsection name="Catalina"> + <changelog> + <add> + <bug>63206</bug>: Add a new attribute to <code>Context</code> - + <code>createUploadTargets</code> which, if <code>true</code> enables + Tomcat to create the temporary upload location used by a Servlet if the + location specified by the Servlet does not already exist. The deafult + value is <code>false</code>. (markt) + </add> + </changelog> + </subsection> <subsection name="Coyote"> <changelog> <fix> diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index 3ae06e6..d5e1fcb 100644 --- a/webapps/docs/config/context.xml +++ b/webapps/docs/config/context.xml @@ -336,6 +336,13 @@ only on URL rewriting by the application.</p> </attribute> + <attribute name="createUploadTargets" required="false"> + <p>Set to <code>true</code> if Tomcat should attempt to create the + temporary upload location specified in the <code>MultipartConfig</code> + for a Servlet if the location does not already exist. If not specified, + the default value of <code>false</code> will be used.</p> + </attribute> + <attribute name="crossContext" required="false"> <p>Set to <code>true</code> if you want calls within this application to <code>ServletContext.getContext()</code> to successfully return a --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org