tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [tomcat] branch master updated: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63206
Date Tue, 05 Mar 2019 13:16:36 GMT
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 267b8d8  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63206
267b8d8 is described below

commit 267b8d8852db44dbad249453099ef6e9c26a4e9f
Author: Mark Thomas <markt@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
---
 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 192d1d2..5e3d285 100644
--- a/java/org/apache/catalina/Context.java
+++ b/java/org/apache/catalina/Context.java
@@ -1871,4 +1871,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 a7b5fee..bb018d9 100644
--- a/java/org/apache/catalina/connector/LocalStrings.properties
+++ b/java/org/apache/catalina/connector/LocalStrings.properties
@@ -60,6 +60,8 @@ coyoteRequest.sessionCreateCommitted=Cannot create a session after the response
 coyoteRequest.sessionEndAccessFail=Exception triggered ending access to session while recycling
request
 coyoteRequest.setAttribute.namenull=Cannot call setAttribute with a null name
 coyoteRequest.trailersNotReady=It is illegal to call getTrailerFields() before isTrailerFieldsReady()
has returned true
+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
 
 coyoteResponse.encoding.invalid=The encoding [{0}] is not recognised by the JRE
diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java
index 2cb29fc..db51182 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -2815,6 +2815,15 @@ public class Request 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 a61130c..5885b02 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -822,10 +822,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 83f9c45..02f5847 100644
--- a/java/org/apache/catalina/startup/FailedContext.java
+++ b/java/org/apache/catalina/startup/FailedContext.java
@@ -814,4 +814,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 d106788..9725e76 100644
--- a/test/org/apache/tomcat/unittest/TesterContext.java
+++ b/test/org/apache/tomcat/unittest/TesterContext.java
@@ -1279,4 +1279,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 431b57c..e53934a 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -63,6 +63,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 306568c..d4c024e 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message