Apache Tomcat 11 + Axis2 HTTP/2 Integration Guide

🚀 Apache Tomcat 11 HTTP/2 - Excellent Support with Simplified Configuration

Tomcat 11 HTTP/2 Configuration (Production-Optimized)

1. Complete server.xml HTTP/2 Configuration

<!-- Apache Tomcat 11 - HTTP/2 Optimized Configuration -->
<!-- Aligned with Axis2 Enhanced Moshi H2 Processing -->

<Server port="8005" shutdown="SHUTDOWN">

  <!-- Global Naming Resources -->
  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- Thread Pool for HTTP/2 Optimization -->
  <!-- Aligned with Axis2 Enhanced Moshi H2 async processing -->
  <Service name="Catalina">

    <!-- HTTP/2 Thread Pool Configuration: maxThreads matches the
         HTTP/2 concurrent stream limit; idle threads expire after 10 minutes -->
    <Executor name="tomcatThreadPool"
              namePrefix="catalina-exec-"
              maxThreads="200"
              minSpareThreads="20"
              maxIdleTime="600000"
              prestartminSpareThreads="true" />

    <!-- HTTP Connector (HTTP/1.1, redirects to HTTPS).
         maxPostSize: 100MB for large JSON payloads;
         connectionTimeout / keepAliveTimeout: 5 minutes for large payload processing;
         compression: compress JSON responses larger than 2KB -->
    <Connector executor="tomcatThreadPool"
               port="8080"
               protocol="HTTP/1.1"
               redirectPort="8443"
               maxPostSize="104857600"
               connectionTimeout="300000"
               keepAliveTimeout="300000"
               maxKeepAliveRequests="1000"
               compression="on"
               compressionMinSize="2048"
               compressibleMimeType="application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css" />

    <!-- HTTPS Connector with HTTP/2 (negotiated with ALPN).
         Tomcat 11 has no APR connector: use the NIO connector, with JSSE or OpenSSL. -->
    <Connector executor="tomcatThreadPool"
               port="8443"
               protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxPostSize="104857600"
               SSLEnabled="true"
               scheme="https"
               secure="true"
               connectionTimeout="300000"
               keepAliveTimeout="300000"
               compression="on"
               compressionMinSize="2048"
               compressibleMimeType="application/json,application/xml">

        <!-- HTTP/2 settings belong on the nested UpgradeProtocol element.
             initialWindowSize 2MB avoids flow-control round trips on large
             responses; compression settings are inherited from the Connector. -->
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol"
                         maxConcurrentStreams="200"
                         initialWindowSize="2097152"
                         keepAliveTimeout="300000"
                         readTimeout="300000"
                         writeTimeout="300000" />

        <!-- TLS configuration: TLS 1.2 and 1.3 only -->
        <SSLHostConfig protocols="TLSv1.2+TLSv1.3">
            <Certificate certificateFile="/path/to/your/certificate.crt"
                         certificateKeyFile="/path/to/your/private.key"
                         certificateChainFile="/path/to/your/chain.crt"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

    <!-- Engine Configuration -->
    <Engine name="Catalina" defaultHost="localhost">

      <!-- Host Configuration with HTTP/2 Access Logging -->
      <Host name="localhost"
            appBase="webapps"
            unpackWARs="true"
            autoDeploy="true">

        <!-- HTTP/2 + JSON Performance Access Log -->
        <Valve className="org.apache.catalina.valves.AccessLogValve"
               directory="logs"
               prefix="axis2_http2_access_log"
               suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b %D Protocol:%H JSON-Size:%{Content-Length}o Time:%T" />

      </Host>
    </Engine>
  </Service>
</Server>

2. Key Configuration Highlights

Parameter Tomcat 11 Value Optimization Purpose WildFly Equivalent
UpgradeProtocol maxConcurrentStreams 200 High multiplexing for large JSON APIs http2-max-concurrent-streams="200"
UpgradeProtocol initialWindowSize 2097152 (2MB) Avoids flow-control round trips on large responses http2-initial-window-size="2097152"
Connector maxPostSize 104857600 (100MB) Large JSON payload support max-post-size="104857600"
Connector connectionTimeout 300000 (5min) Large payload processing time no-request-timeout="300000"

