This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new a3277bb Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63206 a3277bb is described below commit a3277bb34b5307edf477c377a06be884bb39ee4a 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 --- 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 | 7 +++++++ webapps/docs/config/context.xml | 7 +++++++ 8 files changed, 71 insertions(+) diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index 23e43b9..8471fa4 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -1901,4 +1901,26 @@ public interface Context extends Container, ContextBind { 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 e8ebf6f..b70b187 100644 --- a/java/org/apache/catalina/connector/LocalStrings.properties +++ b/java/org/apache/catalina/connector/LocalStrings.properties @@ -50,6 +50,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 92e279f..8aed515 100644 --- a/java/org/apache/catalina/connector/Request.java +++ b/java/org/apache/catalina/connector/Request.java @@ -2867,6 +2867,15 @@ public class Request implements org.apache.catalina.servlet4preview.http.HttpSer } } + 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 298b006..7533d77 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -820,10 +820,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 5115e08..0c96fdf 100644 --- a/java/org/apache/catalina/startup/FailedContext.java +++ b/java/org/apache/catalina/startup/FailedContext.java @@ -821,4 +821,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 d472890..5f6ebad 100644 --- a/test/org/apache/tomcat/unittest/TesterContext.java +++ b/test/org/apache/tomcat/unittest/TesterContext.java @@ -1295,4 +1295,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 2ef5914..6269449 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -89,6 +89,13 @@ <code>maxLogMessageBufferSize</code> that were accidentally removed. (markt) </fix> + <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> <fix> <bug>63210</bug>: Ensure that the Apache Commons DBCP 2 based default connection pool is correctly shutdown when it is no longer required. diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index 5eacd12..767aefe 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