Skip to content

Commit 7987cd1

Browse files
committed
Merge branch '3.x' into 4.x
2 parents 1761a34 + 03defaf commit 7987cd1

File tree

16 files changed

+206
-120
lines changed

16 files changed

+206
-120
lines changed

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,34 @@ public static void runApp(@NonNull String[] args, @NonNull Consumer<Jooby> consu
11301130
runApp(args, ExecutionMode.DEFAULT, consumerProvider(consumer));
11311131
}
11321132

1133+
/**
1134+
* Setup default environment, logging (logback or log4j2) and run application.
1135+
*
1136+
* @param args Application arguments.
1137+
* @param server Server to run.
1138+
* @param consumer Application consumer.
1139+
*/
1140+
public static void runApp(
1141+
@NonNull String[] args, @NonNull Server server, @NonNull Consumer<Jooby> consumer) {
1142+
runApp(args, server, ExecutionMode.DEFAULT, consumer);
1143+
}
1144+
1145+
/**
1146+
* Setup default environment, logging (logback or log4j2) and run application.
1147+
*
1148+
* @param args Application arguments.
1149+
* @param server Server to run.
1150+
* @param consumer Application consumer.
1151+
*/
1152+
public static void runApp(
1153+
@NonNull String[] args,
1154+
@NonNull Server server,
1155+
@NonNull ExecutionMode executionMode,
1156+
@NonNull Consumer<Jooby> consumer) {
1157+
configurePackage(consumer.getClass().getPackage());
1158+
runApp(args, server, executionMode, List.of(consumerProvider(consumer)));
1159+
}
1160+
11331161
/**
11341162
* Setup default environment, logging (logback or log4j2) and run application.
11351163
*
@@ -1208,37 +1236,38 @@ public static void runApp(
12081236
@NonNull Server server,
12091237
@NonNull ExecutionMode executionMode,
12101238
@NonNull List<Supplier<Jooby>> provider) {
1239+
12111240
/* Dump command line as system properties. */
12121241
parseArguments(args).forEach(System::setProperty);
12131242
var apps = new ArrayList<Jooby>();
12141243
var targetServer = server.getLoggerOff().isEmpty() ? server : MutedServer.mute(server);
1215-
for (var factory : provider) {
1216-
var app = createApp(server, executionMode, factory);
1217-
/*
1218-
When running a single app instance, there is no issue with server options, when multiple
1219-
apps set options a warning will be printed
1220-
*/
1221-
ServerOptions.from(app.getConfig())
1222-
.ifPresent(
1223-
options -> {
1224-
options.setServer(server.getName());
1225-
server.setOptions(options);
1226-
});
1227-
apps.add(app);
1228-
}
12291244
try {
1245+
for (var factory : provider) {
1246+
var app = createApp(server, executionMode, factory);
1247+
/*
1248+
When running a single app instance, there is no issue with server options, when multiple
1249+
apps set options a warning will be printed
1250+
*/
1251+
ServerOptions.from(app.getConfig())
1252+
.ifPresent(
1253+
options -> {
1254+
options.setServer(server.getName());
1255+
server.setOptions(options);
1256+
});
1257+
apps.add(app);
1258+
}
1259+
12301260
targetServer.start(apps.toArray(new Jooby[0]));
12311261
} catch (Throwable startupError) {
1232-
apps.forEach(app -> app.stopped.set(true));
12331262
try {
1234-
server.stop();
1263+
targetServer.stop();
12351264
} catch (Throwable ignored) {
12361265
// no need to log here
12371266
}
12381267
// rethrow
12391268
throw startupError instanceof StartupException
12401269
? (StartupException) startupError
1241-
: new StartupException("Startup resulted in exception", startupError);
1270+
: new StartupException("Application initialization resulted in exception", startupError);
12421271
}
12431272
}
12441273

