Skip to content

Commit

Permalink
Merge pull request #4268 from cristianonicolai/4267
Browse files Browse the repository at this point in the history
Support WebSocket sub-protocols
  • Loading branch information
stuartwdouglas authored Nov 5, 2019
2 parents 2040247 + a1055ac commit 0996aa8
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 9 deletions.
5 changes: 5 additions & 0 deletions bom/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-graphql-deployment</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
5 changes: 5 additions & 0 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,11 @@
<artifactId>keycloak-authz-client</artifactId>
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-graphql</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@

<!-- vault -->
<module>vault</module>
<module>vertx-graphql</module>
</modules>

<!-- Unfortunately the config below introduces a build dependency on the maven plugin
Expand Down
49 changes: 49 additions & 0 deletions extensions/vertx-graphql/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-graphql-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-vertx-graphql-deployment</artifactId>
<name>Quarkus - Quarkus - Vert.x GraphQL - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-graphql</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.vertx.graphql.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.vertx.http.deployment.WebsocketSubProtocolsBuildItem;

class VertxGraphqlProcessor {

private static final String FEATURE = "vertx-graphql";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
WebsocketSubProtocolsBuildItem websocketSubProtocols(CombinedIndexBuildItem combinedIndexBuildItem) {
return new WebsocketSubProtocolsBuildItem("graphql-ws");
}
}
21 changes: 21 additions & 0 deletions extensions/vertx-graphql/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extensions-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-vertx-graphql-parent</artifactId>
<name>Quarkus - Quarkus - Vert.x GraphQL - Parent</name>

<packaging>pom</packaging>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
43 changes: 43 additions & 0 deletions extensions/vertx-graphql/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-graphql-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-vertx-graphql</artifactId>
<name>Quarkus - Quarkus - Vert.x GraphQL - Runtime</name>

<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-graphql</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ ServiceStartBuildItem finalizeRouter(
InternalWebVertxBuildItem vertx,
LaunchModeBuildItem launchMode, ShutdownContextBuildItem shutdown, List<DefaultRouteBuildItem> defaultRoutes,
List<FilterBuildItem> filters, VertxWebRouterBuildItem router, EventLoopCountBuildItem eventLoopCountBuildItem,
HttpBuildTimeConfig httpBuildTimeConfig)
HttpBuildTimeConfig httpBuildTimeConfig,
List<WebsocketSubProtocolsBuildItem> websocketSubProtocolsBuildItem)
throws BuildException, IOException {
Optional<DefaultRouteBuildItem> defaultRoute;
if (defaultRoutes == null || defaultRoutes.isEmpty()) {
Expand All @@ -129,7 +130,9 @@ ServiceStartBuildItem finalizeRouter(
boolean startSocket = !startVirtual || launchMode.getLaunchMode() != LaunchMode.NORMAL;
recorder.startServer(vertx.getVertx(), shutdown,
httpConfiguration, launchMode.getLaunchMode(), startVirtual, startSocket,
eventLoopCountBuildItem.getEventLoopCount());
eventLoopCountBuildItem.getEventLoopCount(),
websocketSubProtocolsBuildItem.stream().map(bi -> bi.getWebsocketSubProtocols())
.collect(Collectors.joining(",")));

return new ServiceStartBuildItem("vertx-http");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.vertx.http.deployment;

import io.quarkus.builder.item.MultiBuildItem;

public final class WebsocketSubProtocolsBuildItem extends MultiBuildItem {

private final String websocketSubProtocols;

public WebsocketSubProtocolsBuildItem(String websocketSubProtocols) {
this.websocketSubProtocols = websocketSubProtocols;
}

public String getWebsocketSubProtocols() {
return websocketSubProtocols;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static void startServerAfterFailedStart() {
public Integer get() {
return ProcessorInfo.availableProcessors() * 2; //this is dev mode, so the number of IO threads not always being 100% correct does not really matter in this case
}
});
}, null);

} catch (Exception e) {
throw new RuntimeException(e);
Expand All @@ -147,7 +147,8 @@ public RuntimeValue<Router> initializeRouter(final RuntimeValue<Vertx> vertxRunt

public void startServer(RuntimeValue<Vertx> vertxRuntimeValue, ShutdownContext shutdown,
HttpConfiguration httpConfiguration, LaunchMode launchMode,
boolean startVirtual, boolean startSocket, Supplier<Integer> ioThreads) throws IOException {
boolean startVirtual, boolean startSocket, Supplier<Integer> ioThreads, String websocketSubProtocols)
throws IOException {

Vertx vertx = vertxRuntimeValue.getValue();
if (startVirtual) {
Expand All @@ -156,7 +157,7 @@ public void startServer(RuntimeValue<Vertx> vertxRuntimeValue, ShutdownContext s
if (startSocket) {
// Start the server
if (closeTask == null) {
doServerStart(vertx, httpConfiguration, launchMode, ioThreads);
doServerStart(vertx, httpConfiguration, launchMode, ioThreads, websocketSubProtocols);
if (launchMode != LaunchMode.DEVELOPMENT) {
shutdown.addShutdownTask(closeTask);
}
Expand Down Expand Up @@ -213,10 +214,9 @@ public void finalizeRouter(BeanContainer container, Consumer<Route> defaultRoute
}

private static void doServerStart(Vertx vertx, HttpConfiguration httpConfiguration, LaunchMode launchMode,
Supplier<Integer> eventLoops)
throws IOException {
Supplier<Integer> eventLoops, String websocketSubProtocols) throws IOException {
// Http server configuration
HttpServerOptions httpServerOptions = createHttpServerOptions(httpConfiguration, launchMode);
HttpServerOptions httpServerOptions = createHttpServerOptions(httpConfiguration, launchMode, websocketSubProtocols);
HttpServerOptions sslConfig = createSslOptions(httpConfiguration, launchMode);

int eventLoopCount = eventLoops.get();
Expand Down Expand Up @@ -393,12 +393,13 @@ private static byte[] doRead(InputStream is) throws IOException {
}

private static HttpServerOptions createHttpServerOptions(HttpConfiguration httpConfiguration,
LaunchMode launchMode) {
LaunchMode launchMode, String websocketSubProtocols) {
// TODO other config properties
HttpServerOptions options = new HttpServerOptions();
options.setHost(httpConfiguration.host);
options.setPort(httpConfiguration.determinePort(launchMode));
options.setMaxHeaderSize(httpConfiguration.limits.maxHeaderSize.asBigInteger().intValueExact());
options.setWebsocketSubProtocols(websocketSubProtocols);
return options;
}

Expand Down
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<module>narayana-stm</module>
<module>narayana-jta</module>
<module>elytron-security-jdbc</module>
<module>vertx-graphql</module>
</modules>

<build>
Expand Down
110 changes: 110 additions & 0 deletions integration-tests/vertx-graphql/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-integration-tests-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-vertx-graphql-integration-test</artifactId>
<name>Quarkus - Quarkus - Vert.x GraphQL - Integration Test</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-graphql</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<id>native-image</id>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<reportErrorsAtRuntime>false</reportErrorsAtRuntime>
<cleanupServer>true</cleanupServer>
<enableHttpsUrlHandler>true</enableHttpsUrlHandler>
<enableServer>false</enableServer>
<dumpProxies>false</dumpProxies>
<graalvmHome>${graalvmHome}</graalvmHome>
<enableJni>true</enableJni>
<enableAllSecurityServices>true</enableAllSecurityServices>
<enableReports>false</enableReports>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Loading

0 comments on commit 0996aa8

Please sign in to comment.