|
| 1 | +/* |
| 2 | + * Copyright 2012-2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.autoconfigure.web.server.jetty; |
| 18 | + |
| 19 | +import java.time.Duration; |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
| 23 | +import org.springframework.util.unit.DataSize; |
| 24 | + |
| 25 | +/** |
| 26 | + * Jetty server properties. |
| 27 | + * |
| 28 | + * @author Dave Syer |
| 29 | + * @author Stephane Nicoll |
| 30 | + * @author Andy Wilkinson |
| 31 | + * @author Ivan Sopov |
| 32 | + * @author Marcos Barbero |
| 33 | + * @author Eddú Meléndez |
| 34 | + * @author Quinten De Swaef |
| 35 | + * @author Venil Noronha |
| 36 | + * @author Aurélien Leboulanger |
| 37 | + * @author Brian Clozel |
| 38 | + * @author Olivier Lamy |
| 39 | + * @author Chentao Qu |
| 40 | + * @author Artsiom Yudovin |
| 41 | + * @author Andrew McGhie |
| 42 | + * @author Rafiullah Hamedy |
| 43 | + * @author Dirk Deyne |
| 44 | + * @author HaiTao Zhang |
| 45 | + * @author Victor Mandujano |
| 46 | + * @author Chris Bono |
| 47 | + * @author Parviz Rozikov |
| 48 | + * @author Florian Storz |
| 49 | + * @author Michael Weidmann |
| 50 | + * @author Lasse Wulff |
| 51 | + * @since 3.5.0 |
| 52 | + */ |
| 53 | +@ConfigurationProperties("server.jetty") |
| 54 | +public class JettyServerProperties { |
| 55 | + |
| 56 | + /** |
| 57 | + * Maximum size of the form content in any HTTP post request. |
| 58 | + */ |
| 59 | + private DataSize maxHttpFormPostSize = DataSize.ofBytes(200000); |
| 60 | + |
| 61 | + /** |
| 62 | + * Maximum number of form keys. |
| 63 | + */ |
| 64 | + private int maxFormKeys = 1000; |
| 65 | + |
| 66 | + /** |
| 67 | + * Time that the connection can be idle before it is closed. |
| 68 | + */ |
| 69 | + private Duration connectionIdleTimeout; |
| 70 | + |
| 71 | + /** |
| 72 | + * Maximum size of the HTTP response header. |
| 73 | + */ |
| 74 | + private DataSize maxHttpResponseHeaderSize = DataSize.ofKilobytes(8); |
| 75 | + |
| 76 | + /** |
| 77 | + * Maximum number of connections that the server accepts and processes at any given |
| 78 | + * time. |
| 79 | + */ |
| 80 | + private int maxConnections = -1; |
| 81 | + |
| 82 | + /** |
| 83 | + * Access log configuration. |
| 84 | + */ |
| 85 | + private final Accesslog accesslog = new Accesslog(); |
| 86 | + |
| 87 | + /** |
| 88 | + * Thread related configuration. |
| 89 | + */ |
| 90 | + private final Threads threads = new Threads(); |
| 91 | + |
| 92 | + public Accesslog getAccesslog() { |
| 93 | + return this.accesslog; |
| 94 | + } |
| 95 | + |
| 96 | + public Threads getThreads() { |
| 97 | + return this.threads; |
| 98 | + } |
| 99 | + |
| 100 | + public DataSize getMaxHttpFormPostSize() { |
| 101 | + return this.maxHttpFormPostSize; |
| 102 | + } |
| 103 | + |
| 104 | + public void setMaxHttpFormPostSize(DataSize maxHttpFormPostSize) { |
| 105 | + this.maxHttpFormPostSize = maxHttpFormPostSize; |
| 106 | + } |
| 107 | + |
| 108 | + public int getMaxFormKeys() { |
| 109 | + return this.maxFormKeys; |
| 110 | + } |
| 111 | + |
| 112 | + public void setMaxFormKeys(int maxFormKeys) { |
| 113 | + this.maxFormKeys = maxFormKeys; |
| 114 | + } |
| 115 | + |
| 116 | + public Duration getConnectionIdleTimeout() { |
| 117 | + return this.connectionIdleTimeout; |
| 118 | + } |
| 119 | + |
| 120 | + public void setConnectionIdleTimeout(Duration connectionIdleTimeout) { |
| 121 | + this.connectionIdleTimeout = connectionIdleTimeout; |
| 122 | + } |
| 123 | + |
| 124 | + public DataSize getMaxHttpResponseHeaderSize() { |
| 125 | + return this.maxHttpResponseHeaderSize; |
| 126 | + } |
| 127 | + |
| 128 | + public void setMaxHttpResponseHeaderSize(DataSize maxHttpResponseHeaderSize) { |
| 129 | + this.maxHttpResponseHeaderSize = maxHttpResponseHeaderSize; |
| 130 | + } |
| 131 | + |
| 132 | + public int getMaxConnections() { |
| 133 | + return this.maxConnections; |
| 134 | + } |
| 135 | + |
| 136 | + public void setMaxConnections(int maxConnections) { |
| 137 | + this.maxConnections = maxConnections; |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Jetty access log properties. |
| 142 | + */ |
| 143 | + public static class Accesslog { |
| 144 | + |
| 145 | + /** |
| 146 | + * Enable access log. |
| 147 | + */ |
| 148 | + private boolean enabled = false; |
| 149 | + |
| 150 | + /** |
| 151 | + * Log format. |
| 152 | + */ |
| 153 | + private Accesslog.FORMAT format = FORMAT.NCSA; |
| 154 | + |
| 155 | + /** |
| 156 | + * Custom log format, see org.eclipse.jetty.server.CustomRequestLog. If defined, |
| 157 | + * overrides the "format" configuration key. |
| 158 | + */ |
| 159 | + private String customFormat; |
| 160 | + |
| 161 | + /** |
| 162 | + * Log filename. If not specified, logs redirect to "System.err". |
| 163 | + */ |
| 164 | + private String filename; |
| 165 | + |
| 166 | + /** |
| 167 | + * Date format to place in log file name. |
| 168 | + */ |
| 169 | + private String fileDateFormat; |
| 170 | + |
| 171 | + /** |
| 172 | + * Number of days before rotated log files are deleted. |
| 173 | + */ |
| 174 | + private int retentionPeriod = 31; // no days |
| 175 | + |
| 176 | + /** |
| 177 | + * Append to log. |
| 178 | + */ |
| 179 | + private boolean append; |
| 180 | + |
| 181 | + /** |
| 182 | + * Request paths that should not be logged. |
| 183 | + */ |
| 184 | + private List<String> ignorePaths; |
| 185 | + |
| 186 | + public boolean isEnabled() { |
| 187 | + return this.enabled; |
| 188 | + } |
| 189 | + |
| 190 | + public void setEnabled(boolean enabled) { |
| 191 | + this.enabled = enabled; |
| 192 | + } |
| 193 | + |
| 194 | + public Accesslog.FORMAT getFormat() { |
| 195 | + return this.format; |
| 196 | + } |
| 197 | + |
| 198 | + public void setFormat(Accesslog.FORMAT format) { |
| 199 | + this.format = format; |
| 200 | + } |
| 201 | + |
| 202 | + public String getCustomFormat() { |
| 203 | + return this.customFormat; |
| 204 | + } |
| 205 | + |
| 206 | + public void setCustomFormat(String customFormat) { |
| 207 | + this.customFormat = customFormat; |
| 208 | + } |
| 209 | + |
| 210 | + public String getFilename() { |
| 211 | + return this.filename; |
| 212 | + } |
| 213 | + |
| 214 | + public void setFilename(String filename) { |
| 215 | + this.filename = filename; |
| 216 | + } |
| 217 | + |
| 218 | + public String getFileDateFormat() { |
| 219 | + return this.fileDateFormat; |
| 220 | + } |
| 221 | + |
| 222 | + public void setFileDateFormat(String fileDateFormat) { |
| 223 | + this.fileDateFormat = fileDateFormat; |
| 224 | + } |
| 225 | + |
| 226 | + public int getRetentionPeriod() { |
| 227 | + return this.retentionPeriod; |
| 228 | + } |
| 229 | + |
| 230 | + public void setRetentionPeriod(int retentionPeriod) { |
| 231 | + this.retentionPeriod = retentionPeriod; |
| 232 | + } |
| 233 | + |
| 234 | + public boolean isAppend() { |
| 235 | + return this.append; |
| 236 | + } |
| 237 | + |
| 238 | + public void setAppend(boolean append) { |
| 239 | + this.append = append; |
| 240 | + } |
| 241 | + |
| 242 | + public List<String> getIgnorePaths() { |
| 243 | + return this.ignorePaths; |
| 244 | + } |
| 245 | + |
| 246 | + public void setIgnorePaths(List<String> ignorePaths) { |
| 247 | + this.ignorePaths = ignorePaths; |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * Log format for Jetty access logs. |
| 252 | + */ |
| 253 | + public enum FORMAT { |
| 254 | + |
| 255 | + /** |
| 256 | + * NCSA format, as defined in CustomRequestLog#NCSA_FORMAT. |
| 257 | + */ |
| 258 | + NCSA, |
| 259 | + |
| 260 | + /** |
| 261 | + * Extended NCSA format, as defined in CustomRequestLog#EXTENDED_NCSA_FORMAT. |
| 262 | + */ |
| 263 | + EXTENDED_NCSA |
| 264 | + |
| 265 | + } |
| 266 | + |
| 267 | + } |
| 268 | + |
| 269 | + /** |
| 270 | + * Jetty thread properties. |
| 271 | + */ |
| 272 | + public static class Threads { |
| 273 | + |
| 274 | + /** |
| 275 | + * Number of acceptor threads to use. When the value is -1, the default, the |
| 276 | + * number of acceptors is derived from the operating environment. |
| 277 | + */ |
| 278 | + private Integer acceptors = -1; |
| 279 | + |
| 280 | + /** |
| 281 | + * Number of selector threads to use. When the value is -1, the default, the |
| 282 | + * number of selectors is derived from the operating environment. |
| 283 | + */ |
| 284 | + private Integer selectors = -1; |
| 285 | + |
| 286 | + /** |
| 287 | + * Maximum number of threads. Doesn't have an effect if virtual threads are |
| 288 | + * enabled. |
| 289 | + */ |
| 290 | + private Integer max = 200; |
| 291 | + |
| 292 | + /** |
| 293 | + * Minimum number of threads. Doesn't have an effect if virtual threads are |
| 294 | + * enabled. |
| 295 | + */ |
| 296 | + private Integer min = 8; |
| 297 | + |
| 298 | + /** |
| 299 | + * Maximum capacity of the thread pool's backing queue. A default is computed |
| 300 | + * based on the threading configuration. |
| 301 | + */ |
| 302 | + private Integer maxQueueCapacity; |
| 303 | + |
| 304 | + /** |
| 305 | + * Maximum thread idle time. |
| 306 | + */ |
| 307 | + private Duration idleTimeout = Duration.ofMillis(60000); |
| 308 | + |
| 309 | + public Integer getAcceptors() { |
| 310 | + return this.acceptors; |
| 311 | + } |
| 312 | + |
| 313 | + public void setAcceptors(Integer acceptors) { |
| 314 | + this.acceptors = acceptors; |
| 315 | + } |
| 316 | + |
| 317 | + public Integer getSelectors() { |
| 318 | + return this.selectors; |
| 319 | + } |
| 320 | + |
| 321 | + public void setSelectors(Integer selectors) { |
| 322 | + this.selectors = selectors; |
| 323 | + } |
| 324 | + |
| 325 | + public void setMin(Integer min) { |
| 326 | + this.min = min; |
| 327 | + } |
| 328 | + |
| 329 | + public Integer getMin() { |
| 330 | + return this.min; |
| 331 | + } |
| 332 | + |
| 333 | + public void setMax(Integer max) { |
| 334 | + this.max = max; |
| 335 | + } |
| 336 | + |
| 337 | + public Integer getMax() { |
| 338 | + return this.max; |
| 339 | + } |
| 340 | + |
| 341 | + public Integer getMaxQueueCapacity() { |
| 342 | + return this.maxQueueCapacity; |
| 343 | + } |
| 344 | + |
| 345 | + public void setMaxQueueCapacity(Integer maxQueueCapacity) { |
| 346 | + this.maxQueueCapacity = maxQueueCapacity; |
| 347 | + } |
| 348 | + |
| 349 | + public void setIdleTimeout(Duration idleTimeout) { |
| 350 | + this.idleTimeout = idleTimeout; |
| 351 | + } |
| 352 | + |
| 353 | + public Duration getIdleTimeout() { |
| 354 | + return this.idleTimeout; |
| 355 | + } |
| 356 | + |
| 357 | + } |
| 358 | + |
| 359 | +} |
0 commit comments