Skip to content

Commit

Permalink
Merge pull request #24959 from pmd1nh/24958-New_Configurable_Property…
Browse files Browse the repository at this point in the history
…_For_FileUpload

Add new configurable property for fileUpload
  • Loading branch information
pmd1nh committed Apr 16, 2023
2 parents 8112f1c + 833d22a commit 59aab9d
Show file tree
Hide file tree
Showing 20 changed files with 483 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ symbolicName=com.ibm.websphere.appserver.servlet-servletSpi1.0
WLP-DisableAllFeatures-OnConflict: false
visibility=private
-jars=com.ibm.websphere.appserver.spi.servlet; location:=dev/spi/ibm/
-files=dev/spi/ibm/javadoc/com.ibm.websphere.appserver.spi.servlet_2.10-javadoc.zip
-files=dev/spi/ibm/javadoc/com.ibm.websphere.appserver.spi.servlet_2.11-javadoc.zip
kind=ga
edition=core
WLP-Activation-Type: parallel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
symbolicName=io.openliberty.servlet-servletSpi2.0
visibility=private
-jars=io.openliberty.servlet.spi; location:=dev/spi/ibm/
-files=dev/spi/ibm/javadoc/io.openliberty.servlet.spi_2.10-javadoc.zip
-files=dev/spi/ibm/javadoc/io.openliberty.servlet.spi_2.11-javadoc.zip
kind=ga
edition=core
WLP-Activation-Type: parallel
2 changes: 1 addition & 1 deletion dev/com.ibm.websphere.appserver.spi.servlet/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

-sub: *.bnd

bVersion: 2.10
bVersion: 2.11

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

Expand Down
1 change: 1 addition & 0 deletions dev/com.ibm.ws.webcontainer.servlet.4.0_fat/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="fat/src"/>
<classpathentry kind="src" path="test-applications/FileUploadFileCountMaxTest.war/src"/>
<classpathentry kind="src" path="test-applications/TestEncoding.war/src"/>
<classpathentry kind="src" path="test-applications/TestServlet40.war/src"/>
<classpathentry kind="src" path="test-applications/TestServlet40.jar/src"/>
Expand Down
3 changes: 2 additions & 1 deletion dev/com.ibm.ws.webcontainer.servlet.4.0_fat/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
# Copyright (c) 2017, 2022 IBM Corporation and others.
# Copyright (c) 2017, 2023 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
Expand All @@ -15,6 +15,7 @@ bVersion=1.0

src: \
fat/src,\
test-applications/FileUploadFileCountMaxTest.war/src,\
test-applications/TestServlet40.war/src,\
test-applications/TestServlet40.jar/src,\
test-applications/TestGetMapping.war/src,\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2012, 2022 IBM Corporation and others.
* Copyright (c) 2012, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand All @@ -25,6 +25,8 @@
import com.ibm.ws.fat.wc.tests.WCApplicationMBeanStatusTest;
import com.ibm.ws.fat.wc.tests.WCContextRootPrecedence;
import com.ibm.ws.fat.wc.tests.WCEncodingTest;
import com.ibm.ws.fat.wc.tests.WCFileUpLoadFileCountMaxPropertyTest;
import com.ibm.ws.fat.wc.tests.WCFileUpLoadFileCountMaxTest;
import com.ibm.ws.fat.wc.tests.WCGetMappingSlashStarTest;
import com.ibm.ws.fat.wc.tests.WCGetMappingTest;
import com.ibm.ws.fat.wc.tests.WCPushBuilderTest;
Expand Down Expand Up @@ -78,6 +80,8 @@
WCAddJspFileTest.class,
WCTrailersTest.class,
WCEncodingTest.class,
WCFileUpLoadFileCountMaxPropertyTest.class,
WCFileUpLoadFileCountMaxTest.class,
WCServerTest.class,
WC5JakartaServletTest.class,
WCGetMappingTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*******************************************************************************
* Copyright (c) 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package com.ibm.ws.fat.wc.tests;

import static org.junit.Assert.assertTrue;

import java.util.logging.Logger;

import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.ShrinkHelper;

import componenttest.annotation.Server;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.custom.junit.runner.Mode;
import componenttest.custom.junit.runner.Mode.TestMode;
import componenttest.topology.impl.LibertyServer;

