Skip to content

Commit c34f85a

Browse files
committed
update debugging a bit, repair tests and make some fields protected instead of private
1 parent 63c9906 commit c34f85a

File tree

3 files changed

+7
-23
lines changed

3 files changed

+7
-23
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<modelVersion>4.0.0</modelVersion>
1212
<artifactId>websocket-server</artifactId>
13-
<version>1.0.6</version>
13+
<version>1.0.7</version>
1414
<name>WebsocketServer</name>
1515
<packaging>jar</packaging>
1616

src/main/java/info/unterrainer/websocketserver/WsOauthHandlerBase.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
@Slf4j
1919
public class WsOauthHandlerBase extends WsHandlerBase {
2020

21-
private OauthTokenManager tokenHandler;
22-
private Set<WsConnectContext> clientsConnected = ConcurrentHashMap.newKeySet();
23-
private Set<WsConnectContext> clientsQuarantined = ConcurrentHashMap.newKeySet();
21+
protected OauthTokenManager tokenHandler;
22+
protected Set<WsConnectContext> clientsConnected = ConcurrentHashMap.newKeySet();
23+
protected Set<WsConnectContext> clientsQuarantined = ConcurrentHashMap.newKeySet();
2424

2525
void setTokenHandler(OauthTokenManager tokenHandler) {
2626
this.tokenHandler = tokenHandler;
@@ -89,6 +89,8 @@ public void onMessage(WsMessageContext ctx) throws Exception {
8989
try {
9090
tokenHandler.checkAccess(ctx.message());
9191
WsConnectContext client = getQuarantinedClient(ctx.session);
92+
log.debug("Client [{}] passed token validation. Moving from quarantine to connected.",
93+
ctx.session.getRemoteAddress());
9294
clientsQuarantined.removeIf(c -> c.session.equals(ctx.session));
9395
clientsConnected.add(client);
9496
} catch (Exception e) {

src/test/java/info/unterrainer/websocketserver/AiComm.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
11
package info.unterrainer.websocketserver;
22

3-
import java.util.Set;
4-
import java.util.concurrent.ConcurrentHashMap;
5-
6-
import io.javalin.websocket.WsCloseContext;
73
import io.javalin.websocket.WsConnectContext;
84
import io.javalin.websocket.WsMessageContext;
95
import lombok.extern.slf4j.Slf4j;
106

117
@Slf4j
128
public class AiComm extends WsOauthHandlerBase {
139

14-
private Set<WsConnectContext> connectedWsClients = ConcurrentHashMap.newKeySet();
15-
16-
@Override
17-
public void onConnect(WsConnectContext ctx) throws Exception {
18-
super.onConnect(ctx);
19-
connectedWsClients.add(ctx);
20-
ctx.send("Welcome to our websocket-server!");
21-
}
22-
23-
@Override
24-
public void onClose(WsCloseContext ctx) {
25-
connectedWsClients.removeIf(client -> client.session.equals(ctx.session));
26-
}
27-
2810
@Override
2911
public void onMessage(WsMessageContext ctx) throws Exception {
3012
super.onMessage(ctx);
3113

3214
// Broadcast to all connected WS clients.
33-
for (WsConnectContext client : connectedWsClients) {
15+
for (WsConnectContext client : clientsConnected) {
3416
if (client.session.isOpen()) {
3517
client.send("Echo from server: [" + ctx.message() + "]");
3618
}

0 commit comments

Comments
 (0)