From dev-return-197165-archive-asf-public=cust-asf.ponee.io@tomcat.apache.org Tue Mar 5 13:16:39 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 94F61180648 for ; Tue, 5 Mar 2019 14:16:38 +0100 (CET) Received: (qmail 50427 invoked by uid 500); 5 Mar 2019 13:16:37 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 50417 invoked by uid 99); 5 Mar 2019 13:16:37 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Mar 2019 13:16:37 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id D1E31877DA; Tue, 5 Mar 2019 13:16:36 +0000 (UTC) Date: Tue, 05 Mar 2019 13:16:36 +0000 To: "dev@tomcat.apache.org" Subject: [tomcat] branch master updated: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63206 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <155179179605.15587.626722385475051452@gitbox.apache.org> From: markt@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: tomcat X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 8066eb5f5e5459fed5827546b1b60d434f4a1090 X-Git-Newrev: 267b8d8852db44dbad249453099ef6e9c26a4e9f X-Git-Rev: 267b8d8852db44dbad249453099ef6e9c26a4e9f X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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 @@ maxLogMessageBufferSize that were accidentally removed. (markt) + + 63206: Add a new attribute to Context - + createUploadTargets which, if true 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 false. (markt) + 63210: 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.

+ +

Set to true if Tomcat should attempt to create the + temporary upload location specified in the MultipartConfig + for a Servlet if the location does not already exist. If not specified, + the default value of false will be used.

+
+

Set to true if you want calls within this application to ServletContext.getContext() to successfully return a --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org