Skip to content

Commit

Permalink
Merge pull request #1311 from mkouba/vertx-web
Browse files Browse the repository at this point in the history
Add Vertx web extension
  • Loading branch information
cescoffier committed Mar 20, 2019
2 parents 4445ca4 + 70050ff commit d3b2afb
Show file tree
Hide file tree
Showing 22 changed files with 1,110 additions and 39 deletions.
11 changes: 11 additions & 0 deletions bom/pom.xml
Expand Up @@ -411,6 +411,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
Expand Down Expand Up @@ -1423,6 +1429,11 @@
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-axle-generator</artifactId>
Expand Down
12 changes: 11 additions & 1 deletion build-parent/pom.xml
Expand Up @@ -488,6 +488,16 @@
<artifactId>quarkus-vertx-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow-websockets</artifactId>
Expand Down Expand Up @@ -1011,4 +1021,4 @@
</build>
</profile>
</profiles>
</project>
</project>
Expand Up @@ -44,6 +44,7 @@ public final class FeatureBuildItem extends MultiBuildItem {
public static final String SPRING_DI = "spring-di";
public static final String UNDERTOW_WEBSOCKETS = "undertow-websockets";
public static final String VERTX = "vertx";
public static final String VERTX_WEB = "vertx-web";

private final String info;

Expand Down
@@ -1,31 +1,10 @@
/*
* Copyright 2018 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.quarkus.undertow.deployment.devmode;
package io.quarkus.deployment.devmode;

import java.io.PrintWriter;
import java.io.StringWriter;

import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;

/**
* Generates an error page with a stack trace
*
* @author Stuart Douglas
* Generates an error page with a stack trace.
*/
public class ReplacementDebugPage {

Expand Down Expand Up @@ -118,15 +97,7 @@ public class ReplacementDebugPage {
" line-height: 1.5;\n" +
"}\n";

public static void handleRequest(HttpServerExchange exchange, final Throwable exception) {
String bodyText = generateHtml(exception);

exchange.setStatusCode(500);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=UTF-8");
exchange.getResponseSender().send(bodyText);
}

private static String generateHtml(final Throwable exception) {
public static String generateHtml(final Throwable exception) {
String headerMessage = generateHeaderMessage(exception);
String stackTrace = generateStackTrace(exception);

Expand Down
Expand Up @@ -4,7 +4,6 @@
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;

import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
Expand Down Expand Up @@ -66,7 +65,7 @@ public <A extends Annotation> AnnotationProxyBuilder<A> builder(AnnotationInstan
if (clazz == null) {
try (InputStream annotationStream = IoUtil.readClass(classLoader, name.toString())) {
clazz = indexer.index(annotationStream);
} catch (IOException e) {
} catch (Exception e) {
throw new IllegalStateException("Failed to index: " + name, e);
}
}
Expand Down
1 change: 1 addition & 0 deletions extensions/pom.xml
Expand Up @@ -59,6 +59,7 @@

<!-- Reactive -->
<module>vertx</module>
<module>vertx-web</module>
<module>netty</module>
<module>reactive-streams-operators</module>
<module>smallrye-reactive-messaging</module>
Expand Down
Expand Up @@ -2,10 +2,12 @@

import io.quarkus.deployment.devmode.HotReplacementContext;
import io.quarkus.deployment.devmode.HotReplacementSetup;
import io.quarkus.deployment.devmode.ReplacementDebugPage;
import io.quarkus.undertow.runtime.UndertowDeploymentTemplate;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;

public class UndertowHotReplacementSetup implements HotReplacementSetup {

Expand Down Expand Up @@ -43,7 +45,7 @@ void handleHotDeploymentRequest(HttpServerExchange exchange, HttpHandler next) t

if (nextUpdate > System.currentTimeMillis()) {
if (context.getDeploymentProblem() != null) {
ReplacementDebugPage.handleRequest(exchange, context.getDeploymentProblem());
handleDeploymentProblem(exchange, context.getDeploymentProblem());
return;
}
next.handleRequest(exchange);
Expand All @@ -52,15 +54,22 @@ void handleHotDeploymentRequest(HttpServerExchange exchange, HttpHandler next) t
synchronized (this) {
if (nextUpdate < System.currentTimeMillis()) {
context.doScan();
//we update at most once every 2s
// we update at most once every 2s
nextUpdate = System.currentTimeMillis() + TWO_SECONDS;

}
}
if (context.getDeploymentProblem() != null) {
ReplacementDebugPage.handleRequest(exchange, context.getDeploymentProblem());
handleDeploymentProblem(exchange, context.getDeploymentProblem());
return;
}
next.handleRequest(exchange);
}

private void handleDeploymentProblem(HttpServerExchange exchange, final Throwable exception) {
String bodyText = ReplacementDebugPage.generateHtml(exception);
exchange.setStatusCode(500);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=UTF-8");
exchange.getResponseSender().send(bodyText);
}
}
72 changes: 72 additions & 0 deletions extensions/vertx-web/deployment/pom.xml
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2018 Red Hat, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<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">
<parent>
<artifactId>quarkus-vertx-web-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-vertx-web</artifactId>
<name>Quarkus - Vert.x Web - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-web-runtime</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<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>
@@ -0,0 +1,35 @@
package io.quarkus.vertx.web.deployment;

import java.util.List;

import org.jboss.builder.item.MultiBuildItem;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.MethodInfo;

import io.quarkus.arc.processor.BeanInfo;

public final class RouteHandlerBuildItem extends MultiBuildItem {

private final BeanInfo bean;
private final List<AnnotationInstance> routes;
private final MethodInfo method;

public RouteHandlerBuildItem(BeanInfo bean, MethodInfo method, List<AnnotationInstance> routes) {
this.bean = bean;
this.method = method;
this.routes = routes;
}

public BeanInfo getBean() {
return bean;
}

public MethodInfo getMethod() {
return method;
}

public List<AnnotationInstance> getRoutes() {
return routes;
}

}

0 comments on commit d3b2afb

Please sign in to comment.