Skip to content

Commit 4def302

Browse files
committed
Jooby v4.0.9 ignores server.port
- setting server options manually overrides everything: `new NettyServer(new ServerOptions())` - otherwise, read from env, args, conf files - fix #3798
1 parent a99f4d4 commit 4def302

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

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

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
import com.typesafe.config.Config;
30-
import com.typesafe.config.ConfigFactory;
3130
import edu.umd.cs.findbugs.annotations.NonNull;
3231
import edu.umd.cs.findbugs.annotations.Nullable;
3332
import io.jooby.exception.RegistryException;
@@ -1200,12 +1199,7 @@ public static void runApp(
12001199
@NonNull String[] args,
12011200
@NonNull ExecutionMode executionMode,
12021201
@NonNull List<Supplier<Jooby>> provider) {
1203-
var configMap = new HashMap<>(parseArguments(args));
1204-
// TODO: Add new way to override server options mainly from system properties/environment
1205-
// variables. Probably by adding a new config file: server.conf
1206-
// configMap.putAll(System.getenv());
1207-
var options = ServerOptions.from(ConfigFactory.parseMap(configMap)).orElse(new ServerOptions());
1208-
runApp(args, Server.loadServer(options), options, executionMode, provider);
1202+
runApp(args, Server.loadServer(), executionMode, provider);
12091203
}
12101204

12111205
/**
@@ -1233,42 +1227,26 @@ public static void runApp(
12331227
@NonNull Server server,
12341228
@NonNull ExecutionMode executionMode,
12351229
@NonNull List<Supplier<Jooby>> provider) {
1236-
runApp(args, server, null, executionMode, provider);
1237-
}
1238-
1239-
/**
1240-
* Setup default environment, logging (logback or log4j2) and run application.
1241-
*
1242-
* @param args Application arguments.
1243-
* @param server Server.
1244-
* @param executionMode Default application execution mode. Can be overridden by application.
1245-
* @param provider Application provider.
1246-
*/
1247-
private static void runApp(
1248-
@NonNull String[] args,
1249-
@NonNull Server server,
1250-
@Nullable ServerOptions options,
1251-
@NonNull ExecutionMode executionMode,
1252-
@NonNull List<Supplier<Jooby>> provider) {
1253-
12541230
/* Dump command line as system properties. */
12551231
parseArguments(args).forEach(System::setProperty);
1232+
ServerOptions appServerOptions = null;
12561233
var apps = new ArrayList<Jooby>();
12571234
var targetServer = server.getLoggerOff().isEmpty() ? server : MutedServer.mute(server);
12581235
try {
12591236
for (var factory : provider) {
12601237
var app = createApp(server, executionMode, factory);
12611238
/*
12621239
When running a single app instance, there is no issue with server options.
1263-
When multiple apps pick first on the provided order.
1240+
When multiple apps pick first in the provided order.
12641241
*/
1265-
if (options == null) {
1266-
options = ServerOptions.from(app.getConfig()).orElse(null);
1242+
if (appServerOptions == null) {
1243+
appServerOptions = ServerOptions.from(app.getConfig()).orElse(null);
12671244
}
12681245
apps.add(app);
12691246
}
1270-
if (options != null) {
1271-
server.setOptions(options);
1247+
// Override when there is something and server options were not set
1248+
if (server.getOptions().defaults && appServerOptions != null) {
1249+
server.setOptions(appServerOptions);
12721250
}
12731251
targetServer.start(apps.toArray(new Jooby[0]));
12741252
} catch (Throwable startupError) {

jooby/src/main/java/io/jooby/Server.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected void addShutdownHook() {
125125
}
126126
}
127127

128-
private ServerOptions options = new ServerOptions();
128+
private ServerOptions options = new ServerOptions(true);
129129

130130
@Override
131131
public final ServerOptions getOptions() {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ public class ServerOptions {
139139

140140
private Boolean expectContinue;
141141

142+
/** Internal usage only. */
143+
/*pakcage*/ boolean defaults;
144+
145+
/*package*/ ServerOptions(boolean defaults) {
146+
this.defaults = defaults;
147+
}
148+
149+
public ServerOptions() {
150+
this(false);
151+
}
152+
142153
/**
143154
* Creates server options from config object. The configuration options must provided entries
144155
* like: <code>server.port</code>, <code>server.ioThreads</code>, etc...

0 commit comments

Comments
 (0)