@@ -1268,13 +1297,6 @@ public static Jooby createApp(
12681297
Jooby.BOOT_SERVER = server;
12691298
Jooby.BOOT_EXECUTION_MODE = executionMode;
12701299
app = provider.get();
1271-
} catch (Throwable t) {
1272-
LoggerFactory.getLogger(Jooby.class)
1273-
.error("Application initialization resulted in exception", t);
1274-
1275-
throw t instanceof StartupException
1276-
? (StartupException) t
1277-
: new StartupException("Application initialization resulted in exception", t);
12781300
} finally {
12791301
Jooby.BOOT_EXECUTION_MODE = executionMode;
12801302
Jooby.BOOT_SERVER = null;

jooby/src/main/java/io/jooby/ServerOptions.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public class ServerOptions {
106106
*/
107107
private int maxRequestSize = _10MB;
108108

109+
/** The maximum size in bytes of a http request header. Default is <code>8kb</code> */
110+
private int maxHeaderSize = _8KB;
111+
109112
private String host = LOCAL_HOST;
110113

111114
private SslOptions ssl;
@@ -255,12 +258,12 @@ public int getPort() {
255258
}
256259

257260
/**
258-
* True when SSL is enabled. Either bc the secure port or SSL options are set.
261+
* True when SSL is enabled. Either bc the secure port, httpsOnly or SSL options are set.
259262
*
260-
* @return True when SSL is enabled. Either bc the secure port or SSL options are set.
263+
* @return True when SSL is enabled. Either bc the secure port, httpsOnly or SSL options are set.
261264
*/
262265
public boolean isSSLEnabled() {
263-
return securePort != null || ssl != null;
266+
return securePort != null || ssl != null || httpsOnly;
264267
}
265268

266269
/**
@@ -438,6 +441,34 @@ public int getMaxRequestSize() {
438441
return this;
439442
}
440443

444+
/**
445+
* The maximum size in bytes of an http request header. Exceeding the size generates a different
446+
* response across server implementations.
447+
*
448+
* <ul>
449+
* <li>Jetty: generates a 431 error message
450+
* <li>Netty: the header is dropped/ignored, but don't fail
451+
* <li>Undertow: generates an empty 400 response, and the connection is closed.
452+
* </ul>
453+
*
454+
* @return The maximum size in bytes of an http request header.
455+
*/
456+
public int getMaxHeaderSize() {
457+
return maxHeaderSize;
458+
}
459+
460+
/**
461+
* Set the maximum size in bytes of an http request header.
462+
*
463+
* @param maxHeaderSize The maximum size in bytes of an http request header. Default is <code>8kb
464+
* </code>.
465+
* @return The maximum size in bytes of an http request header. Default is <code>8kb</code>.
466+
*/
467+
public @NonNull ServerOptions setMaxHeaderSize(int maxHeaderSize) {
468+
this.maxHeaderSize = maxHeaderSize;
469+
return this;
470+
}
471+
441472
/**
442473
* Server host, defaults is <code>0.0.0.0</code>.
443474
*

modules/jooby-awssdk-v2/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<name>jooby-awssdk-v2</name>
1313

1414
<properties>
15-
<aws.java.sdk.version>2.31.77</aws.java.sdk.version>
15+
<aws.java.sdk.version>2.31.78</aws.java.sdk.version>
1616
</properties>
1717

1818
<dependencyManagement>

modules/jooby-caffeine/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>com.github.ben-manes.caffeine</groupId>
2424
<artifactId>caffeine</artifactId>
25-
<version>3.2.1</version>
25+
<version>3.2.2</version>
2626
</dependency>
2727

2828
<!-- Test dependencies -->

modules/jooby-jetty/src/main/java/io/jooby/jetty/JettyServer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import edu.umd.cs.findbugs.annotations.NonNull;
3333
import io.jooby.*;
3434
import io.jooby.buffer.BufferedOutputFactory;
35+
import io.jooby.exception.StartupException;
3536
import io.jooby.internal.jetty.JettyHandler;
3637
import io.jooby.internal.jetty.JettyHttpExpectAndContinueHandler;
3738
import io.jooby.internal.jetty.PrefixHandler;
@@ -110,6 +111,7 @@ public JettyServer configure(Consumer<HttpConfiguration> configurer) {
110111
public io.jooby.Server start(@NonNull Jooby... application) {
111112
// force options to be non-null
112113
var options = getOptions();
114+
var portInUse = options.getPort();
113115
try {
114116
this.applications = List.of(application);
115117
/* Set max request size attribute: */
@@ -145,6 +147,7 @@ public io.jooby.Server start(@NonNull Jooby... application) {
145147
httpConf.setSendXPoweredBy(false);
146148
httpConf.setSendDateHeader(options.getDefaultHeaders());
147149
httpConf.setSendServerVersion(false);
150+
httpConf.setRequestHeaderSize(options.getMaxHeaderSize());
148151

149152
if (httpConfigurer != null) {
150153
httpConfigurer.accept(httpConf);
@@ -207,13 +210,13 @@ public io.jooby.Server start(@NonNull Jooby... application) {
207210
acceptors,
208211
selectors,
209212
secureConnectionFactories.toArray(new ConnectionFactory[0]));
210-
secureConnector.setPort(options.getSecurePort());
213+
portInUse = options.getSecurePort();
214+
secureConnector.setPort(portInUse);
211215
secureConnector.setHost(options.getHost());
212216

213217
server.addConnector(secureConnector);
214218
} else if (options.isHttpsOnly()) {
215-
throw new IllegalArgumentException(
216-
"Server configured for httpsOnly, but ssl options not set");
219+
throw new StartupException("Server configured for httpsOnly, but ssl options not set");
217220
}
218221

219222
var context = new ContextHandler();
@@ -270,7 +273,7 @@ public io.jooby.Server start(@NonNull Jooby... application) {
270273
fireReady(applications);
271274
} catch (Exception x) {
272275
if (io.jooby.Server.isAddressInUse(x.getCause())) {
273-
x = new BindException("Address already in use: " + options.getPort());
276+
x = new BindException("Address already in use: " + portInUse);
274277
}
275278
throw SneakyThrows.propagate(x);
276279
}

modules/jooby-mutiny/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>io.smallrye.reactive</groupId>
2828
<artifactId>mutiny</artifactId>
29-
<version>2.9.2</version>
29+
<version>2.9.3</version>
3030
</dependency>
3131

3232
<!-- Test dependencies -->

modules/jooby-netty/src/main/java/io/jooby/netty/NettyServer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.jooby.netty;
77

88
import static io.jooby.ServerOptions._4KB;
9-
import static io.jooby.ServerOptions._8KB;
109
import static java.util.concurrent.Executors.newFixedThreadPool;
1110

1211
import java.net.BindException;
@@ -23,6 +22,7 @@
2322
import io.jooby.SneakyThrows;
2423
import io.jooby.SslOptions;
2524
import io.jooby.buffer.BufferedOutputFactory;
25+
import io.jooby.exception.StartupException;
2626
import io.jooby.internal.netty.*;
2727
import io.netty.bootstrap.ServerBootstrap;
2828
import io.netty.buffer.ByteBufAllocator;
@@ -105,6 +105,7 @@ public String getName() {
105105
public Server start(@NonNull Jooby... application) {
106106
// force options to be non-null
107107
var options = getOptions();
108+
var portInUse = options.getPort();
108109
try {
109110
this.applications = List.of(application);
110111
/* Worker: Application blocking code */
@@ -154,10 +155,10 @@ public Server start(@NonNull Jooby... application) {
154155
var https =
155156
newBootstrap(
156157
allocator, transport, newPipeline(options, sslContext, dateService, http2));
157-
https.bind(options.getHost(), options.getSecurePort()).get();
158+
portInUse = options.getSecurePort();
159+
https.bind(options.getHost(), portInUse).get();
158160
} else if (options.isHttpsOnly()) {
159-
throw new IllegalArgumentException(
160-
"Server configured for httpsOnly, but ssl options not set");
161+
throw new StartupException("Server configured for httpsOnly, but ssl options not set");
161162
}
162163

163164
fireReady(applications);
@@ -166,7 +167,7 @@ public Server start(@NonNull Jooby... application) {
166167
} catch (ExecutionException x) {
167168
var cause = x.getCause();
168169
if (Server.isAddressInUse(cause)) {
169-
cause = new BindException("Address already in use: " + options.getPort());
170+
cause = new BindException("Address already in use: " + portInUse);
170171
}
171172
throw SneakyThrows.propagate(cause);
172173
}
@@ -196,7 +197,7 @@ private NettyPipeline newPipeline(
196197
var decoderConfig =
197198
new HttpDecoderConfig()
198199
.setMaxInitialLineLength(_4KB)
199-
.setMaxHeaderSize(_8KB)
200+
.setMaxHeaderSize(options.getMaxHeaderSize())
200201
.setMaxChunkSize(options.getBuffer().getSize())
201202
.setHeadersFactory(NettyContext.HEADERS)
202203
.setTrailersFactory(NettyContext.HEADERS);

modules/jooby-openapi/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<dependency>
8686
<groupId>org.apache.commons</groupId>
8787
<artifactId>commons-lang3</artifactId>
88-
<version>3.17.0</version>
88+
<version>3.18.0</version>
8989
<scope>test</scope>
9090
</dependency>
9191

modules/jooby-rxjava3/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>io.reactivex.rxjava3</groupId>
2828
<artifactId>rxjava</artifactId>
29-
<version>3.1.10</version>
29+
<version>3.1.11</version>
3030
</dependency>
3131

3232
<!-- Test dependencies -->

modules/jooby-swagger-ui/package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)