Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with RESTEasy GET requests when using standalone vert.x #4466

Merged
merged 3 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void close() throws IOException {
}
}

public class VertxBlockingInput implements Handler<Buffer> {
public static class VertxBlockingInput implements Handler<Buffer> {
protected final HttpServerRequest request;
protected Buffer input1;
protected Deque<Buffer> inputOverflow;
Expand Down Expand Up @@ -137,7 +137,7 @@ public void handle(Void event) {
});
request.fetch(1);
} else {
throw new IOException("Request was ended before Resteasy could process it.");
eof = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.IntStream;

import org.apache.commons.io.FileUtils;
import org.apache.maven.shared.invoker.MavenInvocationException;
Expand Down Expand Up @@ -43,6 +44,17 @@ public void testThatClassAppCanRun() throws MavenInvocationException, IOExceptio
assertThatOutputWorksCorrectly(running.log());
}

@Test
public void testThatResteasyWithoutUndertowCanRun() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic-no-undertow", "projects/project-classic-no-undertow-run");
run();

//make sure that a simple HTTP GET request always works
IntStream.range(0, 10).forEach(i -> {
assertThat(getStrictHttpResponse("/hello", 200)).isTrue();
});
}

@Test
public void testThatTheApplicationIsReloadedOnJavaChange() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-run-java-change");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>acme</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<quarkus.version>@project.version@</quarkus.version>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>quarkus-resteasy</artifactId>
<version>${quarkus.version}</version>
</dependency>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>quarkus-junit5</artifactId>
<version>${quarkus.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.acme;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class HelloResource {

@Inject
@ConfigProperty(name = "greeting")
String greeting;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}

@GET
@Path("/greeting")
@Produces(MediaType.TEXT_PLAIN)
public String greeting() {
return greeting;
}


public static class Blah {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>acme - 1.0-SNAPSHOT</title>
<style>
h1, h2, h3, h4, h5, h6 {
margin-bottom: 0.5rem;
font-weight: 400;
line-height: 1.5;
}

h1 {
font-size: 2.5rem;
}

h2 {
font-size: 2rem
}

h3 {
font-size: 1.75rem
}

h4 {
font-size: 1.5rem
}

h5 {
font-size: 1.25rem
}

h6 {
font-size: 1rem
}

.lead {
font-weight: 300;
font-size: 2rem;
}

.banner {
font-size: 2.7rem;
margin: 0;
padding: 2rem 1rem;
background-color: #00A1E2;
color: white;
}

body {
margin: 0;
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

code {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 87.5%;
color: #e83e8c;
word-break: break-word;
}

.left-column {
padding: .75rem;
max-width: 75%;
min-width: 55%;
}

.right-column {
padding: .75rem;
max-width: 25%;
}

.container {
display: flex;
width: 100%;
}

li {
margin: 0.75rem;
}

.right-section {
margin-left: 1rem;
padding-left: 0.5rem;
}

.right-section h3 {
padding-top: 0;
font-weight: 200;
}

.right-section ul {
border-left: 0.3rem solid #00A1E2;
list-style-type: none;
padding-left: 0;
}

</style>
</head>
<body>

<div class="banner lead">
Your new Cloud-Native application is ready!
</div>

<div class="container">
<div class="left-column">
<p class="lead"> Congratulations, you have created a new Quarkus application.</p>

<h2>Why do you see this?</h2>

<p>This page is served by Quarkus. The source is in
<code>src/main/resources/META-INF/resources/index.html</code>.</p>

<h2>What can I do from here?</h2>

<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>.
</p>
<ul>
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
<li>Configure your application in <code>src/main/resources/application.properties</code>.
</li>
</ul>

<h2>How do I get rid of this page?</h2>
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
</div>
<div class="right-column">
<div class="right-section">
<h3>Application</h3>
<ul>
<li>GroupId: org.acme</li>
<li>ArtifactId: acme</li>
<li>Version: 1.0-SNAPSHOT</li>
<li>Quarkus Version: 999-SNAPSHOT</li>
</ul>
</div>
<div class="right-section">
<h3>Next steps</h3>
<ul>
<!-- the url have been erased on purpose -->
<li><a href="#">Setup your IDE</a></li>
<li><a href="#">Getting started</a></li>
<li><a href="#">Documentation</a></li>
</ul>
</div>
</div>
</div>


</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Configuration file
key = value
greeting=bonjour
quarkus.live-reload.password=secret
quarkus.live-reload.url=http://localhost:8080/
quarkus.log.level=INFO
quarkus.log.file.enable=false
quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n
quarkus.log.file.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %h %N[%i] %-5p [%c{3.}] (%t) %s%e%n
quarkus.log.category."io.quarkus".level=INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.acme;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
public class HelloResourceTest {

@Test
public void testHelloEndpoint() {
given()
.when().get("/app/hello")
.then()
.statusCode(200)
.body(is("hello"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@ static boolean getHttpResponse(String path, int expectedStatus) {
return code.get();
}

// will fail if it receives any http response except the expected one
static boolean getStrictHttpResponse(String path, int expectedStatus) {
AtomicBoolean code = new AtomicBoolean();
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(5, TimeUnit.MINUTES).until(() -> {
try {
URL url = new URL("http://localhost:8080" + ((path.startsWith("/") ? path : "/" + path)));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// the default Accept header used by HttpURLConnection is not compatible with RESTEasy negotiation as it uses q=.2
connection.setRequestProperty("Accept", "text/html, *; q=0.2, */*; q=0.2");
code.set(connection.getResponseCode() == expectedStatus);
//complete no matter what the response code was
return true;
} catch (Exception e) {
return false;
}
});
return code.get();
}

public static String get() throws IOException {
URL url = new URL("http://localhost:8080");
return IOUtils.toString(url, "UTF-8");
Expand Down