-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Wire up Server Push #11082
Merged
Merged
Wire up Server Push #11082
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...ertow/deployment/src/test/java/io/quarkus/undertow/test/push/Http2ServerPushTestCase.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,97 @@ | ||
package io.quarkus.undertow.test.push; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.http.HttpClientOptions; | ||
import io.vertx.core.http.HttpClientRequest; | ||
import io.vertx.core.http.HttpClientResponse; | ||
import io.vertx.core.http.HttpVersion; | ||
import io.vertx.core.net.JdkSSLEngineOptions; | ||
|
||
public class Http2ServerPushTestCase { | ||
|
||
@TestHTTPResource(value = "/push", ssl = true) | ||
URL sslUrl; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ServerPushServlet.class, MessageServlet.class) | ||
.addAsResource(new File("src/test/resources/ssl-jks.conf"), "application.properties") | ||
.addAsResource(new File("src/test/resources/server-keystore.jks"), "server-keystore.jks")); | ||
|
||
@Test | ||
public void testServerPush() throws Exception { | ||
Assumptions.assumeTrue(JdkSSLEngineOptions.isAlpnAvailable()); //don't run on JDK8 | ||
Vertx vertx = Vertx.vertx(); | ||
try { | ||
HttpClientOptions options = new HttpClientOptions().setSsl(true).setUseAlpn(true) | ||
.setProtocolVersion(HttpVersion.HTTP_2).setVerifyHost(false).setTrustAll(true); | ||
|
||
final CompletableFuture<String> pushedPath = new CompletableFuture<>(); | ||
final CompletableFuture<String> pushedBody = new CompletableFuture<>(); | ||
|
||
HttpClientRequest request = vertx.createHttpClient(options) | ||
.get(sslUrl.getPort(), sslUrl.getHost(), sslUrl.getPath()); | ||
request.pushHandler(new Handler<HttpClientRequest>() { | ||
@Override | ||
public void handle(HttpClientRequest event) { | ||
pushedPath.complete(event.path()); | ||
event.handler(new Handler<HttpClientResponse>() { | ||
@Override | ||
public void handle(HttpClientResponse event) { | ||
event.bodyHandler(new Handler<Buffer>() { | ||
@Override | ||
public void handle(Buffer event) { | ||
pushedBody.complete(new String(event.getBytes(), StandardCharsets.UTF_8)); | ||
} | ||
}); | ||
event.exceptionHandler(new Handler<Throwable>() { | ||
@Override | ||
public void handle(Throwable event) { | ||
pushedBody.completeExceptionally(event); | ||
pushedPath.completeExceptionally(event); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
request.handler(new Handler<HttpClientResponse>() { | ||
@Override | ||
public void handle(HttpClientResponse event) { | ||
event.endHandler(new Handler<Void>() { | ||
@Override | ||
public void handle(Void event) { | ||
|
||
} | ||
}); | ||
} | ||
}); | ||
request.end(); | ||
Assertions.assertEquals("/pushed", pushedPath.get(10, TimeUnit.SECONDS)); | ||
Assertions.assertEquals("pushed-body", pushedBody.get(10, TimeUnit.SECONDS)); | ||
|
||
} finally { | ||
vertx.close(); | ||
} | ||
|
||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...sions/undertow/deployment/src/test/java/io/quarkus/undertow/test/push/MessageServlet.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,18 @@ | ||
package io.quarkus.undertow.test.push; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@WebServlet(urlPatterns = "/pushed") | ||
public class MessageServlet extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
resp.getWriter().print("pushed-body"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ns/undertow/deployment/src/test/java/io/quarkus/undertow/test/push/ServerPushServlet.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,20 @@ | ||
package io.quarkus.undertow.test.push; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@WebServlet(urlPatterns = "/push") | ||
public class ServerPushServlet extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
req.newPushBuilder() | ||
.path("pushed") | ||
.push(); | ||
} | ||
} |
Binary file added
BIN
+2.37 KB
extensions/undertow/deployment/src/test/resources/server-keystore.jks
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
extensions/undertow/deployment/src/test/resources/ssl-jks.conf
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,3 @@ | ||
# Enable SSL, configure the key store | ||
quarkus.http.ssl.certificate.key-store-file=server-keystore.jks | ||
quarkus.http.ssl.certificate.key-store-password=secret |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure: at this point we are entirely sure that the root handler is set in
VertxHttpRecorder
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. At this point the server is processing requests, if the root handler was not set then no request processing would be happening.