Skip to content

Commit

Permalink
Upgrade dropwizard version to 4.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
DanVanAtta committed Jul 30, 2024
1 parent 83b3c2f commit 9d8db1a
Show file tree
Hide file tree
Showing 41 changed files with 162 additions and 232 deletions.
15 changes: 10 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {

apply plugin: "com.diffplug.spotless"


jar {
manifest {
attributes "Main-Class": "org.triplea.spitfire.server.SpitfireServerApplication"
Expand Down Expand Up @@ -50,7 +49,7 @@ dockerCompose {
// waitAfterHealthyStateProbeFailure = java.time.Duration.ofSeconds(5) // how long to sleep before next attempt to check healthy status; default is 5 seconds
// checkContainersRunning = true // turns on/off checking if container is running or restarting (during waiting for open TCP port and healthy state); default is true
//
// captureContainersOutput = false // if true, prints output of all containers to Gradle output - very useful for debugging; default is false
captureContainersOutput = true // if true, prints output of all containers to Gradle output - very useful for debugging; default is false
// captureContainersOutputToFile = project.file('/path/to/logFile') // sends output of all containers to a log file
// captureContainersOutputToFiles = project.file('/path/to/directory') // sends output of all services to a dedicated log file in the directory specified, e.g. 'web.log' for service named 'log'
// composeLogToFile = project.file('build/my-logs.txt') // redirect output of composeUp and composeDown tasks to this file; default is null (ouput is not redirected)
Expand Down Expand Up @@ -116,7 +115,7 @@ ext {
awaitilityVersion = "4.2.1"
bcryptVersion = "0.10.2"
databaseRiderVersion = "1.43.0"
dropwizardVersion = "2.1.0"
dropwizardVersion = "4.0.7"
dropwizardWebsocketsVersion = "1.3.14"
feignVersion = "13.2.1"
hamcrestJsonVersion = "0.3"
Expand All @@ -132,12 +131,13 @@ ext {
mockitoVersion = "5.11.0"
openFeignVersion = "13.3"
postgresqlVersion = "42.7.3"
tripleaClient = "2.7.14846"
wireMockJunit5Version = "1.3.1"
}

dependencies {
implementation "at.favre.lib:bcrypt:$bcryptVersion"
implementation "com.liveperson:dropwizard-websockets:$dropwizardWebsocketsVersion"
implementation "be.tomcools:dropwizard-websocket-jsr356-bundle:4.0.0"
implementation "com.sun.mail:jakarta.mail:$jakartaMailVersion"
implementation "com.sun.xml.bind:jaxb-core:$jaxbCoreVersion"
implementation "com.sun.xml.bind:jaxb-impl:$jaxbImplVersion"
Expand All @@ -147,11 +147,16 @@ dependencies {
implementation "io.github.openfeign:feign-core:$openFeignVersion"
implementation "io.github.openfeign:feign-gson:$openFeignVersion"
implementation "javax.activation:activation:$javaxActivationVersion"
implementation "javax.servlet:servlet-api:2.5"
implementation "javax.xml.bind:jaxb-api:$jaxbApiVersion"
implementation "org.java-websocket:Java-WebSocket:$javaWebSocketVersion"
implementation "org.jdbi:jdbi3-core:$jdbiVersion"
implementation "org.jdbi:jdbi3-sqlobject:$jdbiVersion"
implementation "triplea:lobby-client:2.6.14759"
implementation "triplea:domain-data:$tripleaClient"
implementation "triplea:feign-common:$tripleaClient"
implementation "triplea:java-extras:$tripleaClient"
implementation "triplea:lobby-client:$tripleaClient"
implementation "triplea:websocket-client:$tripleaClient"
runtimeOnly "org.postgresql:postgresql:$postgresqlVersion"

testImplementation "com.github.database-rider:rider-junit5:$databaseRiderVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.dropwizard.auth.Authorizer;
import io.dropwizard.auth.CachingAuthenticator;
import io.dropwizard.auth.oauth.OAuthCredentialAuthFilter;
import io.dropwizard.setup.Environment;
import io.dropwizard.core.setup.Environment;
import java.security.Principal;
import java.time.Duration;
import lombok.experimental.UtilityClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.triplea.dropwizard.common;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;

/**
* This class is used to convert IllegalArgumentExceptions thrown by http endpoint controllers to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.triplea.dropwizard.common;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import lombok.experimental.UtilityClass;

@UtilityClass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.triplea.dropwizard.common;

import io.dropwizard.Configuration;
import io.dropwizard.configuration.EnvironmentVariableSubstitutor;
import io.dropwizard.configuration.SubstitutingSourceProvider;
import io.dropwizard.core.Configuration;
import io.dropwizard.core.setup.Bootstrap;
import io.dropwizard.core.setup.Environment;
import io.dropwizard.jdbi3.bundles.JdbiExceptionsBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.websockets.WebsocketBundle;
import java.util.Arrays;
import jakarta.ws.rs.container.ContainerRequestFilter;
import java.util.List;
import javax.websocket.server.ServerEndpointConfig;
import javax.ws.rs.container.ContainerRequestFilter;
import lombok.AllArgsConstructor;

/**
Expand All @@ -28,27 +25,13 @@ public static class WebsocketConfig {
private final String path;
}

private ServerConfiguration(
final Bootstrap<T> bootstrap, final WebsocketConfig... websocketConfigs) {
private ServerConfiguration(final Bootstrap<T> bootstrap) {
this.bootstrap = bootstrap;

final ServerEndpointConfig[] websockets = addWebsockets(websocketConfigs);
bootstrap.addBundle(new WebsocketBundle(websockets));
}

private ServerEndpointConfig[] addWebsockets(final WebsocketConfig... websocketConfigs) {
return Arrays.stream(websocketConfigs)
.map(
websocketConfig ->
ServerEndpointConfig.Builder.create(
websocketConfig.websocketClass, websocketConfig.path)
.build())
.toArray(ServerEndpointConfig[]::new);
}

public static <T extends Configuration> ServerConfiguration<T> build(
final Bootstrap<T> bootstrap, final WebsocketConfig... websocketConfigs) {
return new ServerConfiguration<>(bootstrap, websocketConfigs);
final Bootstrap<T> bootstrap) {
return new ServerConfiguration<>(bootstrap);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.triplea.http.client.HttpClientConstants;
import org.triplea.java.StringUtils;

/** Represents request data to create a github issue. */
Expand All @@ -20,12 +19,12 @@ public class CreateIssueRequest {
private String[] labels;

public String getTitle() {
return title == null ? null : StringUtils.truncate(title, HttpClientConstants.TITLE_MAX_LENGTH);
final int maxLength = 125;
return title == null ? null : StringUtils.truncate(title, maxLength);
}

public String getBody() {
return body == null
? null
: StringUtils.truncate(body, HttpClientConstants.REPORT_BODY_MAX_LENGTH);
final int maxLength = 65536;
return body == null ? null : StringUtils.truncate(body, maxLength);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.slf4j.LoggerFactory;
import org.triplea.http.client.HttpClient;

// import org.triplea.http.client.HttpClient;

/** Can be used to interact with github's webservice API. */
public class GithubApiClient {
/** If this client is set to 'test' mode, we will return a stubbed response. */
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/triplea/modules/chat/Chatters.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.triplea.modules.chat;

import com.google.common.annotations.VisibleForTesting;
import jakarta.websocket.CloseReason;
import java.net.InetAddress;
import java.time.Clock;
import java.time.Instant;
Expand All @@ -12,7 +13,6 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import javax.websocket.CloseReason;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/triplea/spitfire/server/HttpController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.triplea.spitfire.server;

import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

/**
* Base class for http server controllers. This class is mainly to share the annotations needed for
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/triplea/spitfire/server/ResponseStatus.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.triplea.spitfire.server;

import jakarta.ws.rs.core.Response;
import javax.annotation.Nonnull;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status.Family;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -20,8 +19,8 @@ public class ResponseStatus implements Response.StatusType {
@Nonnull private final Integer statusCode;

@Override
public Family getFamily() {
return Family.familyOf(getStatusCode());
public Response.Status.Family getFamily() {
return Response.Status.Family.familyOf(getStatusCode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.triplea.spitfire.server;

import be.tomcools.dropwizard.websocket.WebsocketBundle;
import com.codahale.metrics.MetricRegistry;
import io.dropwizard.Application;
import io.dropwizard.core.Application;
import io.dropwizard.core.setup.Bootstrap;
import io.dropwizard.core.setup.Environment;
import io.dropwizard.jdbi3.JdbiFactory;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.core.Jdbi;
Expand All @@ -13,8 +14,6 @@
import org.triplea.dropwizard.common.IllegalArgumentMapper;
import org.triplea.dropwizard.common.JdbiLogging;
import org.triplea.dropwizard.common.ServerConfiguration;
import org.triplea.dropwizard.common.ServerConfiguration.WebsocketConfig;
import org.triplea.http.client.web.socket.WebsocketPaths;
import org.triplea.modules.chat.ChatMessagingService;
import org.triplea.modules.chat.Chatters;
import org.triplea.modules.game.listing.GameListing;
Expand All @@ -29,7 +28,6 @@
import org.triplea.spitfire.server.controllers.lobby.moderation.AccessLogController;
import org.triplea.spitfire.server.controllers.lobby.moderation.BadWordsController;
import org.triplea.spitfire.server.controllers.lobby.moderation.DisconnectUserController;
import org.triplea.spitfire.server.controllers.lobby.moderation.GameChatHistoryController;
import org.triplea.spitfire.server.controllers.lobby.moderation.ModeratorAuditHistoryController;
import org.triplea.spitfire.server.controllers.lobby.moderation.ModeratorsController;
import org.triplea.spitfire.server.controllers.lobby.moderation.MuteUserController;
Expand Down Expand Up @@ -58,6 +56,7 @@ public class SpitfireServerApplication extends Application<SpitfireServerConfig>
private static final String[] DEFAULT_ARGS = new String[] {"server", "configuration.yml"};

private ServerConfiguration<SpitfireServerConfig> serverConfiguration;
private final WebsocketBundle websocketBundle = new WebsocketBundle();

/**
* Main entry-point method, launches the drop-wizard http server. If no args are passed then will
Expand All @@ -72,13 +71,10 @@ public static void main(final String[] args) throws Exception {
@Override
public void initialize(final Bootstrap<SpitfireServerConfig> bootstrap) {
serverConfiguration =
ServerConfiguration.build(
bootstrap,
new WebsocketConfig(GameConnectionWebSocket.class, WebsocketPaths.GAME_CONNECTIONS),
new WebsocketConfig(
PlayerConnectionWebSocket.class, WebsocketPaths.PLAYER_CONNECTIONS))
ServerConfiguration.build(bootstrap)
.enableEnvironmentVariablesInConfig()
.enableBetterJdbiExceptions();
bootstrap.addBundle(websocketBundle);
}

@Override
Expand All @@ -93,6 +89,9 @@ public void run(final SpitfireServerConfig configuration, final Environment envi
JdbiLogging.registerSqlLogger(jdbi);
}

websocketBundle.addEndpoint(GameConnectionWebSocket.class);
websocketBundle.addEndpoint(PlayerConnectionWebSocket.class);

serverConfiguration.registerRequestFilter(
environment, BannedPlayerFilter.newBannedPlayerFilter(jdbi));

Expand Down Expand Up @@ -127,10 +126,9 @@ public void run(final SpitfireServerConfig configuration, final Environment envi
CreateAccountController.build(jdbi),
DisconnectUserController.build(jdbi, chatters, playerConnectionMessagingBus),
ForgotPasswordController.build(configuration, jdbi),
GameChatHistoryController.build(jdbi),
GameHostingController.build(jdbi),
GameListingController.build(gameListing),
LobbyWatcherController.build(configuration, jdbi, gameListing),
LobbyWatcherController.build(configuration, gameListing),
LoginController.build(jdbi, chatters),
UsernameBanController.build(jdbi),
UserBanController.build(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.triplea.spitfire.server;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
import io.dropwizard.core.Configuration;
import io.dropwizard.db.DataSourceFactory;
import jakarta.validation.Valid;
import java.net.URI;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.triplea.http.client.github.GithubApiClient;
Expand Down Expand Up @@ -34,8 +33,7 @@ public class SpitfireServerConfig extends Configuration implements LobbyModuleCo
@Setter(onMethod_ = {@JsonProperty})
private boolean logSqlStatements;

@Valid @NotNull @JsonProperty @Getter
private final DataSourceFactory database = new DataSourceFactory();
@Valid @JsonProperty @Getter private final DataSourceFactory database = new DataSourceFactory();

@Getter(onMethod_ = {@JsonProperty})
@Setter(onMethod_ = {@JsonProperty})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.container.PreMatching;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.Provider;
import java.time.Clock;
import java.time.Duration;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.Provider;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.eclipse.jetty.http.HttpStatus;
import org.jdbi.v3.core.Jdbi;
import org.triplea.db.dao.user.ban.BanLookupRecord;
import org.triplea.db.dao.user.ban.UserBanDao;
import org.triplea.dropwizard.common.IpAddressExtractor;
import org.triplea.http.client.LobbyHttpClientConfig;
import org.triplea.http.client.lobby.moderator.BanDurationFormatter;
import org.triplea.spitfire.server.ResponseStatus;

@Provider
@PreMatching
Expand All @@ -44,7 +41,7 @@ public void filter(final ContainerRequestContext requestContext) {
if (Strings.emptyToNull(request.getHeader(LobbyHttpClientConfig.SYSTEM_ID_HEADER)) == null) {
// missing system id header, abort the request
requestContext.abortWith(
Response.status(Status.UNAUTHORIZED).entity("Invalid request").build());
Response.status(Response.Status.UNAUTHORIZED).entity("Invalid request").build());

} else {
// check if user is banned, if so abort the request
Expand All @@ -56,11 +53,7 @@ public void filter(final ContainerRequestContext requestContext) {
.ifPresent(
banMessage ->
requestContext.abortWith(
Response.status(
ResponseStatus.builder()
.statusCode(HttpStatus.UNAUTHORIZED_401)
.reasonPhrase(banMessage)
.build())
Response.status(Response.Status.UNAUTHORIZED.getStatusCode(), banMessage)
.build()));
}
}
Expand Down
Loading

0 comments on commit 9d8db1a

Please sign in to comment.