/**
* Test FileUpload 1.5's property fileCountMax=-1 which is unlimited
* Send more than 5k params in body and verify working
* Send more than 10k params which exceeding the maxparamperrequest's default limit of 10000 and cause exception.
*/
@RunWith(FATRunner.class)
@Mode(TestMode.FULL)
public class WCFileUpLoadFileCountMaxPropertyTest {

private static final Logger LOG = Logger.getLogger(WCFileUpLoadFileCountMaxPropertyTest.class.getName());
private static final String APP_NAME = "FileUploadFileCountMaxTest";

@Server("servlet40_FileUploadFileCountMaxProperty")
public static LibertyServer server;

@BeforeClass
public static void setUp() throws Exception {
LOG.info("Setup : " + APP_NAME);
ShrinkHelper.defaultDropinApp(server, APP_NAME + ".war", "filecountmax");

// Start the server and use the class name so we can find logs easily.
server.startServer(WCFileUpLoadFileCountMaxPropertyTest.class.getSimpleName() + ".log");
LOG.info("Setup : complete, ready for Tests");
}

@AfterClass
public static void tearDown() throws Exception {
LOG.info("tearDown : stop server");

if (server != null && server.isStarted()) {
//Expecting the Error during the param parsing
server.stopServer("SRVE0133E");
}
}

/**
* Test webContainer maxFileCount=-1
* Send in 5555 files/parts
* Verify no Exception.
*/
@Test
public void testFileUpload_overMaxFileCountWithProperty() throws Exception {
int totalFiles = 5555;
String expectedResponse = "Test Complete. Received parts size [" + totalFiles + "]";
String url = "http://" + server.getHostname() + ":" + server.getHttpDefaultPort() + "/" + APP_NAME + "/GetPartName";

MultipartEntityBuilder builder = createMultiPartData(totalFiles);
HttpPost postRequest = new HttpPost(url);
postRequest.setEntity(builder.build());

LOG.info("\nSending [" + totalFiles + "] multipart Post Request to [" + url + "");

try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (final CloseableHttpResponse response = client.execute(postRequest)) {
LOG.info("Request result: " + response.getReasonPhrase());
LOG.info("Status code: " + response.getCode());
LOG.info("Expected response contains: [" + expectedResponse + "]");

String content = EntityUtils.toString(response.getEntity());
LOG.info("Actual response: \n" + content);
EntityUtils.consume(response.getEntity());

assertTrue("Response did not contain expected response: [" + expectedResponse + "] ; Actual response [" + content + "]", content.contains(expectedResponse));
}
}
}

/**
* Test webContainer maxFileCount=-1
* Send in 10,001 files/parts. This will cause exception because it exceeds maxparamperrequest default limit of 10,000
* Expecting SRVE0133E
*/
@Test
public void testFileUpload_over10KWithProperty() throws Exception {
int totalFiles = 10001;
String expectedResponse = "SRVE0325E: Exceeding maximum parameters allowed per request";
String url = "http://" + server.getHostname() + ":" + server.getHttpDefaultPort() + "/" + APP_NAME + "/GetPartName";

MultipartEntityBuilder builder = createMultiPartData(totalFiles);
HttpPost postRequest = new HttpPost(url);
postRequest.setEntity(builder.build());

LOG.info("\nSending [" + totalFiles + "] multipart Post Request to [" + url + "");

try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (final CloseableHttpResponse response = client.execute(postRequest)) {
LOG.info("Request result: " + response.getReasonPhrase());
LOG.info("Status code: " + response.getCode());
LOG.info("Expected response contains: [" + expectedResponse + "]");

String content = EntityUtils.toString(response.getEntity());
LOG.info("Actual response: \n" + content);
EntityUtils.consume(response.getEntity());

assertTrue("Response did not contain expected response: [" + expectedResponse + "] ; Actual response [" + content + "]", content.contains(expectedResponse));
}
}
}