Tomcat does not expose a setting for the HTTP/2 maximum frame size, and Tomcat 11 does not support HTTP/2 server push, which web services do not need.

Axis2 Integration Configuration

1. Enhanced axis2.xml for Tomcat HTTP/2

<!-- axis2.xml - Tomcat 11 + HTTP/2 + Enhanced Moshi H2 Configuration -->
<axisconfig name="AxisJava2.0-Tomcat11-HTTP2-EnhancedMoshiH2">

    <!-- JSON processing mode and Tomcat HTTP/2 tuning are configured in
         Tomcat's server.xml (compression, keep-alive, buffer sizes, etc.),
         not in axis2.xml.  Use the standard JSON message builder below. -->

    <!-- Enhanced JSON Message Builder -->
    <messageBuilder contentType="application/json"
                    class="org.apache.axis2.json.moshih2.EnhancedMoshiJsonBuilder"/>

    <!-- Enhanced JSON Message Formatter -->
    <messageFormatter contentType="application/json"
                      class="org.apache.axis2.json.moshih2.EnhancedMoshiJsonFormatter"/>

    <!-- HTTP/1.1 Transport (Fallback) -->
    <transportSender name="http"
                     class="org.apache.axis2.transport.http.impl.httpclient5.HTTPClient5TransportSender">
        <parameter name="PROTOCOL">HTTP/1.1</parameter>
    </transportSender>

    <!-- HTTP/2 Transport (Coordinated with Tomcat 11) -->
    <transportSender name="h2"
                     class="org.apache.axis2.transport.h2.impl.httpclient5.H2TransportSender">
        <parameter name="PROTOCOL">HTTP/2.0</parameter>

        <!-- Coordination with Tomcat 11 HTTP/2 -->
        <parameter name="maxConcurrentStreams">200</parameter>              <!-- Matches Tomcat -->
        <parameter name="initialWindowSize">2097152</parameter>             <!-- 2MB (default 64KB): avoids flow-control round trips -->
        <parameter name="maxConnectionsTotal">50</parameter>
        <parameter name="maxConnectionsPerRoute">10</parameter>
        <parameter name="connectionTimeout">60000</parameter>               <!-- 1 minute connection -->
        <parameter name="responseTimeout">300000</parameter>                <!-- 5min response timeout -->

        <!-- JSON streaming and compression are handled by the message formatter
             and Tomcat's server.xml respectively — no additional transport
             sender parameters are needed for Moshi or Tomcat integration. -->
    </transportSender>

</axisconfig>

Advanced Configuration Options

1. SSL/TLS Certificate Setup

Tomcat 11 simplifies SSL setup compared to WildFly. Tomcat 11 removed the APR/native connector; TLS is configured on the NIO connector with a nested SSLHostConfig, using either JSSE or OpenSSL.

Option A: PEM Certificate Files (Recommended for Production)

<SSLHostConfig protocols="TLSv1.2+TLSv1.3">
    <Certificate certificateFile="/etc/ssl/certs/your-domain.crt"
                 certificateKeyFile="/etc/ssl/private/your-domain.key"
                 certificateChainFile="/etc/ssl/certs/chain.crt"
                 type="RSA" />
</SSLHostConfig>

Option B: Java KeyStore SSL

# Generate keystore
keytool -genkeypair -keyalg RSA -keysize 2048 -keystore tomcat-keystore.p12 \
        -storetype PKCS12 -alias tomcat -dname "CN=your-domain.com,OU=IT,O=YourOrg,C=US"

# server.xml configuration
<Connector port="8443"
           protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxPostSize="104857600"
           SSLEnabled="true">
    <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
    <SSLHostConfig>
        <Certificate certificateKeystoreFile="/path/to/tomcat-keystore.p12"
                     certificateKeystorePassword="your-password"
                     certificateKeyAlias="tomcat"
                     type="RSA" />
    </SSLHostConfig>
</Connector>

2. Memory Optimization for HTTP/2 + JSON Processing

JVM Memory Settings (catalina.sh)

