0
# Jetty EE10 Servlets
1
2
Jetty 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.
3
4
## Package Information
5
6
- **Package Name**: jetty-ee10-servlets
7
- **Group ID**: org.eclipse.jetty.ee10
8
- **Package Type**: Maven
9
- **Language**: Java
10
- **Installation**:
11
12
```xml
13
<dependency>
14
<groupId>org.eclipse.jetty.ee10</groupId>
15
<artifactId>jetty-ee10-servlets</artifactId>
16
<version>12.0.21</version>
17
</dependency>
18
```
19
20
## Core Imports
21
22
```java
23
import org.eclipse.jetty.ee10.servlets.*;
24
```
25
26
For specific classes:
27
28
```java
29
import org.eclipse.jetty.ee10.servlets.DoSFilter;
30
import org.eclipse.jetty.ee10.servlets.CrossOriginFilter;
31
import org.eclipse.jetty.ee10.servlets.EventSource;
32
import org.eclipse.jetty.ee10.servlets.EventSourceServlet;
33
import org.eclipse.jetty.ee10.servlets.HeaderFilter;
34
import org.eclipse.jetty.ee10.servlets.QoSFilter;
35
import org.eclipse.jetty.ee10.servlets.IncludeExcludeBasedFilter;
36
import org.eclipse.jetty.ee10.servlets.CloseableDoSFilter;
37
```
38
39
## Basic Usage
40
41
### DoS Protection Filter
42
43
```java
44
import org.eclipse.jetty.ee10.servlets.DoSFilter;
45
import jakarta.servlet.Filter;
46
47
// Configure DoS filter in web.xml
48
/*
49
<filter>
50
<filter-name>DoSFilter</filter-name>
51
<filter-class>org.eclipse.jetty.ee10.servlets.DoSFilter</filter-class>
52
<init-param>
53
<param-name>maxRequestsPerSec</param-name>
54
<param-value>10</param-value>
55
</init-param>
56
<init-param>
57
<param-name>delayMs</param-name>
58
<param-value>1000</param-value>
59
</init-param>
60
</filter>
61
*/
62
63
// Or programmatically
64
DoSFilter dosFilter = new DoSFilter();
65
dosFilter.setMaxRequestsPerSec(10);
66
dosFilter.setDelayMs(1000);
67
```
68
69
### Server-Sent Events
70
71
```java
72
import org.eclipse.jetty.ee10.servlets.EventSource;
73
import org.eclipse.jetty.ee10.servlets.EventSourceServlet;
74
75
public class MyEventSourceServlet extends EventSourceServlet {
76
@Override
77
protected EventSource newEventSource(HttpServletRequest request) {
78
return new EventSource() {
79
@Override
80
public void onOpen(Emitter emitter) throws IOException {
81
// Send welcome message
82
emitter.data("Welcome to the event stream!");
83
}
84
85
@Override
86
public void onClose() {
87
// Cleanup when connection closes
88
}
89
};
90
}
91
}
92
```
93
94
## Architecture
95
96
The Jetty EE10 Servlets package is organized into several key functional areas:
97
98
- **Security & Filtering**: DoS protection filters that provide rate limiting and request throttling
99
- **Cross-Origin Resource Sharing**: CORS filter for managing cross-origin requests (deprecated)
100
- **Server-Sent Events**: EventSource interface and servlet for real-time server-to-client communication
101
- **Quality of Service**: Request concurrency management and prioritization (deprecated)
102
- **Header Management**: HTTP header manipulation and modification utilities
103
- **Base Filtering**: Abstract classes providing common include/exclude filtering patterns
104
105
## Capabilities
106
107
### Denial of Service Protection
108
109
Comprehensive DoS protection with rate limiting, request throttling, and IP whitelisting. Supports JMX management and extensive configuration options.
110
111
```java { .api }
112
public class DoSFilter implements Filter {
113
public void setMaxRequestsPerSec(int value);
114
public void setDelayMs(long value);
115
public void setThrottledRequests(int value);
116
public void setWhitelist(String commaSeparatedList);
117
}
118
```
119
120
[DoS Protection and Rate Limiting](./dos-protection.md)
121
122
### Server-Sent Events (EventSource)
123
124
Implementation of the W3C EventSource specification for server-sent events, enabling real-time server-to-client communication.
125
126
```java { .api }
127
public interface EventSource {
128
void onOpen(Emitter emitter) throws IOException;
129
void onClose();
130
131
interface Emitter {
132
void event(String name, String data) throws IOException;
133
void data(String data) throws IOException;
134
void comment(String comment) throws IOException;
135
void close();
136
}
137
}
138
139
public abstract class EventSourceServlet extends HttpServlet {
140
protected abstract EventSource newEventSource(HttpServletRequest request);
141
}
142
```
143
144
[Server-Sent Events](./server-sent-events.md)
145
146
### Cross-Origin Resource Sharing (CORS)
147
148
**Note: This filter is deprecated. Use `org.eclipse.jetty.server.handler.CrossOriginHandler` instead.**
149
150
CORS filter implementation for managing cross-origin requests with extensive configuration options.
151
152
```java { .api }
153
public class CrossOriginFilter implements Filter {
154
// Configuration constants
155
public static final String ALLOWED_ORIGINS_PARAM = "allowedOrigins";
156
public static final String ALLOWED_METHODS_PARAM = "allowedMethods";
157
public static final String ALLOWED_HEADERS_PARAM = "allowedHeaders";
158
}
159
```
160
161
[CORS Filter](./cors-filter.md)
162
163
### HTTP Header Management
164
165
Filter for setting, adding, or modifying HTTP headers on responses with flexible configuration syntax.
166
167
```java { .api }
168
public class HeaderFilter extends IncludeExcludeBasedFilter {
169
// Configured via headerConfig parameter
170
// Syntax: [action] [header name]: [header value]
171
// Actions: set, add, setDate, addDate
172
}
173
```
174
175
[Header Management](./header-management.md)
176
177
### Quality of Service Management
178
179
**Note: This filter is deprecated. Use `org.eclipse.jetty.server.handler.QoSHandler` instead.**
180
181
Request concurrency management with priority-based queuing and suspension.
182
183
```java { .api }
184
public class QoSFilter implements Filter {
185
public long getWaitMs();
186
public long getSuspendMs();
187
public int getMaxRequests();
188
}
189
```
190
191
[Quality of Service](./quality-of-service.md)
192
193
### Include/Exclude Base Filtering
194
195
Abstract base class for filters that need path, MIME type, or HTTP method-based filtering capabilities.
196
197
```java { .api }
198
public abstract class IncludeExcludeBasedFilter implements Filter {
199
protected boolean shouldFilter(HttpServletRequest request, HttpServletResponse response);
200
protected String guessMimeType(HttpServletRequest request, HttpServletResponse response);
201
}
202
```
203
204
[Base Filtering Patterns](./base-filtering.md)
205
206
## Types
207
208
### Common Enums and Constants
209
210
```java { .api }
211
// DoSFilter Action enum
212
public enum Action {
213
NO_ACTION, ABORT, REJECT, DELAY, THROTTLE;
214
public static Action fromDelay(long delayMs);
215
}
216
217
// DoSFilter interfaces
218
public interface OverLimit {
219
String getRateId();
220
Duration getDuration();
221
long getCount();
222
}
223
224
public static class Listener {
225
public Action onRequestOverLimit(HttpServletRequest request, OverLimit overlimit, DoSFilter dosFilter);
226
}
227
```