Skip to content

Commit 59aab9d

Browse files
authored
Merge pull request #24959 from pmd1nh/24958-New_Configurable_Property_For_FileUpload
Add new configurable property for fileUpload
2 parents 8112f1c + 833d22a commit 59aab9d

File tree

20 files changed

+483
-21
lines changed

20 files changed

+483
-21
lines changed

dev/com.ibm.websphere.appserver.features/visibility/private/com.ibm.websphere.appserver.servlet-servletSpi1.0.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ symbolicName=com.ibm.websphere.appserver.servlet-servletSpi1.0
33
WLP-DisableAllFeatures-OnConflict: false
44
visibility=private
55
-jars=com.ibm.websphere.appserver.spi.servlet; location:=dev/spi/ibm/
6-
-files=dev/spi/ibm/javadoc/com.ibm.websphere.appserver.spi.servlet_2.10-javadoc.zip
6+
-files=dev/spi/ibm/javadoc/com.ibm.websphere.appserver.spi.servlet_2.11-javadoc.zip
77
kind=ga
88
edition=core
99
WLP-Activation-Type: parallel

dev/com.ibm.websphere.appserver.features/visibility/private/io.openliberty.servlet-servletSpi2.0.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
symbolicName=io.openliberty.servlet-servletSpi2.0
33
visibility=private
44
-jars=io.openliberty.servlet.spi; location:=dev/spi/ibm/
5-
-files=dev/spi/ibm/javadoc/io.openliberty.servlet.spi_2.10-javadoc.zip
5+
-files=dev/spi/ibm/javadoc/io.openliberty.servlet.spi_2.11-javadoc.zip
66
kind=ga
77
edition=core
88
WLP-Activation-Type: parallel

dev/com.ibm.websphere.appserver.spi.servlet/bnd.bnd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
-sub: *.bnd
1313

14-
bVersion: 2.10
14+
bVersion: 2.11
1515

1616
Import-Package: com.ibm.wsspi.webcontainer.extension,com.ibm.wsspi.webcontainer.webapp,com.ibm.wsspi.webcontainer.filter,com.ibm.wsspi.webcontainer.collaborator,com.ibm.wsspi.webcontainer.osgi.extension,com.ibm.wsspi.webcontainer.servlet,com.ibm.ws.webcontainer.extension,com.ibm.websphere.servlet.filter,com.ibm.wsspi.webcontainer,com.ibm.wsspi.webcontainer.metadata,com.ibm.websphere.servlet.response,com.ibm.ws.webcontainer.spiadapter.collaborator
1717

dev/com.ibm.ws.webcontainer.servlet.4.0_fat/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="fat/src"/>
4+
<classpathentry kind="src" path="test-applications/FileUploadFileCountMaxTest.war/src"/>
45
<classpathentry kind="src" path="test-applications/TestEncoding.war/src"/>
56
<classpathentry kind="src" path="test-applications/TestServlet40.war/src"/>
67
<classpathentry kind="src" path="test-applications/TestServlet40.jar/src"/>

dev/com.ibm.ws.webcontainer.servlet.4.0_fat/bnd.bnd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#*******************************************************************************
2-
# Copyright (c) 2017, 2022 IBM Corporation and others.
2+
# Copyright (c) 2017, 2023 IBM Corporation and others.
33
# All rights reserved. This program and the accompanying materials
44
# are made available under the terms of the Eclipse Public License 2.0
55
# which accompanies this distribution, and is available at
@@ -15,6 +15,7 @@ bVersion=1.0
1515

1616
src: \
1717
fat/src,\
18+
test-applications/FileUploadFileCountMaxTest.war/src,\
1819
test-applications/TestServlet40.war/src,\
1920
test-applications/TestServlet40.jar/src,\
2021
test-applications/TestGetMapping.war/src,\

