- Published on
Configuring Tomcat in Azure App Service: Increase maxParameterCount
- Authors
- Name
- Jeevan Wijerathna
- @iamjeevanvj
When hosting Java web applications on Azure App Service using Tomcat, you might encounter issues with legacy Java applications due to the default maxParameterCount
limit (1000). For legacy applications handling large forms or query strings, this limit can block expected behavior and cause request failures.
In this guide, I'll walk you through a quick and effective way to increase the maxParameterCount
parameter to 10000 using a custom startup script in Azure App Service.
Understanding the Problem
By default, Tomcat sets a limit of 1000 parameters that can be processed in a single HTTP request. This includes:
- Form fields in POST requests
- URL parameters in query strings
- Multiple values for the same parameter name
When your application exceeds this limit, Tomcat will ignore additional parameters, potentially breaking your application's functionality without clear error messages.
Solution: Custom Startup Script
We'll create a startup script that:
- Modifies the
server.xml
configuration file - Updates the
maxParameterCount
value - Starts Tomcat with the new configuration
Step 1: Create a Startup Script
There are several ways to create and upload the startup script to your Azure App Service:
Option 1: Using the Kudu Console (Azure App Service Advanced Tools)
- Navigate to your Azure App Service in the Azure Portal
- Go to Development Tools > Advanced Tools > Go
- In the Kudu console, click on Debug console > SSH
- Navigate to the
/home
directory - Click on the + button > New File and name it
startup.sh
- Copy and paste the following script:
#!/bin/bash
# Update maxParameterCount from 1000 to 10000 in server.xmlset -e
SERVER_XML="/usr/local/tomcat/conf/server.xml"NEW_VALUE="10000"
echo "[$(date)] Starting Tomcat configuration update..."
# Backup original filecp "$SERVER_XML" "${SERVER_XML}.backup"echo "[$(date)] Backup created."
# Update valuesed -i 's/maxParameterCount="1000"/maxParameterCount="'"$NEW_VALUE"'"/g' "$SERVER_XML"echo "[$(date)] Updated maxParameterCount to $NEW_VALUE"
# Verify updateif grep -q "maxParameterCount=\"$NEW_VALUE\"" "$SERVER_XML"; then echo "[$(date)] Configuration update successful"else echo "[$(date)] ERROR: Update failed, restoring backup" cp "${SERVER_XML}.backup" "$SERVER_XML" exit 1fi
# Start Tomcatecho "[$(date)] Starting Tomcat..."exec catalina.sh run
- Save the file
- In the SSH console, run:
chmod +x /home/startup.sh
Option 2: Using FTP/FTPS
- Set up FTP/FTPS credentials in your App Service (under Deployment Center > FTPS credentials)
- Create the script locally on your computer
- Upload the file to the
/home
directory using your preferred FTP client (like FileZilla) - Connect to the Kudu SSH console as described above and run:
chmod +x /home/startup.sh
Option 3: Using Azure CLI
- Create the script locally on your computer (e.g.,
startup.sh
) - Use Azure CLI to upload it:
# Login to Azureaz login# Set your subscription (if you have multiple)az account set --subscription <your-subscription-id># Upload the file to the App Serviceaz webapp deploy --resource-group <your-resource-group> --name <your-app-name> --src-path startup.sh --target-path /home/startup.sh# Connect to the App Service using SSHaz webapp ssh --resource-group <your-resource-group> --name <your-app-name># Inside the SSH session, make the script executablechmod +x /home/startup.sh
This script performs the following operations:
- Creates a backup of the original configuration file
- Uses
sed
to replace the default value with our new value - Verifies the change was successful
- Starts Tomcat with the updated configuration
Step 2: Configure App Service to Use the Script
- Navigate to your Azure App Service in the Azure Portal
- Go to Configuration > General settings
- In the Startup Command field, enter:
/home/startup.sh
- Click Save
Verification and Testing
After deploying your changes:
- Check the application logs in Log stream to verify the script executed successfully
- Look for messages like:
[date] Updated maxParameterCount to 10000
and[date] Configuration update successful
- Test your application with a request that contains more than 1000 parameters
Important Considerations
- Always test configuration changes in a staging slot before deploying to production
- This approach assumes you're using Tomcat on Linux in Azure App Service
- The exact path to
server.xml
may vary depending on your Tomcat version and configuration - Consider security implications of increasing this limit, as very large requests could potentially be used in DoS attacks
Conclusion
By implementing this custom startup script, you can easily increase Tomcat's maxParameterCount
to handle larger requests in your Azure App Service. This approach ensures the configuration is applied consistently each time your application starts, avoiding the need for manual intervention after deployments or service restarts.
For more complex scenarios or additional Tomcat configuration needs, you might consider creating a custom Docker image with your preferred settings pre-configured.