-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make sure annotated endpoints works along Vaadin PUSH (#86)
The workaround added to make PUSH work in Quarkus prevents the usage of custom annotated websocket endpoint. This change allows them to work along Vaadin PUSH. Fixes #78
- Loading branch information
1 parent
eabc925
commit 74310d8
Showing
14 changed files
with
311 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...sts/common-test-code/src/main/java/com/vaadin/flow/quarkus/it/CustomAnnotatedEnpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.vaadin.flow.quarkus.it; | ||
|
||
import jakarta.websocket.OnMessage; | ||
import jakarta.websocket.OnOpen; | ||
import jakarta.websocket.Session; | ||
import jakarta.websocket.server.ServerEndpoint; | ||
|
||
@ServerEndpoint(CustomAnnotatedEnpoint.URI) | ||
public class CustomAnnotatedEnpoint { | ||
|
||
public static final String URI = "/app-annotated-websocket"; | ||
public static final String PREFIX = ">> Application Annotated Endpoint: "; | ||
|
||
@OnOpen | ||
public void onOpen(Session session) { | ||
session.getAsyncRemote().sendText(PREFIX + "Welcome"); | ||
} | ||
|
||
@OnMessage | ||
public void onMessage(String message, Session session) { | ||
session.getAsyncRemote().sendText(PREFIX + message); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...n-tests/common-test-code/src/test/java/com/vaadin/flow/quarkus/it/CustomWebsocketsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.vaadin.flow.quarkus.it; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.concurrent.LinkedBlockingDeque; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import jakarta.websocket.ClientEndpoint; | ||
import jakarta.websocket.ContainerProvider; | ||
import jakarta.websocket.OnMessage; | ||
import jakarta.websocket.OnOpen; | ||
import jakarta.websocket.Session; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.vaadin.sample.websockets.DependencyAnnotatedWS; | ||
import org.vaadin.sample.websockets.SimpleEndpoint; | ||
|
||
@QuarkusIntegrationTest | ||
class CustomWebsocketsIT { | ||
|
||
@TestHTTPResource(DependencyAnnotatedWS.URI) | ||
URI dependencyAnnotatedWSURI; | ||
|
||
@TestHTTPResource(SimpleEndpoint.URI) | ||
URI dependencyNotAnnotatedWSURI; | ||
|
||
@TestHTTPResource(CustomAnnotatedEnpoint.URI) | ||
URI appAnnotatedWSURI; | ||
|
||
@Test | ||
void dependencyAnnotatedEndpointShouldWork() throws Exception { | ||
assertWebsocketWorks(dependencyAnnotatedWSURI, | ||
DependencyAnnotatedWS.PREFIX); | ||
} | ||
|
||
@Test | ||
void applicationAnnotatedEndpointShouldWork() throws Exception { | ||
assertWebsocketWorks(appAnnotatedWSURI, CustomAnnotatedEnpoint.PREFIX); | ||
} | ||
|
||
@Test | ||
void dependencyNotAnnotatedEndpointShouldWork() throws Exception { | ||
assertWebsocketWorks(dependencyNotAnnotatedWSURI, | ||
SimpleEndpoint.PREFIX); | ||
} | ||
|
||
void assertWebsocketWorks(URI uri, String messagePrefix) throws Exception { | ||
Client client = new Client(); | ||
try (Session session = ContainerProvider.getWebSocketContainer() | ||
.connectToServer(client, uri)) { | ||
Assertions.assertEquals("CONNECT", client.receivedMessage()); | ||
Assertions.assertEquals(messagePrefix + "Welcome", | ||
client.receivedMessage()); | ||
session.getBasicRemote().sendText("hello world"); | ||
Assertions.assertEquals(messagePrefix + "hello world", | ||
client.receivedMessage()); | ||
} | ||
} | ||
|
||
@ClientEndpoint | ||
public static class Client { | ||
final LinkedBlockingDeque<String> messages = new LinkedBlockingDeque<>(); | ||
|
||
@OnOpen | ||
public void open(Session session) throws IOException { | ||
messages.add("CONNECT"); | ||
} | ||
|
||
@OnMessage | ||
void message(String msg) { | ||
messages.add(msg); | ||
} | ||
|
||
String receivedMessage() throws InterruptedException { | ||
return messages.poll(12, TimeUnit.SECONDS); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0"?> | ||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
|
||
<parent> | ||
<groupId>com.vaadin</groupId> | ||
<artifactId>vaadin-quarkus-integration-tests</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>custom-websockets</artifactId> | ||
<name>Test dependency with custom websocket endpoints</name> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<maven.deploy.skip>true</maven.deploy.skip> | ||
<maven.javadoc.skip>true</maven.javadoc.skip> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.websocket</groupId> | ||
<artifactId>jakarta.websocket-api</artifactId> | ||
<version>2.1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.websocket</groupId> | ||
<artifactId>jakarta.websocket-client-api</artifactId> | ||
<version>2.1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jboss.jandex</groupId> | ||
<artifactId>jandex-maven-plugin</artifactId> | ||
<version>1.2.2</version> | ||
<executions> | ||
<execution> | ||
<id>make-index</id> | ||
<goals> | ||
<goal>jandex</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
23 changes: 23 additions & 0 deletions
23
...ebsocket-dependency/src/main/java/org/vaadin/sample/websockets/DependencyAnnotatedWS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.vaadin.sample.websockets; | ||
|
||
import jakarta.websocket.OnMessage; | ||
import jakarta.websocket.OnOpen; | ||
import jakarta.websocket.Session; | ||
import jakarta.websocket.server.ServerEndpoint; | ||
|
||
@ServerEndpoint(DependencyAnnotatedWS.URI) | ||
public class DependencyAnnotatedWS { | ||
|
||
public static final String URI = "/dependency-annotated-websocket"; | ||
public static final String PREFIX = ">> Dependency Annotated Endpoint: "; | ||
|
||
@OnOpen | ||
public void onOpen(Session session) { | ||
session.getAsyncRemote().sendText(PREFIX + "Welcome"); | ||
} | ||
|
||
@OnMessage | ||
public void onMessage(String message, Session session) { | ||
session.getAsyncRemote().sendText(PREFIX + message); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ustom-websocket-dependency/src/main/java/org/vaadin/sample/websockets/SimpleEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.vaadin.sample.websockets; | ||
|
||
import jakarta.websocket.Endpoint; | ||
import jakarta.websocket.EndpointConfig; | ||
import jakarta.websocket.MessageHandler; | ||
import jakarta.websocket.RemoteEndpoint; | ||
import jakarta.websocket.Session; | ||
|
||
public class SimpleEndpoint extends Endpoint { | ||
|
||
public static final String URI = "/dependency-websocket"; | ||
|
||
public static final String PREFIX = ">> Dependency Simple Endpoint: "; | ||
|
||
@Override | ||
public void onOpen(Session session, EndpointConfig config) { | ||
Handler handler = new Handler(session.getAsyncRemote()); | ||
session.addMessageHandler(handler); | ||
handler.reply("Welcome"); | ||
} | ||
|
||
private static class Handler implements MessageHandler.Whole<String> { | ||
|
||
private final RemoteEndpoint.Async remote; | ||
|
||
public Handler(RemoteEndpoint.Async remote) { | ||
this.remote = remote; | ||
} | ||
|
||
@Override | ||
public void onMessage(String message) { | ||
reply(message); | ||
} | ||
|
||
private void reply(String message) { | ||
remote.sendText(PREFIX + message); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...websocket-dependency/src/main/java/org/vaadin/sample/websockets/SimpleEndpointConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.vaadin.sample.websockets; | ||
|
||
import jakarta.websocket.Endpoint; | ||
import jakarta.websocket.server.ServerApplicationConfig; | ||
import jakarta.websocket.server.ServerEndpointConfig; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class SimpleEndpointConfig implements ServerApplicationConfig { | ||
@Override | ||
public Set<ServerEndpointConfig> getEndpointConfigs( | ||
Set<Class<? extends Endpoint>> endpointClasses) { | ||
return Set.of(ServerEndpointConfig.Builder | ||
.create(SimpleEndpoint.class, SimpleEndpoint.URI).build()); | ||
} | ||
|
||
@Override | ||
public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) { | ||
return Collections.emptySet(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.