or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

http-client.mdindex.mdreactive-web-server.mdserver-configuration.mdservlet-web-server.mdwebsocket-support.md

server-configuration.mddocs/

0

# Server Configuration

1

2

Comprehensive server configuration and customization options including SSL, threading, connectors, and advanced Jetty features. Provides extensive customization capabilities for both servlet and reactive applications.

3

4

## Capabilities

5

6

### JettyServerCustomizer

7

8

Primary interface for customizing Jetty server configuration with direct access to the underlying Jetty Server instance.

9

10

```java { .api }

11

/**

12

* Interface for customizing Jetty Server instances

13

*/

14

@FunctionalInterface

15

public interface JettyServerCustomizer {

16

17

/** Customize the Jetty Server instance */

18

void customize(Server server);

19

}

20

```

21

22

**Usage Examples:**

23

24

```java

25

@Configuration

26

public class JettyCustomizerConfig {

27

28

@Bean

29

public JettyServletWebServerFactory jettyFactory() {

30

JettyServletWebServerFactory factory = new JettyServletWebServerFactory();

31

32

// Add multiple customizers

33

factory.addServerCustomizers(

34

// Custom connector configuration

35

server -> {

36

ServerConnector connector = new ServerConnector(server);

37

connector.setPort(8080);

38

connector.setIdleTimeout(30000);

39

connector.setAcceptQueueSize(128);

40

server.addConnector(connector);

41

},

42

43

// Thread pool configuration

44

server -> {

45

QueuedThreadPool threadPool = new QueuedThreadPool();

46

threadPool.setMaxThreads(200);

47

threadPool.setMinThreads(10);

48

threadPool.setIdleTimeout(60000);

49

server.setThreadPool(threadPool);

50

}

51

);

52

53

return factory;

54

}

55

}

56

```

57

58

### ConfigurableJettyWebServerFactory

59

60

Common interface for both servlet and reactive Jetty web server factories providing configuration methods.

61

62

```java { .api }

63

/**

64

* Common configuration interface for Jetty web server factories

65

*/

66

public interface ConfigurableJettyWebServerFactory extends ConfigurableWebServerFactory {

67

68

/** Add server customizers for configuration */

69

void addServerCustomizers(JettyServerCustomizer... customizers);

70

71

/** Set number of acceptor threads */

72

void setAcceptors(int acceptors);

73

74

/** Set number of selector threads */

75

void setSelectors(int selectors);

76

77

/** Configure forward headers handling */

78

void setUseForwardHeaders(boolean useForwardHeaders);

79

80

/** Set custom thread pool */

81

void setThreadPool(ThreadPool threadPool);

82

83

/** Set maximum number of connections */

84

void setMaxConnections(int maxConnections);

85

}

86

```

87

88

### Thread Pool Configuration

89

90

Custom thread pool implementations and configuration for Jetty servers.

91

92

```java { .api }

93

/**

94

* Jetty thread pool configuration

95

*/

96

public class JettyThreadPool implements ThreadPool {

97

98

/** Create thread pool with default configuration */

99

public JettyThreadPool();

100

101

/** Create thread pool with specified parameters */

102

public JettyThreadPool(int maxThreads, int minThreads, int idleTimeout);

103

104

/** Create thread pool from server properties */

105

public static JettyThreadPool create(ServerProperties.Jetty jettyProperties);

106

107

/** Get maximum number of threads */

108

public int getMaxThreads();

109

110

/** Set maximum number of threads */

111

public void setMaxThreads(int maxThreads);

112

113

/** Get minimum number of threads */

114

public int getMinThreads();

115

116

/** Set minimum number of threads */

117

public void setMinThreads(int minThreads);

118

119

/** Get idle timeout in milliseconds */

120

public int getIdleTimeout();

121

122

/** Set idle timeout in milliseconds */

123

public void setIdleTimeout(int idleTimeout);

124

125

/** Execute a task */

126

public void execute(Runnable job);

127

128

/** Check if thread pool is low on threads */

129

public boolean isLowOnThreads();

130

}

131

```

132

133

### Web Server Factory Customizers

134

135

Auto-configuration customizers that apply default Jetty configuration based on Spring Boot properties.

136

137

