Skip to content

Commit

Permalink
Marked vaadin-flow-sockjs as optional
Browse files Browse the repository at this point in the history
Making vaadin-flow-sockjs an optional dependency allows
end users to select the best matching implementation for
the Vaadin Flow version in use, by specifing
an appropriate classifier.
  • Loading branch information
mcollovati committed Sep 24, 2020
1 parent 7cff2fd commit 1096e4d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
51 changes: 30 additions & 21 deletions vertx-vaadin-flow-parent/vertx-vaadin-flow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,60 @@ All [Vaadin Servlet configuration parameters](https://vaadin.com/docs/v14/flow/a
}
```

Two dependencies are needed to run Vaadin on Vert.x: `vertx-vaadin` adapter and Servlet APIs (because Vaadin relies on them but they are not provided by Vert.x).
Two dependencies are needed to run Vaadin on Vert.x: `vertx-vaadin` adapter and Servlet APIs (because Vaadin relies on them, but they are not provided by Vert.x).

```xml
<dependency>
<groupId>com.github.mcollovati.vertx</groupId>
<artifactId>vertx-vaadin-flow</artifactId>
<version>13.0.2</version>
<version>${vertx-vaadin-flow.version}</version>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>4.0.2</version>
<version>${jakarta.servlet-api.version}</version>
<scope>runtime</scope>
</dependency>
```

## PUSH support

Vertx-Vaadin supports PUSH using a custom implementation based on SockJS that replaces the [Atmosphere stack](https://github.com/Atmosphere/atmosphere) on the client and server side. For this reason, Vaadin `flow-push` and `flow-client` dependencies must be excluded:
Vertx-Vaadin supports PUSH using a custom implementation based on SockJS that replaces the [Atmosphere stack](https://github.com/Atmosphere/atmosphere) on the client and server side.
For this reason, in addition to adding `vaadin-flow-sockjs`, Vaadin `flow-push` and `flow-client` dependencies must be excluded:

```xml
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
<exclusions>
<exclusion>
<groupId>com.vaadin</groupId>
<artifactId>flow-push</artifactId>
</exclusion>
<exclusion>
<groupId>com.vaadin</groupId>
<artifactId>flow-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependnecies>
<dependency>
<groupId>com.github.mcollovati.vertx</groupId>
<artifactId>vaadin-flow-sockjs</artifactId>
<version>${vertx-vaadin-flow.version}</version>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-core</artifactId>
<exclusions>
<exclusion>
<groupId>com.vaadin</groupId>
<artifactId>flow-push</artifactId>
</exclusion>
<exclusion>
<groupId>com.vaadin</groupId>
<artifactId>flow-client</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependnecies>
```

For better compatibility, add a dependency on the specific version of `vaadin-flow-sockjs` by specifying the classifier for the Vaadin version in use. For example:
For better compatibility, use a specific version of `vaadin-flow-sockjs` targeted to the Vaadin version in use by specifying the classifier.

```xml
<dependency>
<groupId>com.github.mcollovati.vertx</groupId>
<artifactId>vaadin-flow-sockjs</artifactId>
<version>13.0.2</version>
<version>${vertx-vaadin-flow.version}</version>
<classifier>vaadin-${vaadin.version}</classifier>
</dependency>
```
Expand Down Expand Up @@ -103,7 +112,7 @@ Change the scope of the Servlet API dependency from 'provided' to `runtime` (or
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>4.0.2</version>
<version>${jakarta.servlet-api.version}</version>
<scope>runtime</scope>
</dependency>
```
Expand Down
1 change: 1 addition & 0 deletions vertx-vaadin-flow-parent/vertx-vaadin-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<groupId>com.github.mcollovati.vertx</groupId>
<artifactId>vaadin-flow-sockjs</artifactId>
<version>${vaadin-flow-sockjs.version}</version>
<optional>true</optional>
</dependency>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,13 @@ private Router initRouter() {

// Serve push javascript
StaticHandler metaInfVaadinStatic = StaticHandler.create("META-INF/resources/VAADIN/static");

String pushJavascript = String.format(
"META-INF/resources/VAADIN/static/push/vaadinPush%s",
config.supportsSockJS() ? "SockJS" : ""
);
vaadinRouter.routeWithRegex("/VAADIN/static/push/vaadinPush(SockJS)?(?<suffix>.*)")
.handler(ctx -> ctx.response().sendFile("META-INF/resources/VAADIN/static/push/vaadinPushSockJS"
+ ctx.request().getParam("suffix")));
.handler(ctx -> ctx.response().sendFile(pushJavascript + ctx.request().getParam("suffix")));

if (DevModeHandler.getDevModeHandler() != null) {
logger.info("Starting DevModeHandler proxy");
Expand Down
5 changes: 5 additions & 0 deletions vertx-vaadin-flow-parent/vertx-vaadin-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<artifactId>vertx-vaadin-flow</artifactId>
<version>${vertx-vaadin-flow.version}</version>
</dependency>
<dependency>
<groupId>com.github.mcollovati.vertx</groupId>
<artifactId>vaadin-flow-sockjs</artifactId>
<version>${vertx-vaadin-flow.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
Expand Down

0 comments on commit 1096e4d

Please sign in to comment.