Collection of utility servlets and filters for Jakarta EE 10 web applications including CORS, DoS protection, QoS management, header manipulation, and server-sent events.
npx @tessl/cli install tessl/maven-org-eclipse-jetty-ee10--jetty-ee10-servlets@12.0.0Jetty EE10 Servlets is a comprehensive collection of utility servlets and filters for Jakarta EE 10 web applications built on the Eclipse Jetty web server. It provides essential security and performance components including DoS protection, CORS support, quality-of-service management, HTTP header manipulation, and server-sent events functionality.
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlets</artifactId>
<version>12.0.21</version>
</dependency>import org.eclipse.jetty.ee10.servlets.*;For specific classes:
import org.eclipse.jetty.ee10.servlets.DoSFilter;
import org.eclipse.jetty.ee10.servlets.CrossOriginFilter;
import org.eclipse.jetty.ee10.servlets.EventSource;
import org.eclipse.jetty.ee10.servlets.EventSourceServlet;
import org.eclipse.jetty.ee10.servlets.HeaderFilter;
import org.eclipse.jetty.ee10.servlets.QoSFilter;
import org.eclipse.jetty.ee10.servlets.IncludeExcludeBasedFilter;
import org.eclipse.jetty.ee10.servlets.CloseableDoSFilter;import org.eclipse.jetty.ee10.servlets.DoSFilter;
import jakarta.servlet.Filter;
// Configure DoS filter in web.xml
/*
<filter>
<filter-name>DoSFilter</filter-name>
<filter-class>org.eclipse.jetty.ee10.servlets.DoSFilter</filter-class>
<init-param>
<param-name>maxRequestsPerSec</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>delayMs</param-name>
<param-value>1000</param-value>
</init-param>
</filter>
*/
// Or programmatically
DoSFilter dosFilter = new DoSFilter();
dosFilter.setMaxRequestsPerSec(10);
dosFilter.setDelayMs(1000);import org.eclipse.jetty.ee10.servlets.EventSource;
import org.eclipse.jetty.ee10.servlets.EventSourceServlet;
public class MyEventSourceServlet extends EventSourceServlet {
@Override
protected EventSource newEventSource(HttpServletRequest request) {
return new EventSource() {
@Override
public void onOpen(Emitter emitter) throws IOException {
// Send welcome message
emitter.data("Welcome to the event stream!");
}
@Override
public void onClose() {
// Cleanup when connection closes
}
};
}
}The Jetty EE10 Servlets package is organized into several key functional areas:
Comprehensive DoS protection with rate limiting, request throttling, and IP whitelisting. Supports JMX management and extensive configuration options.
public class DoSFilter implements Filter {
public void setMaxRequestsPerSec(int value);
public void setDelayMs(long value);
public void setThrottledRequests(int value);
public void setWhitelist(String commaSeparatedList);
}DoS Protection and Rate Limiting
Implementation of the W3C EventSource specification for server-sent events, enabling real-time server-to-client communication.
public interface EventSource {
void onOpen(Emitter emitter) throws IOException;
void onClose();
interface Emitter {
void event(String name, String data) throws IOException;
void data(String data) throws IOException;
void comment(String comment) throws IOException;
void close();
}
}
public abstract class EventSourceServlet extends HttpServlet {
protected abstract EventSource newEventSource(HttpServletRequest request);
}Note: This filter is deprecated. Use org.eclipse.jetty.server.handler.CrossOriginHandler instead.
CORS filter implementation for managing cross-origin requests with extensive configuration options.
public class CrossOriginFilter implements Filter {
// Configuration constants
public static final String ALLOWED_ORIGINS_PARAM = "allowedOrigins";
public static final String ALLOWED_METHODS_PARAM = "allowedMethods";
public static final String ALLOWED_HEADERS_PARAM = "allowedHeaders";
}Filter for setting, adding, or modifying HTTP headers on responses with flexible configuration syntax.
public class HeaderFilter extends IncludeExcludeBasedFilter {
// Configured via headerConfig parameter
// Syntax: [action] [header name]: [header value]
// Actions: set, add, setDate, addDate
}Note: This filter is deprecated. Use org.eclipse.jetty.server.handler.QoSHandler instead.
Request concurrency management with priority-based queuing and suspension.
public class QoSFilter implements Filter {
public long getWaitMs();
public long getSuspendMs();
public int getMaxRequests();
}Abstract base class for filters that need path, MIME type, or HTTP method-based filtering capabilities.
public abstract class IncludeExcludeBasedFilter implements Filter {
protected boolean shouldFilter(HttpServletRequest request, HttpServletResponse response);
protected String guessMimeType(HttpServletRequest request, HttpServletResponse response);
}// DoSFilter Action enum
public enum Action {
NO_ACTION, ABORT, REJECT, DELAY, THROTTLE;
public static Action fromDelay(long delayMs);
}
// DoSFilter interfaces
public interface OverLimit {
String getRateId();
Duration getDuration();
long getCount();
}
public static class Listener {
public Action onRequestOverLimit(HttpServletRequest request, OverLimit overlimit, DoSFilter dosFilter);
}