Embedded Apache Tomcat servlet container with Jakarta Servlet API, HTTP connectors, and lifecycle management for Java web applications
Coyote connector architecture provides protocol handlers for HTTP/1.1, HTTP/2, and AJP protocols. Connectors manage network I/O, thread pools, connection limits, and protocol-specific processing to efficiently handle incoming requests and generate responses.
Main connector implementation managing protocol handlers and network configuration.
public class Connector extends LifecycleMBeanBase {
// Constructors
public Connector();
public Connector(String protocol);
public Connector(ProtocolHandler protocolHandler);
// Protocol configuration
public String getProtocol();
public String getProtocolHandlerClassName();
public ProtocolHandler getProtocolHandler();
// Network configuration
public int getPort();
public void setPort(int port);
public int getPortOffset();
public void setPortOffset(int portOffset);
public int getPortWithOffset();
public int getLocalPort();
// Scheme and security
public String getScheme();
public void setScheme(String scheme);
public boolean getSecure();
public void setSecure(boolean secure);
// Async timeout configuration
public long getAsyncTimeout();
public void setAsyncTimeout(long asyncTimeout);
// Request configuration
public int getMaxPostSize();
public void setMaxPostSize(int maxPostSize);
public int getMaxSavePostSize();
public void setMaxSavePostSize(int maxSavePostSize);
public int getMaxParameterCount();
public void setMaxParameterCount(int maxParameterCount);
public int getMaxCookieCount();
public void setMaxCookieCount(int maxCookieCount);
public String getParseBodyMethods();
public void setParseBodyMethods(String methods);
// Encoding
public String getURIEncoding();
public void setURIEncoding(String URIEncoding);
public Charset getURICharset();
public boolean getUseBodyEncodingForURI();
public void setUseBodyEncodingForURI(boolean useBodyEncodingForURI);
public String getEncodedSolidusHandling();
public void setEncodedSolidusHandling(String encodedSolidusHandling);
public String getEncodedReverseSolidusHandling();
public void setEncodedReverseSolidusHandling(String encodedReverseSolidusHandling);
// Proxy configuration
public String getProxyName();
public void setProxyName(String proxyName);
public int getProxyPort();
public void setProxyPort(int proxyPort);
// Redirect configuration
public int getRedirectPort();
public void setRedirectPort(int redirectPort);
public int getRedirectPortWithOffset();
// Service reference
public Service getService();
public void setService(Service service);
// Request/Response creation
public Request createRequest();
public Response createResponse();
// Protocol handler properties (delegated via reflection)
public boolean setProperty(String name, String value);
public Object getProperty(String name);
// Utility configuration
public boolean getAllowBackslash();
public void setAllowBackslash(boolean allowBackslash);
public boolean getAllowTrace();
public void setAllowTrace(boolean allowTrace);
public boolean getEnableLookups();
public void setEnableLookups(boolean enableLookups);
public boolean getDiscardFacades();
public void setDiscardFacades(boolean discardFacades);
public boolean getEnforceEncodingInGetWriter();
public void setEnforceEncodingInGetWriter(boolean enforceEncodingInGetWriter);
public boolean getXpoweredBy();
public void setXpoweredBy(boolean xpoweredBy);
public boolean getUseIPVHosts();
public void setUseIPVHosts(boolean useIPVHosts);
public boolean getRejectSuspiciousURIs();
public void setRejectSuspiciousURIs(boolean rejectSuspiciousURIs);
// SSL configuration
public void addSslHostConfig(SSLHostConfig sslHostConfig);
public SSLHostConfig[] findSslHostConfigs();
// Protocol upgrades
public void addUpgradeProtocol(UpgradeProtocol upgradeProtocol);
public UpgradeProtocol[] findUpgradeProtocols();
// Executor
public String getExecutorName();
public void setExecutorName(String executorName);
// Lifecycle methods
public void init() throws LifecycleException;
public void start() throws LifecycleException;
public void stop() throws LifecycleException;
public void destroy() throws LifecycleException;
public void pause();
public void resume();
public LifecycleState getState();
public String getStateName();
// Management
public String getDomain();
public ObjectName getObjectName();
// Lifecycle listeners
public void addLifecycleListener(LifecycleListener listener);
public void removeLifecycleListener(LifecycleListener listener);
public LifecycleListener[] findLifecycleListeners();
}The Connector class delegates many configuration properties to its underlying ProtocolHandler using the setProperty(String name, String value) method. Common properties include:
These properties are accessed via reflection on the ProtocolHandler implementation.
Base interfaces for protocol implementations.
public interface ProtocolHandler {
// Configuration
public void setAdapter(Adapter adapter);
public Adapter getAdapter();
// Executor
public Executor getExecutor();
// Lifecycle
public void init() throws Exception;
public void start() throws Exception;
public void pause() throws Exception;
public void resume() throws Exception;
public void stop() throws Exception;
public void destroy() throws Exception;
// Socket utilities
public boolean isSendfileSupported();
}
public interface Adapter {
public void service(org.apache.coyote.Request req, org.apache.coyote.Response res)
throws Exception;
public boolean prepare(org.apache.coyote.Request req, org.apache.coyote.Response res)
throws Exception;
public boolean asyncDispatch(org.apache.coyote.Request req, org.apache.coyote.Response res,
SocketEvent status) throws Exception;
public void log(org.apache.coyote.Request req, org.apache.coyote.Response res, long time);
public void checkRecycled(org.apache.coyote.Request req, org.apache.coyote.Response res);
public String getDomain();
}Low-level request/response objects used by protocol handlers.
// Coyote Request
public final class Request {
// Request line
public MessageBytes method();
public MessageBytes requestURI();
public MessageBytes decodedURI();
public MessageBytes queryString();
public MessageBytes protocol();
// Headers
public MimeHeaders getMimeHeaders();
public int getServerPort();
public void setServerPort(int port);
public MessageBytes serverName();
// Request body
public InputBuffer getInputBuffer();
public void setInputBuffer(InputBuffer inputBuffer);
public int doRead(ApplicationBufferHandler handler) throws IOException;
public int getAvailable();
public boolean isFinished();
// Attributes
public void setAttribute(String name, Object o);
public Object getAttribute(String name);
// Content
public long getContentLengthLong();
public String getContentType();
// Connection
public MessageBytes remoteAddr();
public MessageBytes remoteHost();
public int getRemotePort();
public MessageBytes localAddr();
public int getLocalPort();
public MessageBytes localName();
// Lifecycle
public void recycle();
// Async
public boolean isAsync();
}
// Coyote Response
public final class Response {
// Status
public void setStatus(int status);
public int getStatus();
public String getMessage();
public void setMessage(String message);
// Headers
public MimeHeaders getMimeHeaders();
public void setContentLength(long length);
public long getContentLength();
public void setContentType(String type);
public String getContentType();
// Response body
public OutputBuffer getOutputBuffer();
public void setOutputBuffer(OutputBuffer outputBuffer);
public int doWrite(ByteBuffer chunk) throws IOException;
// State
public boolean isCommitted();
public void setCommitted(boolean committed);
public void action(ActionCode actionCode, Object param);
// Error
public void setErrorException(Exception ex);
public Exception getErrorException();
// Lifecycle
public void recycle();
// Async
public boolean isAsync();
}import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.connector.Connector;
public class ConnectorConfigExample {
public static void main(String[] args) throws Exception {
Tomcat tomcat = new Tomcat();
// HTTP/1.1 NIO connector
Connector connector = new Connector("HTTP/1.1");
connector.setPort(8080);
connector.setScheme("http");
// Configure protocol handler properties via setProperty
connector.setProperty("maxThreads", "200");
connector.setProperty("minSpareThreads", "10");
connector.setProperty("maxConnections", "10000");
connector.setProperty("connectionTimeout", "20000");
connector.setProperty("compression", "on");
connector.setProperty("compressionMinSize", "2048");
connector.setProperty("compressibleMimeType",
"text/html,text/xml,text/plain,text/css,application/json");
tomcat.setConnector(connector);
tomcat.start();
tomcat.getServer().await();
}
}Install with Tessl CLI
npx tessl i tessl/maven-org-apache-tomcat-embed--tomcat-embed-core