Skip to content

Commit e12edd9

Browse files
Update javalin to v7 (major) (#159)
* Update javalin to v7 * migrate methods --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
1 parent a421b7a commit e12edd9

4 files changed

Lines changed: 30 additions & 29 deletions

File tree

bot/src/main/java/de/chojo/gamejam/api/Api.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,36 @@ public Api(Configuration configuration, ShardManager shardManager, Guilds guilds
5757

5858
private void build() {
5959
app = Javalin.create(config -> {
60-
config.useVirtualThreads = true;
60+
config.concurrency.useVirtualThreads = true;
6161
config.requestLogger.http((ctx, executionTimeMs) -> {
6262
log.debug("{}: {} in {}ms\nHeaders:\n{}\nBody:\n{}",
6363
ctx.method(), ctx.path(), executionTimeMs,
6464
headers(ctx),
6565
ctx.body().substring(0, Math.min(100, ctx.body().length())));
6666
});
67-
config.router.apiBuilder(this::routes);
67+
config.routes.apiBuilder(this::routes);
6868
config.registerPlugin(openApi());
6969
config.registerPlugin(swagger());
70-
}).start(configuration.api().host(), configuration.api().port());
7170

72-
app.exception(InterruptException.class, (exception, ctx) -> {
73-
ctx.status(exception.status()).result(exception.getMessage());
74-
});
7571

76-
app.beforeMatched(ctx -> {
77-
for (String path : unauthorized) {
78-
if(ctx.path().startsWith(path)) return;
79-
}
80-
81-
var token = ctx.req().getHeader("authorization");
82-
if (token == null) {
83-
throw new UnauthorizedResponse();
84-
} else if (!token.equals(configuration.api().token())) {
85-
throw new UnauthorizedResponse();
86-
}
87-
});
72+
config.routes.exception(InterruptException.class, (exception, ctx) -> {
73+
ctx.status(exception.status()).result(exception.getMessage());
74+
});
75+
76+
config.routes.beforeMatched(ctx -> {
77+
for (String path : unauthorized) {
78+
if(ctx.path().startsWith(path)) return;
79+
}
80+
81+
var token = ctx.req().getHeader("authorization");
82+
if (token == null) {
83+
throw new UnauthorizedResponse();
84+
} else if (!token.equals(configuration.api().token())) {
85+
throw new UnauthorizedResponse();
86+
}
87+
});
88+
89+
}).start(configuration.api().host(), configuration.api().port());
8890
}
8991

9092
private void routes() {
@@ -111,23 +113,22 @@ private OpenApiPlugin openApi() {
111113
return new OpenApiPlugin(config ->
112114
config.withDocumentationPath("/api/openapi.json")
113115
.withDefinitionConfiguration((version, definition) ->
114-
definition.withInfo(info ->
116+
definition.info(info ->
115117
info.description("Plugin Jam Bot")
116118
.license("AGPL-3.0")
117119
)
118-
.withServer(server ->
120+
.server(server ->
119121
server.description("Lyna Backend")
120122
.url(configuration.api().url()))
121-
.withSecurity(security ->
122-
security.withApiKeyAuth("Authorization", "Authorization"))
123+
.withApiKeyAuth("Authorization", "Authorization")
123124
)
124125
);
125126
}
126127

127128
private SwaggerPlugin swagger() {
128129
return new SwaggerPlugin(conf -> {
129-
conf.setUiPath("/api/swagger");
130-
conf.setDocumentationPath("/api/openapi.json");
130+
conf.withUiPath("/api/swagger");
131+
conf.withDocumentationPath("/api/openapi.json");
131132
});
132133
}
133134

plugin-paper/src/main/java/de/chojo/pluginjam/api/Api.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ private void ignite() {
4242
var classLoader = Thread.currentThread().getContextClassLoader();
4343
Thread.currentThread().setContextClassLoader(PluginJam.class.getClassLoader());
4444
javalin = Javalin.create(config -> {
45-
config.useVirtualThreads = true;
46-
config.router.apiBuilder(this::routes);
45+
config.concurrency.useVirtualThreads = true;
46+
config.routes.apiBuilder(this::routes);
4747
});
4848
javalin.start("0.0.0.0", Integer.parseInt(System.getProperty("javalin.port", "30000")));
4949
Thread.currentThread().setContextClassLoader(classLoader);

plugin-velocity/src/main/java/de/chojo/pluginjam/web/Api.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ private void ignite() {
3535
var classLoader = Thread.currentThread().getContextClassLoader();
3636
Thread.currentThread().setContextClassLoader(PluginJam.class.getClassLoader());
3737
javalin = Javalin.create(config -> {
38-
config.useVirtualThreads = true;
39-
config.router.apiBuilder(this::routes);
38+
config.concurrency.useVirtualThreads = true;
39+
config.routes.apiBuilder(this::routes);
4040
});
4141
int port = Integer.parseInt(System.getProperty("javalin.port", "30000"));
4242
javalin.start("0.0.0.0", port);

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencyResolutionManagement {
2323
bundle("logging", listOf("slf4j", "log4j-core", "log4j-slf4j2"))
2424

2525

26-
version("javalin", "6.7.0")
26+
version("javalin", "7.0.0")
2727
library("javalin-core", "io.javalin", "javalin").versionRef("javalin")
2828
library("javalin-bundle", "io.javalin", "javalin-bundle").versionRef("javalin")
2929
library("javalin-annotation", "io.javalin.community.openapi", "openapi-annotation-processor").versionRef("javalin")

0 commit comments

Comments
 (0)