# Memory-optimized JVM settings for HTTP/2 + Enhanced Moshi H2
export CATALINA_OPTS="$CATALINA_OPTS -Xms2048m -Xmx4096m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:+UseG1GC"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxGCPauseMillis=200"
export CATALINA_OPTS="$CATALINA_OPTS -XX:G1HeapRegionSize=16m"

# Networking
export CATALINA_OPTS="$CATALINA_OPTS -Djava.net.preferIPv6Addresses=false"

HTTP/2 stream limits are set on the UpgradeProtocol element in server.xml, and the Enhanced Moshi H2 builder is selected and tuned in axis2.xml (for example the moshiAsyncProcessingThreshold parameter); neither is controlled by system properties.

3. Production Monitoring Configuration

Enhanced Access Logging

<!-- HTTP/2 + JSON Performance Monitoring -->
<Valve className="org.apache.catalina.valves.AccessLogValve"
       directory="logs"
       prefix="http2_performance"
       suffix=".log"
       pattern="%h %u %t "%r" %s %b %D Protocol:%H JSON-Size:%{Content-Length}o Compression:%{Accept-Encoding}i" />

Production Deployment Guide

1. Step-by-Step Deployment

Step 1: Install Tomcat 11

# Download and extract Tomcat 11
cd /opt
sudo wget https://downloads.apache.org/tomcat/tomcat-11/v11.0.x/bin/apache-tomcat-11.0.x.tar.gz
sudo tar -xzf apache-tomcat-11.0.x.tar.gz
sudo mv apache-tomcat-11.0.x tomcat11
sudo chown -R tomcat:tomcat /opt/tomcat11

Step 2: Configure HTTP/2 (Replace server.xml)

# Backup original configuration
sudo cp /opt/tomcat11/conf/server.xml /opt/tomcat11/conf/server.xml.backup

# Apply HTTP/2 optimized configuration (use the server.xml above)
sudo nano /opt/tomcat11/conf/server.xml

Step 3: Deploy Axis2 with Enhanced Moshi H2

# Deploy your Axis2 WAR with Enhanced Moshi H2
sudo cp your-axis2-app.war /opt/tomcat11/webapps/

# Configure axis2.xml with HTTP/2 settings (use configuration above)
# Update WEB-INF/conf/axis2.xml in your deployed WAR

Step 4: Configure SSL Certificates

# Place certificates in secure location
sudo mkdir -p /etc/tomcat11/ssl
sudo cp your-domain.crt /etc/tomcat11/ssl/
sudo cp your-domain.key /etc/tomcat11/ssl/
sudo chown -R tomcat:tomcat /etc/tomcat11/ssl
sudo chmod 600 /etc/tomcat11/ssl/*

Step 5: Start and Validate

# Start Tomcat
sudo systemctl start tomcat11

# Validate HTTP/2 is working
curl -k --http2 --location 'https://localhost:8443/your-app/services/YourService' \
     --header 'Content-Type: application/json' \
     --data '{"test": "HTTP/2 validation"}' \
     --trace-ascii trace.log

# Check for HTTP/2 in trace.log
grep "HTTP/2" trace.log

2. Performance Validation

Validate HTTP/2 Protocol Negotiation

# Test HTTP/2 negotiation
openssl s_client -connect localhost:8443 -alpn h2

# Expected output should show:
# ALPN protocol: h2
# Protocol: TLSv1.3

Test Large JSON Payload Processing

# Test large payload with Enhanced Moshi H2
curl -k --http2 -X POST 'https://localhost:8443/your-app/services/JsonService' \
     --header 'Content-Type: application/json' \
     --data @large-test-payload.json \
     --output response.json \
     --write-out "Time: %{time_total}s, Size: %{size_download} bytes, HTTP: %{http_version}\n"

# Should show HTTP/2.0 and fast processing times

3. Monitoring and Troubleshooting

HTTP/2 Metrics Monitoring

# Monitor access logs for HTTP/2 performance
tail -f /opt/tomcat11/logs/http2_performance.log

# Key metrics to watch:
# - Protocol: HTTP/2.0
# - Request processing times (%D)
# - Compression ratios

JVM Performance Monitoring

# Monitor JVM metrics
jstat -gc -t $(pgrep -f tomcat) 5s

# Monitor HTTP/2 connections
netstat -an | grep :8443 | grep ESTABLISHED | wc -l