You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2020/04/27 22:43:35 UTC

[tomcat] branch 8.5.x updated (59bd13c -> 1871935)

This is an automated email from the ASF dual-hosted git repository.

remm pushed a change to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 59bd13c  Fix bz 64373. Ensure tag file unpacked from WAR can be found.
     new 13de9aa  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64384
     new f98c104  Fix validate
     new 82598eb  Add changelog
     new 1871935  Use javax for 9

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/catalina/startup/ContextConfig.java |  30 ++--
 .../catalina/startup/TestMultipartConfig.java      | 188 +++++++++++++++++++++
 webapps/docs/changelog.xml                         |   6 +-
 3 files changed, 211 insertions(+), 13 deletions(-)
 create mode 100644 test/org/apache/catalina/startup/TestMultipartConfig.java


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 01/04: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64384

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 13de9aa412237a42512cc6e0ae57254665ae539f
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Mon Apr 27 18:01:00 2020 -0400

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64384
    
    Respect partial multipart-config elements.
---
 .../org/apache/catalina/startup/ContextConfig.java |  30 ++--
 .../catalina/startup/TestMultipartConfig.java      | 171 +++++++++++++++++++++
 2 files changed, 189 insertions(+), 12 deletions(-)

diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java
index fe8c87d..0f29773 100644
--- a/java/org/apache/catalina/startup/ContextConfig.java
+++ b/java/org/apache/catalina/startup/ContextConfig.java
@@ -1354,19 +1354,25 @@ public class ContextConfig implements LifecycleListener {
             wrapper.setServletClass(servlet.getServletClass());
             MultipartDef multipartdef = servlet.getMultipartDef();
             if (multipartdef != null) {
-                if (multipartdef.getMaxFileSize() != null &&
-                        multipartdef.getMaxRequestSize()!= null &&
-                        multipartdef.getFileSizeThreshold() != null) {
-                    wrapper.setMultipartConfigElement(new MultipartConfigElement(
-                            multipartdef.getLocation(),
-                            Long.parseLong(multipartdef.getMaxFileSize()),
-                            Long.parseLong(multipartdef.getMaxRequestSize()),
-                            Integer.parseInt(
-                                    multipartdef.getFileSizeThreshold())));
-                } else {
-                    wrapper.setMultipartConfigElement(new MultipartConfigElement(
-                            multipartdef.getLocation()));
+                long maxFileSize = -1;
+                long maxRequestSize = -1;
+                int fileSizeThreshold = 0;
+
+                if(null != multipartdef.getMaxFileSize()) {
+                    maxFileSize = Long.parseLong(multipartdef.getMaxFileSize());
+                }
+                if(null != multipartdef.getMaxRequestSize()) {
+                    maxRequestSize = Long.parseLong(multipartdef.getMaxRequestSize());
                 }
+                if(null != multipartdef.getFileSizeThreshold()) {
+                    fileSizeThreshold = Integer.parseInt(multipartdef.getFileSizeThreshold());
+                }
+
+                wrapper.setMultipartConfigElement(new MultipartConfigElement(
+                        multipartdef.getLocation(),
+                        maxFileSize,
+                        maxRequestSize,
+                        fileSizeThreshold));
             }
             if (servlet.getAsyncSupported() != null) {
                 wrapper.setAsyncSupported(
diff --git a/test/org/apache/catalina/startup/TestMultipartConfig.java b/test/org/apache/catalina/startup/TestMultipartConfig.java
new file mode 100644
index 0000000..d0ca905
--- /dev/null
+++ b/test/org/apache/catalina/startup/TestMultipartConfig.java
@@ -0,0 +1,171 @@
+package org.apache.catalina.startup;
+
+import java.lang.reflect.Method;
+
+import jakarta.servlet.MultipartConfigElement;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleState;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardEngine;
+import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardService;
+import org.apache.catalina.core.StandardWrapper;
+import org.apache.tomcat.util.descriptor.web.MultipartDef;
+import org.apache.tomcat.util.descriptor.web.ServletDef;
+import org.apache.tomcat.util.descriptor.web.WebXml;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestMultipartConfig {
+    @Test
+    public void testNoMultipartConfig() throws Exception {
+        StandardWrapper servlet =  config(null);
+
+        MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+        Assert.assertNull(mce);
+    }
+
+    @Test
+    public void testDefaultMultipartConfig() throws Exception {
+        MultipartDef multipartDef = new MultipartDef();
+        // Do not set any attributes on multipartDef: expect defaults
+
+        StandardWrapper servlet =  config(multipartDef);
+        MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+        Assert.assertNotNull(mce);
+        Assert.assertEquals("", mce.getLocation());
+        Assert.assertEquals(-1, mce.getMaxFileSize());
+        Assert.assertEquals(-1, mce.getMaxRequestSize());
+        Assert.assertEquals(0, mce.getFileSizeThreshold());
+    }
+
+    @Test
+    public void testPartialMultipartConfigMaxFileSize() throws Exception {
+        MultipartDef multipartDef = new MultipartDef();
+        multipartDef.setMaxFileSize("1024");
+
+        StandardWrapper servlet =  config(multipartDef);
+        MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+        Assert.assertNotNull(mce);
+        Assert.assertEquals("", mce.getLocation());
+        Assert.assertEquals(1024, mce.getMaxFileSize());
+        Assert.assertEquals(-1, mce.getMaxRequestSize());
+        Assert.assertEquals(0, mce.getFileSizeThreshold());
+    }
+
+    @Test
+    public void testPartialMultipartConfigMaxReqeustSize() throws Exception {
+        MultipartDef multipartDef = new MultipartDef();
+        multipartDef.setMaxRequestSize("10240");
+
+        StandardWrapper servlet =  config(multipartDef);
+        MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+        Assert.assertNotNull(mce);
+        Assert.assertEquals("", mce.getLocation());
+        Assert.assertEquals(-1, mce.getMaxFileSize());
+        Assert.assertEquals(10240, mce.getMaxRequestSize());
+        Assert.assertEquals(0, mce.getFileSizeThreshold());
+    }
+
+    @Test
+    public void testPartialMultipartConfigFileSizeThreshold() throws Exception {
+        MultipartDef multipartDef = new MultipartDef();
+        multipartDef.setFileSizeThreshold("24");
+
+        StandardWrapper servlet =  config(multipartDef);
+        MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+        Assert.assertNotNull(mce);
+        Assert.assertEquals("", mce.getLocation());
+        Assert.assertEquals(-1, mce.getMaxFileSize());
+        Assert.assertEquals(-1, mce.getMaxRequestSize());
+        Assert.assertEquals(24, mce.getFileSizeThreshold());
+    }
+
+    @Test
+    public void testCompleteMultipartConfig() throws Exception {
+        MultipartDef multipartDef = new MultipartDef();
+        multipartDef.setMaxFileSize("1024");
+        multipartDef.setMaxRequestSize("10240");
+        multipartDef.setFileSizeThreshold("24");
+        multipartDef.setLocation("/tmp/foo");
+
+        StandardWrapper servlet =  config(multipartDef);
+
+        MultipartConfigElement mce = servlet.getMultipartConfigElement();
+
+        Assert.assertNotNull(mce);
+        Assert.assertEquals("/tmp/foo", mce.getLocation());
+        Assert.assertEquals(1024, mce.getMaxFileSize());
+        Assert.assertEquals(10240, mce.getMaxRequestSize());
+        Assert.assertEquals(24, mce.getFileSizeThreshold());
+    }
+
+    private StandardWrapper config(MultipartDef multipartDef) throws Exception {
+        MyContextConfig config = new MyContextConfig();
+
+        WebXml webxml = new WebXml();
+
+        ServletDef servletDef = new ServletDef();
+        servletDef.setServletName("test");
+        servletDef.setServletClass("org.apache.catalina.startup.ParamServlet");
+        servletDef.setMultipartDef(multipartDef);
+        webxml.addServlet(servletDef);
+
+        Method m = ContextConfig.class.getDeclaredMethod("configureContext", WebXml.class);
+
+        // Force our way in
+        m.setAccessible(true);
+
+        m.invoke(config, webxml);
+
+        StandardWrapper servlet = (StandardWrapper)config.getContext().findChild("test");
+
+        return servlet;
+    }
+
+    private static class MyContextConfig extends ContextConfig {
+        public MyContextConfig() {
+            CustomContext context = new CustomContext();
+            super.context = context;
+            context.setConfigured(false);
+            context.setState(LifecycleState.STARTING_PREP);
+            context.setName("test");
+
+            Connector connector = new Connector();
+            StandardService service = new StandardService();
+            service.addConnector(connector);
+            StandardEngine engine = new StandardEngine();
+            engine.setService(service);
+            Container parent = new StandardHost();
+            parent.setParent(engine);
+            super.context.setParent(parent);
+            context.getState().equals(LifecycleState.STARTING_PREP);
+        }
+        public Context getContext() {
+            return super.context;
+        }
+    }
+
+    private static class CustomContext extends StandardContext {
+        private volatile LifecycleState state;
+
+        @Override
+        public LifecycleState getState() {
+            return state;
+        }
+
+        @Override
+        public synchronized void setState(LifecycleState state) {
+            this.state = state;
+        }
+    }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 02/04: Fix validate

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit f98c1049e3803d355fbb78355a61bc27451933db
Author: remm <re...@apache.org>
AuthorDate: Tue Apr 28 00:33:00 2020 +0200

    Fix validate
---
 .../catalina/startup/TestMultipartConfig.java       | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/test/org/apache/catalina/startup/TestMultipartConfig.java b/test/org/apache/catalina/startup/TestMultipartConfig.java
index d0ca905..986edb4 100644
--- a/test/org/apache/catalina/startup/TestMultipartConfig.java
+++ b/test/org/apache/catalina/startup/TestMultipartConfig.java
@@ -1,9 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.catalina.startup;
 
 import java.lang.reflect.Method;
 
 import jakarta.servlet.MultipartConfigElement;
 
+import org.junit.Assert;
+import org.junit.Test;
+
 import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.LifecycleState;
@@ -16,8 +35,6 @@ import org.apache.catalina.core.StandardWrapper;
 import org.apache.tomcat.util.descriptor.web.MultipartDef;
 import org.apache.tomcat.util.descriptor.web.ServletDef;
 import org.apache.tomcat.util.descriptor.web.WebXml;
-import org.junit.Assert;
-import org.junit.Test;
 
 public class TestMultipartConfig {
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 04/04: Use javax for 9

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 187193585dceaaae06839c024e5c760e2b6f12ee
Author: remm <re...@apache.org>
AuthorDate: Tue Apr 28 00:39:43 2020 +0200

    Use javax for 9
---
 test/org/apache/catalina/startup/TestMultipartConfig.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/org/apache/catalina/startup/TestMultipartConfig.java b/test/org/apache/catalina/startup/TestMultipartConfig.java
index 986edb4..c152255 100644
--- a/test/org/apache/catalina/startup/TestMultipartConfig.java
+++ b/test/org/apache/catalina/startup/TestMultipartConfig.java
@@ -18,7 +18,7 @@ package org.apache.catalina.startup;
 
 import java.lang.reflect.Method;
 
-import jakarta.servlet.MultipartConfigElement;
+import javax.servlet.MultipartConfigElement;
 
 import org.junit.Assert;
 import org.junit.Test;


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 03/04: Add changelog

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 82598ebce058be73432bf8d118023a55f682669b
Author: remm <re...@apache.org>
AuthorDate: Tue Apr 28 00:36:10 2020 +0200

    Add changelog
---
 webapps/docs/changelog.xml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 474a727..a8a5930 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -81,10 +81,14 @@
         Sakhare. (markt)
       </add>
       <fix>
-        <bug>64309</bug>; Improve the regular expression used to search for
+        <bug>64309</bug>: Improve the regular expression used to search for
         class loader repositories when bootstrapping Tomcat. Pull request
         provided by Paul Muriel Biya-Bi. (markt)
       </fix>
+      <fix>
+        <bug>64384</bug>: Fix multipart configuration ignoring some parameters
+        in some cases. (schultz)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org