Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tests and move dropwizard to bom (pt2) #120

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR ./frontend
RUN npm i
RUN npm run build

FROM maven:3-openjdk-11 AS build
FROM maven:3-openjdk-17 AS build
WORKDIR /app

COPY backend/pom.xml ./
Expand All @@ -18,7 +18,7 @@ COPY backend/ ./

RUN mvn -Dmaven.test.skip=true package

FROM wirebot/runtime:1.3.0 AS runtime
FROM wirebot/runtime:1.4.0 AS runtime
LABEL description="Wire Roman"
LABEL project="wire-bots:roman"

Expand Down
113 changes: 76 additions & 37 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</licenses>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

Expand All @@ -31,15 +31,62 @@
<lithium.version>3.6.0</lithium.version>
<dropwizard.version>4.0.0</dropwizard.version>
<jwt.version>0.11.5</jwt.version>
<junit5.version>5.8.2</junit5.version>
<jetty.version>11.0.18</jetty.version>
<jakarta.version>2.1.1</jakarta.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-bom</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-auth</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-assets</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-servlets</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard-bundles</groupId>
<artifactId>dropwizard-configurable-assets-bundle</artifactId>
<version>1.3.5</version>
</dependency>
<!-- MIGRATION TO JAKARTA JETTY 11 -->
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.version}</version>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<version>${jakarta.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jakarta-server</artifactId>
<version>${jetty.version}</version>
</dependency>

<dependency>
<groupId>com.wire</groupId>
<artifactId>lithium</artifactId>
Expand Down Expand Up @@ -77,43 +124,35 @@
<version>${jwt.version}</version>
<scope>runtime</scope>
</dependency>

<!-- test dependencies-->
<dependency>
<groupId>io.dropwizard-bundles</groupId>
<artifactId>dropwizard-configurable-assets-bundle</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>io.dropwizard-bundles</groupId>
<artifactId>dropwizard-redirect-bundle</artifactId>
<version>1.3.5</version>
</dependency>
<!--TODO. replace with jakarta version?-->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>9.4.53.v20231009</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-servlets</artifactId>
<version>${dropwizard.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
<version>${dropwizard.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -123,9 +162,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dropwizard.modules</groupId>
<artifactId>dropwizard-testing-junit4</artifactId>
<version>${dropwizard.version}</version>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -136,8 +175,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 0 additions & 2 deletions backend/roman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ server:
requestLog:
appenders:
- type: ${APPENDER_TYPE:-console}
filterFactories:
- type: status-filter-factory

logging:
level: INFO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.wire.bots.roman.DAO;

import com.wire.bots.roman.DAO.mappers.UUIDMapper;
import jakarta.annotation.Nullable;
import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext;
import org.jdbi.v3.sqlobject.config.RegisterColumnMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;

import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.wire.bots.roman.DAO.mappers;

import com.wire.xenon.tools.Logger;
import jakarta.annotation.Nullable;
import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext;

import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/java/com/wire/bots/roman/MessageEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wire.bots.roman.model.OutgoingMessage;
import jakarta.websocket.EncodeException;
import jakarta.websocket.Encoder;
import jakarta.websocket.EndpointConfig;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

public class MessageEncoder implements Encoder.Text<OutgoingMessage> {

Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/com/wire/bots/roman/Sender.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import com.wire.xenon.exceptions.MissingStateException;
import com.wire.xenon.models.AssetKey;
import com.wire.xenon.tools.Logger;
import jakarta.annotation.Nullable;

import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Base64;
import java.util.UUID;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/com/wire/bots/roman/Tools.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.wire.bots.roman;

import io.jsonwebtoken.Jwts;
import jakarta.annotation.Nullable;

import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Date;
Expand Down
8 changes: 4 additions & 4 deletions backend/src/main/java/com/wire/bots/roman/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.wire.bots.roman.model.OutgoingMessage;
import com.wire.xenon.tools.Logger;
import jakarta.websocket.*;
import jakarta.websocket.server.PathParam;
import jakarta.websocket.server.ServerEndpoint;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -47,6 +47,6 @@ public void onClose(Session session) throws IOException {

@OnError
public void onError(Session session, Throwable throwable) {
Logger.exception(throwable,"%s error: %s", session.getId(), throwable.getMessage());
Logger.exception(throwable, "%s error: %s", session.getId(), throwable.getMessage());
}
}
51 changes: 15 additions & 36 deletions backend/src/main/java/com/wire/bots/roman/WebsocketBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,19 @@

package com.wire.bots.roman;

import com.codahale.metrics.MetricRegistry;
import com.wire.bots.roman.model.Config;
import io.dropwizard.core.ConfiguredBundle;
import io.dropwizard.core.setup.Bootstrap;
import io.dropwizard.core.setup.Environment;
import io.dropwizard.jetty.MutableServletContextHandler;
import jakarta.websocket.DeploymentException;
import jakarta.websocket.server.ServerContainer;
import jakarta.websocket.server.ServerEndpoint;
import jakarta.websocket.server.ServerEndpointConfig;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.websocket.common.events.EventDriverFactory;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
import org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration;
import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
import org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.websocket.DeploymentException;
import javax.websocket.server.ServerEndpoint;
import javax.websocket.server.ServerEndpointConfig;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -99,18 +94,21 @@ public void run(Config config, Environment environment) {
@Override
public void lifeCycleStarting(LifeCycle event) {
starting = true;
try {
ServerContainer wsContainer = InstWebSocketServerContainerInitializer.
configureContext(environment.getApplicationContext(), environment.metrics());

JakartaWebSocketServletContainerInitializer.configure(environment.getApplicationContext(), (servletContext, wsContainer) ->
{
// This lambda will be called at the appropriate place in the
// ServletContext initialization phase where you can initialize
// and configure your websocket container.
// Configure defaults for container
wsContainer.setDefaultMaxTextMessageBufferSize(65535);

// Add WebSocket endpoint to jakarta.websocket layer
StringBuilder sb = new StringBuilder("Registering websocket endpoints: ")
.append(System.lineSeparator())
.append(System.lineSeparator());
endpointConfigs.forEach(rethrow(conf -> addEndpoint(wsContainer, conf, sb)));
LOG.info(sb.toString());
} catch (ServletException ex) {
throw new RuntimeException(ex);
}
});
}

private void addEndpoint(ServerContainer wsContainer, ServerEndpointConfig conf, StringBuilder sb) throws DeploymentException {
Expand All @@ -120,25 +118,6 @@ private void addEndpoint(ServerContainer wsContainer, ServerEndpointConfig conf,
});
}

public static class InstWebSocketServerContainerInitializer {
public static ServerContainer configureContext(final MutableServletContextHandler context, final MetricRegistry metrics) throws ServletException {
WebSocketUpgradeFilter filter = WebSocketUpgradeFilter.configure(context);
NativeWebSocketConfiguration wsConfig = filter.getConfiguration();


ServerContainer wsContainer = new ServerContainer(wsConfig, context.getServer().getThreadPool());
EventDriverFactory edf = wsConfig.getFactory().getEventDriverFactory();
edf.clearImplementations();

//edf.addImplementation(new InstJsrServerEndpointImpl(metrics));
//edf.addImplementation(new InstJsrServerExtendsEndpointImpl(metrics));
context.addBean(wsContainer);
context.setAttribute(javax.websocket.server.ServerContainer.class.getName(), wsContainer);
context.setAttribute(WebSocketUpgradeFilter.class.getName(), filter);
return wsContainer;
}
}

public static <T> Consumer<T> rethrow(ConsumerCheckException<T> c) {
return t -> {
try {
Expand Down
Loading
Loading