dev/com.ibm.ws.webcontainer.servlet.4.0_fat/fat/src/com/ibm/ws/fat/wc/FATSuite.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012, 2022 IBM Corporation and others.
2+
* Copyright (c) 2012, 2023 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-2.0/
7-
*
7+
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
1010
* Contributors:
@@ -25,6 +25,8 @@
2525
import com.ibm.ws.fat.wc.tests.WCApplicationMBeanStatusTest;
2626
import com.ibm.ws.fat.wc.tests.WCContextRootPrecedence;
2727
import com.ibm.ws.fat.wc.tests.WCEncodingTest;
28+
import com.ibm.ws.fat.wc.tests.WCFileUpLoadFileCountMaxPropertyTest;
29+
import com.ibm.ws.fat.wc.tests.WCFileUpLoadFileCountMaxTest;
2830
import com.ibm.ws.fat.wc.tests.WCGetMappingSlashStarTest;
2931
import com.ibm.ws.fat.wc.tests.WCGetMappingTest;
3032
import com.ibm.ws.fat.wc.tests.WCPushBuilderTest;
@@ -78,6 +80,8 @@
7880
WCAddJspFileTest.class,
7981
WCTrailersTest.class,
8082
WCEncodingTest.class,
83+
WCFileUpLoadFileCountMaxPropertyTest.class,
84+
WCFileUpLoadFileCountMaxTest.class,
8185
WCServerTest.class,
8286
WC5JakartaServletTest.class,
8387
WCGetMappingTest.class,
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package com.ibm.ws.fat.wc.tests;
11+
12+
import static org.junit.Assert.assertTrue;
13+
14+
import java.util.logging.Logger;
15+
16+
import org.apache.hc.client5.http.classic.methods.HttpPost;
17+
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
18+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
19+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
20+
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
21+
import org.apache.hc.core5.http.io.entity.EntityUtils;
22+
import org.junit.AfterClass;
23+
import org.junit.BeforeClass;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
27+
import com.ibm.websphere.simplicity.ShrinkHelper;
28+
29+
import componenttest.annotation.Server;
30+
import componenttest.custom.junit.runner.FATRunner;
31+
import componenttest.custom.junit.runner.Mode;
32+
import componenttest.custom.junit.runner.Mode.TestMode;
33+
import componenttest.topology.impl.LibertyServer;
34+
35+
/**
36+
* Test FileUpload 1.5's property fileCountMax=-1 which is unlimited
37+
* Send more than 5k params in body and verify working
38+
* Send more than 10k params which exceeding the maxparamperrequest's default limit of 10000 and cause exception.
39+
*/
40+
@RunWith(FATRunner.class)
41+
@Mode(TestMode.FULL)
42+
public class WCFileUpLoadFileCountMaxPropertyTest {
43+
44+
private static final Logger LOG = Logger.getLogger(WCFileUpLoadFileCountMaxPropertyTest.class.getName());
45+
private static final String APP_NAME = "FileUploadFileCountMaxTest";
46+
47+
@Server("servlet40_FileUploadFileCountMaxProperty")
48+
public static LibertyServer server;
49+
50+
@BeforeClass
51+
public static void setUp() throws Exception {
52+
LOG.info("Setup : " + APP_NAME);
53+
ShrinkHelper.defaultDropinApp(server, APP_NAME + ".war", "filecountmax");
54+
55+
// Start the server and use the class name so we can find logs easily.
56+
server.startServer(WCFileUpLoadFileCountMaxPropertyTest.class.getSimpleName() + ".log");
57+
LOG.info("Setup : complete, ready for Tests");
58+
}
59+
60+
@AfterClass
61+
public static void tearDown() throws Exception {
62+
LOG.info("tearDown : stop server");
63+
64+
if (server != null && server.isStarted()) {
65+
//Expecting the Error during the param parsing
66+
server.stopServer("SRVE0133E");
67+
}
68+
}
69+
70+
/**
71+
* Test webContainer maxFileCount=-1
72+
* Send in 5555 files/parts
73+
* Verify no Exception.
74+
*/
75+
@Test
76+
public void testFileUpload_overMaxFileCountWithProperty() throws Exception {
77+
int totalFiles = 5555;
78+
String expectedResponse = "Test Complete. Received parts size [" + totalFiles + "]";
79+
String url = "http://" + server.getHostname() + ":" + server.getHttpDefaultPort() + "/" + APP_NAME + "/GetPartName";
80+
81+
MultipartEntityBuilder builder = createMultiPartData(totalFiles);
82+
HttpPost postRequest = new HttpPost(url);
83+
postRequest.setEntity(builder.build());
84+
85+
LOG.info("\nSending [" + totalFiles + "] multipart Post Request to [" + url + "");
86+
87+
try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
88+
try (final CloseableHttpResponse response = client.execute(postRequest)) {
89+
LOG.info("Request result: " + response.getReasonPhrase());
90+
LOG.info("Status code: " + response.getCode());
91+
LOG.info("Expected response contains: [" + expectedResponse + "]");
92+
93+
String content = EntityUtils.toString(response.getEntity());
94+
LOG.info("Actual response: \n" + content);
95+
EntityUtils.consume(response.getEntity());
96+
97+
assertTrue("Response did not contain expected response: [" + expectedResponse + "] ; Actual response [" + content + "]", content.contains(expectedResponse));
98+
}
99+
}
100+
}
101+
102+
/**
103+
* Test webContainer maxFileCount=-1
104+
* Send in 10,001 files/parts. This will cause exception because it exceeds maxparamperrequest default limit of 10,000
105+
* Expecting SRVE0133E
106+
*/
107+
@Test
108+
public void testFileUpload_over10KWithProperty() throws Exception {
109+
int totalFiles = 10001;
110+
String expectedResponse = "SRVE0325E: Exceeding maximum parameters allowed per request";
111+
String url = "http://" + server.getHostname() + ":" + server.getHttpDefaultPort() + "/" + APP_NAME + "/GetPartName";
112+
113+
MultipartEntityBuilder builder = createMultiPartData(totalFiles);
114+
HttpPost postRequest = new HttpPost(url);
115+
postRequest.setEntity(builder.build());
116+
117+
LOG.info("\nSending [" + totalFiles + "] multipart Post Request to [" + url + "");
118+
119+
try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
120+
try (final CloseableHttpResponse response = client.execute(postRequest)) {
121+
LOG.info("Request result: " + response.getReasonPhrase());
122+
LOG.info("Status code: " + response.getCode());
123+
LOG.info("Expected response contains: [" + expectedResponse + "]");
124+
125+
String content = EntityUtils.toString(response.getEntity());
126+
LOG.info("Actual response: \n" + content);
127+
EntityUtils.consume(response.getEntity());
128+
129+
assertTrue("Response did not contain expected response: [" + expectedResponse + "] ; Actual response [" + content + "]", content.contains(expectedResponse));
130+
}
131+
}
132+
}
133+
134+
private MultipartEntityBuilder createMultiPartData(int parameterNum) {
135+
LOG.info("====== createMultiPartData creating [" + parameterNum + "] parts ======");
136+
MultipartEntityBuilder eBuilder = MultipartEntityBuilder.create();
137+
String name = "Name_";
138+
String value = "Value_";
139+
140+
for (int i = 0; i < parameterNum; i++) {
141+
eBuilder.addTextBody(name + i, value + i);
142+
}
143+
return eBuilder;
144+
}
145+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package com.ibm.ws.fat.wc.tests;
11+
12+
import static org.junit.Assert.assertTrue;
13+
14+
import java.util.logging.Logger;
15+
16+
import org.apache.hc.client5.http.classic.methods.HttpPost;
17+
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
18+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
19+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
20+
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
21+
import org.apache.hc.core5.http.io.entity.EntityUtils;
22+
import org.junit.AfterClass;
23+
import org.junit.BeforeClass;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
27+
import com.ibm.websphere.simplicity.ShrinkHelper;
28+
29+
import componenttest.annotation.Server;
30+
import componenttest.custom.junit.runner.FATRunner;
31+
import componenttest.custom.junit.runner.Mode;
32+
import componenttest.custom.junit.runner.Mode.TestMode;
33+
import componenttest.topology.impl.LibertyServer;
34+
35+
/**
36+
* Test FileUpload 1.5 with default value of fileCountMax
37+
*/
38+
@RunWith(FATRunner.class)
39+
@Mode(TestMode.FULL)
40+
public class WCFileUpLoadFileCountMaxTest {
41+
42+
private static final Logger LOG = Logger.getLogger(WCFileUpLoadFileCountMaxTest.class.getName());
43+
private static final String APP_NAME = "FileUploadFileCountMaxTest";
44+
45+
@Server("servlet40_FileUploadFileCountMax")
46+
public static LibertyServer server;
47+
48+
@BeforeClass
49+
public static void setUp() throws Exception {
50+
LOG.info("Setup : " + APP_NAME);
51+
ShrinkHelper.defaultDropinApp(server, APP_NAME + ".war", "filecountmax");
52+
53+
// Start the server and use the class name so we can find logs easily.
54+
server.startServer(WCFileUpLoadFileCountMaxTest.class.getSimpleName() + ".log");
55+
LOG.info("Setup : complete, ready for Tests");
56+
}
57+
58+
@AfterClass
59+
public static void tearDown() throws Exception {
60+
LOG.info("tearDown : stop server");
61+
62+
if (server != null && server.isStarted()) {
63+
server.stopServer();
64+
}
65+
}
66+
67+
/**
68+
* Test default setting by set 5000 fields/files in the upload.
69+
*
70+
*/
71+
@Test
72+
public void testFileUpload_default5000Files() throws Exception {
73+
int totalFiles = 5000;
74+
String expectedResponse = "Test Complete. Received parts size [5000]";
75+
String url = "http://" + server.getHostname() + ":" + server.getHttpDefaultPort() + "/" + APP_NAME + "/GetPartName";
76+
77+
MultipartEntityBuilder builder = createMultiPartData(totalFiles);
78+
HttpPost postRequest = new HttpPost(url);
79+
postRequest.setEntity(builder.build());
80+
81+
LOG.info("\nSending [" + totalFiles + "] multipart Post Request to [" + url + "");
82+
83+
try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
84+
try (final CloseableHttpResponse response = client.execute(postRequest)) {
85+
LOG.info("Request result: " + response.getReasonPhrase());
86+
LOG.info("Status code: " + response.getCode());
87+
LOG.info("Expected response contains: [" + expectedResponse + "]");
88+
89+
String content = EntityUtils.toString(response.getEntity());
90+
LOG.info("Actual response: \n" + content);
91+
EntityUtils.consume(response.getEntity());
92+
93+
assertTrue("Response did not contain expected response: [" + expectedResponse + "]", content.contains(expectedResponse));
94+
}
95+
}
96+
}
97+
98+
/**
99+
* Test Exception by sending 5001 over max (5k) file count in the upload.
100+
* The servlet will catch and report back the Exception in its response.
101+
*
102+
*/
103+
@Test
104+
public void testFileUpload_overMaxFileCount() throws Exception {
105+
int totalFiles = 5001;
106+
String expectedResponse = "CWWWC0006E";
107+
String url = "http://" + server.getHostname() + ":" + server.getHttpDefaultPort() + "/" + APP_NAME + "/GetPartName";
108+
109+
MultipartEntityBuilder builder = createMultiPartData(totalFiles);
110+
HttpPost postRequest = new HttpPost(url);
111+
postRequest.setEntity(builder.build());
112+
113+
LOG.info("\nSending [" + totalFiles + "] multipart Post Request to [" + url + "");
114+
115+
try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
116+
try (final CloseableHttpResponse response = client.execute(postRequest)) {
117+
LOG.info("Request result: " + response.getReasonPhrase());
118+
LOG.info("Status code: " + response.getCode());
119+
LOG.info("Expected response contains: [" + expectedResponse + "]");
120+
121+
String content = EntityUtils.toString(response.getEntity());
122+
LOG.info("Actual response: \n" + content);
123+
EntityUtils.consume(response.getEntity());
124+
125+
assertTrue("Response did not contain expected response: [" + expectedResponse + "]", content.contains(expectedResponse));
126+
}
127+
}
128+
}
129+
130+
private MultipartEntityBuilder createMultiPartData(int parameterNum) {
131+
LOG.info("====== createMultiPartData creating [" + parameterNum + "] parts ======");
132+
MultipartEntityBuilder eBuilder = MultipartEntityBuilder.create();
133+
String name = "Name_";
134+
String value = "Value_";
135+
136+
for (int i = 0; i < parameterNum; i++) {
137+
eBuilder.addTextBody(name + i, value + i);
138+
}
139+
return eBuilder;
140+
}
141+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
###############################################################################
2+
# Copyright (c) 2023 IBM Corporation and others.
3+
# All rights reserved. This program and the accompanying materials
4+
# are made available under the terms of the Eclipse Public License 2.0
5+
# which accompanies this distribution, and is available at
6+
# http://www.eclipse.org/legal/epl-2.0/
7+
#
8+
# SPDX-License-Identifier: EPL-2.0
9+
#
10+
# Contributors:
11+
# IBM Corporation - initial API and implementation
12+
###############################################################################
13+
bootstrap.include=../testports.properties
14+
osgi.console=7777
15+
com.ibm.ws.logging.trace.specification=*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:GenericBNF=all
16+
com.ibm.ws.logging.max.file.size=20
17+
com.ibm.ws.logging.max.files=10
18+
com.ibm.ws.logging.trace.format=BASIC
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<server description="Server for testing FileUpload 1.5 fileCountMax property">
2+
<include location="../fatTestPorts.xml"/>
3+
<featureManager>
4+
<feature>servlet-4.0</feature>
5+
</featureManager>
6+
7+
</server>

0 commit comments

Comments
 (0)