private MultipartEntityBuilder createMultiPartData(int parameterNum) {
LOG.info("====== createMultiPartData creating [" + parameterNum + "] parts ======");
MultipartEntityBuilder eBuilder = MultipartEntityBuilder.create();
String name = "Name_";
String value = "Value_";

for (int i = 0; i < parameterNum; i++) {
eBuilder.addTextBody(name + i, value + i);
}
return eBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*******************************************************************************
* Copyright (c) 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package com.ibm.ws.fat.wc.tests;

import static org.junit.Assert.assertTrue;

import java.util.logging.Logger;

import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.ShrinkHelper;

import componenttest.annotation.Server;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.custom.junit.runner.Mode;
import componenttest.custom.junit.runner.Mode.TestMode;
import componenttest.topology.impl.LibertyServer;

/**
* Test FileUpload 1.5 with default value of fileCountMax
*/
@RunWith(FATRunner.class)
@Mode(TestMode.FULL)
public class WCFileUpLoadFileCountMaxTest {

private static final Logger LOG = Logger.getLogger(WCFileUpLoadFileCountMaxTest.class.getName());
private static final String APP_NAME = "FileUploadFileCountMaxTest";

@Server("servlet40_FileUploadFileCountMax")
public static LibertyServer server;

@BeforeClass
public static void setUp() throws Exception {
LOG.info("Setup : " + APP_NAME);
ShrinkHelper.defaultDropinApp(server, APP_NAME + ".war", "filecountmax");

// Start the server and use the class name so we can find logs easily.
server.startServer(WCFileUpLoadFileCountMaxTest.class.getSimpleName() + ".log");
LOG.info("Setup : complete, ready for Tests");
}

@AfterClass
public static void tearDown() throws Exception {
LOG.info("tearDown : stop server");

if (server != null && server.isStarted()) {
server.stopServer();
}
}

/**
* Test default setting by set 5000 fields/files in the upload.
*
*/
@Test
public void testFileUpload_default5000Files() throws Exception {
int totalFiles = 5000;
String expectedResponse = "Test Complete. Received parts size [5000]";
String url = "http://" + server.getHostname() + ":" + server.getHttpDefaultPort() + "/" + APP_NAME + "/GetPartName";

MultipartEntityBuilder builder = createMultiPartData(totalFiles);
HttpPost postRequest = new HttpPost(url);
postRequest.setEntity(builder.build());

LOG.info("\nSending [" + totalFiles + "] multipart Post Request to [" + url + "");

try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (final CloseableHttpResponse response = client.execute(postRequest)) {
LOG.info("Request result: " + response.getReasonPhrase());
LOG.info("Status code: " + response.getCode());
LOG.info("Expected response contains: [" + expectedResponse + "]");

String content = EntityUtils.toString(response.getEntity());
LOG.info("Actual response: \n" + content);
EntityUtils.consume(response.getEntity());

assertTrue("Response did not contain expected response: [" + expectedResponse + "]", content.contains(expectedResponse));
}
}
}

/**
* Test Exception by sending 5001 over max (5k) file count in the upload.
* The servlet will catch and report back the Exception in its response.
*
*/
@Test
public void testFileUpload_overMaxFileCount() throws Exception {
int totalFiles = 5001;
String expectedResponse = "CWWWC0006E";
String url = "http://" + server.getHostname() + ":" + server.getHttpDefaultPort() + "/" + APP_NAME + "/GetPartName";

MultipartEntityBuilder builder = createMultiPartData(totalFiles);
HttpPost postRequest = new HttpPost(url);
postRequest.setEntity(builder.build());

LOG.info("\nSending [" + totalFiles + "] multipart Post Request to [" + url + "");

try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (final CloseableHttpResponse response = client.execute(postRequest)) {
LOG.info("Request result: " + response.getReasonPhrase());
LOG.info("Status code: " + response.getCode());
LOG.info("Expected response contains: [" + expectedResponse + "]");

String content = EntityUtils.toString(response.getEntity());
LOG.info("Actual response: \n" + content);
EntityUtils.consume(response.getEntity());

assertTrue("Response did not contain expected response: [" + expectedResponse + "]", content.contains(expectedResponse));
}
}
}

private MultipartEntityBuilder createMultiPartData(int parameterNum) {
LOG.info("====== createMultiPartData creating [" + parameterNum + "] parts ======");
MultipartEntityBuilder eBuilder = MultipartEntityBuilder.create();
String name = "Name_";
String value = "Value_";

for (int i = 0; i < parameterNum; i++) {
eBuilder.addTextBody(name + i, value + i);
}
return eBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
###############################################################################
# Copyright (c) 2023 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
bootstrap.include=../testports.properties
osgi.console=7777
com.ibm.ws.logging.trace.specification=*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:GenericBNF=all
com.ibm.ws.logging.max.file.size=20
com.ibm.ws.logging.max.files=10
com.ibm.ws.logging.trace.format=BASIC
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<server description="Server for testing FileUpload 1.5 fileCountMax property">
<include location="../fatTestPorts.xml"/>
<featureManager>
<feature>servlet-4.0</feature>
</featureManager>

</server>
Loading

0 comments on commit 59aab9d

Please sign in to comment.