CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-tomcat-embed--tomcat-embed-core

Embedded Apache Tomcat servlet container with Jakarta Servlet API, HTTP connectors, and lifecycle management for Java web applications

Overview
Eval results
Files

valves.mddocs/

Valves and Pipeline

Request processing pipeline using chain-of-responsibility pattern with valves for cross-cutting concerns including access logging, authentication, error handling, compression, URL rewriting, remote address filtering, and custom request/response processing.

Capabilities

Valve Interface

Base interface for all valves in the processing pipeline.

public interface Valve {
    // Next valve in chain
    Valve getNext();
    void setNext(Valve valve);
    
    // Processing
    void invoke(Request request, Response response) throws IOException, ServletException;
    boolean isAsyncSupported();
    
    // Background processing
    void backgroundProcess();
}

Pipeline Interface

Container for managing valve chains.

public interface Pipeline extends Contained {
    // Basic valve (end of chain)
    Valve getBasic();
    void setBasic(Valve valve);
    
    // Valve management
    void addValve(Valve valve);
    Valve[] getValves();
    void removeValve(Valve valve);
    Valve getFirst();
    
    // Async support
    boolean isAsyncSupported();
    void findNonAsyncValves(Set<String> result);
}

Common Valve Types

Standard valves provided by Tomcat.

// Access logging valve
public class AccessLogValve extends ValveBase implements AccessLog {
    // Log pattern configuration
    public void setPattern(String pattern);
    public String getPattern();
    
    // File configuration
    public void setDirectory(String directory);
    public String getDirectory();
    public void setPrefix(String prefix);
    public String getPrefix();
    public void setSuffix(String suffix);
    public String getSuffix();
    
    // Rotation
    public void setRotatable(boolean rotatable);
    public boolean isRotatable();
    public void setFileDateFormat(String fileDateFormat);
    public String getFileDateFormat();
    
    // Buffering
    public void setBuffered(boolean buffered);
    public boolean isBuffered();
    
    // Request attributes
    public void setRequestAttributesEnabled(boolean requestAttributesEnabled);
    public boolean getRequestAttributesEnabled();
    
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException;
    public void log(Request request, Response response, long time);
}

// Error report valve
public class ErrorReportValve extends ValveBase {
    public void setShowReport(boolean showReport);
    public boolean isShowReport();
    public void setShowServerInfo(boolean showServerInfo);
    public boolean isShowServerInfo();
    
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException;
}

// Remote address filter valve
public class RemoteAddrValve extends RequestFilterValve {
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException;
}

// Remote host filter valve
public class RemoteHostValve extends RequestFilterValve {
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException;
}

// Remote IP valve (X-Forwarded-For handling)
public class RemoteIpValve extends ValveBase {
    public void setRemoteIpHeader(String header);
    public void setProxiesHeader(String header);
    public void setTrustedProxies(String trustedProxies);
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException;
}

// SSL valve (SSL termination support)
public class SSLValve extends ValveBase {
    public void setSslCipherHeader(String header);
    public void setSslSessionIdHeader(String header);
    public void setSslClientCertHeader(String header);
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException;
}

// Stuck thread detection valve
public class StuckThreadDetectionValve extends ValveBase {
    public void setThreshold(int threshold);
    public void setInterruptThreadThreshold(int interruptThreadThreshold);
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException;
}

Usage Examples

Adding Custom Valve

import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.valves.ValveBase;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.Context;
import jakarta.servlet.ServletException;
import java.io.IOException;

public class CustomValveExample extends ValveBase {
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException {
        // Pre-processing
        long startTime = System.currentTimeMillis();
        System.out.println("Request: " + request.getRequestURI());
        
        // Continue chain
        getNext().invoke(request, response);
        
        // Post-processing
        long duration = System.currentTimeMillis() - startTime;
        System.out.println("Completed in " + duration + "ms");
    }
    
    public static void main(String[] args) throws Exception {
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8080);
        
        Context ctx = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
        
        // Add custom valve
        ctx.getPipeline().addValve(new CustomValveExample());
        
        tomcat.start();
        tomcat.getServer().await();
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-tomcat-embed--tomcat-embed-core

docs

authentication.md

catalina-core.md

connectors.md

embedded-tomcat.md

index.md

logging.md

servlet-api.md

session-management.md

utilities.md

valves.md

web-resources.md

tile.json