```java { .api }

138

/**

139

* Auto-configuration customizer for Jetty web server factories

140

*/

141

public class JettyWebServerFactoryCustomizer

142

implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> {

143

144

/** Create customizer with server properties */

145

public JettyWebServerFactoryCustomizer(ServerProperties serverProperties);

146

147

/** Apply customization to factory */

148

public void customize(ConfigurableJettyWebServerFactory factory);

149

}

150

151

/**

152

* Virtual threads customizer for Jetty (Java 21+)

153

*/

154

public class JettyVirtualThreadsWebServerFactoryCustomizer

155

implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> {

156

157

/** Create virtual threads customizer */

158

public JettyVirtualThreadsWebServerFactoryCustomizer();

159

160

/** Apply virtual threads configuration */

161

public void customize(ConfigurableJettyWebServerFactory factory);

162

}

163

```

164

165

### SSL/TLS Configuration

166

167

SSL/TLS configuration and customization for secure connections.

168

169

```java { .api }

170

/**

171

* SSL/TLS customizer for Jetty servers

172

*/

173

public class SslServerCustomizer implements JettyServerCustomizer {

174

175

/** Create SSL customizer with default configuration */

176

public SslServerCustomizer();

177

178

/** Customize server with SSL configuration */

179

public void customize(Server server);

180

181

/** Configure SSL context factory */

182

public void configureSslContextFactory(SslContextFactory.Server sslContextFactory);

183

184

/** Set SSL protocols */

185

public void setIncludeProtocols(String... protocols);

186

187

/** Set SSL cipher suites */

188

public void setIncludeCipherSuites(String... cipherSuites);

189

190

/** Set client authentication mode */

191

public void setNeedClientAuth(boolean needClientAuth);

192

public void setWantClientAuth(boolean wantClientAuth);

193

}

194

```

195

196

**SSL Configuration Example:**

197

198

```java

199

@Configuration

200

public class JettySslConfig {

201

202

@Bean

203

public JettyServletWebServerFactory jettyFactory() {

204

JettyServletWebServerFactory factory = new JettyServletWebServerFactory();

205

206

factory.addServerCustomizers(server -> {

207

// SSL Context Factory

208

SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();

209

sslContextFactory.setKeyStorePath("/path/to/keystore.jks");

210

sslContextFactory.setKeyStorePassword("password");

211

sslContextFactory.setKeyManagerPassword("password");

212

213

// Security protocols

214

sslContextFactory.setIncludeProtocols("TLSv1.2", "TLSv1.3");

215

sslContextFactory.setExcludeCipherSuites(

216

"SSL_RSA_WITH_DES_CBC_SHA",

217

"SSL_DHE_RSA_WITH_DES_CBC_SHA"

218

);

219

220

// HTTP Configuration

221

HttpConfiguration httpConfig = new HttpConfiguration();

222

httpConfig.setSecureScheme("https");

223

httpConfig.setSecurePort(8443);

224

httpConfig.addCustomizer(new SecureRequestCustomizer());

225

226

// SSL Connection Factory

227

SslConnectionFactory sslConnectionFactory =

228

new SslConnectionFactory(sslContextFactory, "http/1.1");

229

HttpConnectionFactory httpConnectionFactory =

230

new HttpConnectionFactory(httpConfig);

231

232

// SSL Connector

233

ServerConnector sslConnector = new ServerConnector(server,

234

sslConnectionFactory, httpConnectionFactory);

235

sslConnector.setPort(8443);

236

server.addConnector(sslConnector);

237

});

238

239

return factory;

240

}

241

}

242

```

243

244

### Forward Headers Support

245

246

Configuration for handling forward headers from proxies and load balancers.

247

248

```java { .api }

249

/**

250

* Forward headers customizer for proxy support

251

*/

252

public class ForwardHeadersCustomizer implements JettyServerCustomizer {

253

254

/** Create forward headers customizer */

255

public ForwardHeadersCustomizer();

256

257

/** Customize server for forward headers */

258

public void customize(Server server);

259

260

/** Set trusted proxy addresses */

261

public void setTrustedProxies(String... trustedProxies);

262

263

/** Set forward header names */

264

public void setForwardedHostHeader(String forwardedHostHeader);

265

public void setForwardedPortHeader(String forwardedPortHeader);

266

public void setForwardedProtoHeader(String forwardedProtoHeader);

267

}

268

```

269

270

### Properties Configuration

271

272

Spring Boot properties integration for Jetty server configuration through the `server.jetty.*` namespace.

273

274

**Properties Configuration Example:**

275

276

```yaml

277

server:

278

jetty:

279

acceptors: 2

280

selectors: 4

281

max-http-post-size: 10MB

282

threads:

283

max: 200

284

min: 10

285

idle-timeout: 60s

286

connection:

287

idle-timeout: 30s

288

accept-queue-size: 128

289

```