forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vertx HTTP: execute custom logic when HTTP server is started
- resolves quarkusio#42366
- Loading branch information
1 parent
ff782c7
commit 821fd5c
Showing
6 changed files
with
197 additions
and
11 deletions.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
...-http/deployment/src/test/java/io/quarkus/vertx/http/start/HttpServerStartEventsTest.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,69 @@ | ||
package io.quarkus.vertx.http.start; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import jakarta.annotation.PreDestroy; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.event.ObservesAsync; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.vertx.http.HttpServerStart; | ||
import io.quarkus.vertx.http.HttpsServerStart; | ||
import io.smallrye.certs.Format; | ||
import io.smallrye.certs.junit5.Certificate; | ||
import io.smallrye.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = @Certificate(name = "ssl-test", password = "secret", formats = { | ||
Format.JKS, Format.PKCS12, Format.PEM })) | ||
public class HttpServerStartEventsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root.addClasses(MyListener.class) | ||
.addAsResource(new File("target/certs/ssl-test-keystore.jks"), "server-keystore.jks")) | ||
.overrideConfigKey("quarkus.http.ssl.certificate.key-store-file", "server-keystore.jks") | ||
.overrideConfigKey("quarkus.http.ssl.certificate.key-store-password", "secret"); | ||
|
||
@Test | ||
public void test() throws InterruptedException { | ||
assertTrue(MyListener.HTTP.await(5, TimeUnit.SECONDS)); | ||
assertTrue(MyListener.HTTPS.await(5, TimeUnit.SECONDS)); | ||
// httpsStarted() is static | ||
assertEquals(1, MyListener.COUNTER.get()); | ||
} | ||
|
||
@Dependent | ||
public static class MyListener { | ||
|
||
static final AtomicInteger COUNTER = new AtomicInteger(); | ||
static final CountDownLatch HTTP = new CountDownLatch(1); | ||
static final CountDownLatch HTTPS = new CountDownLatch(1); | ||
|
||
void httpStarted(@ObservesAsync HttpServerStart start) { | ||
assertNotNull(start.options()); | ||
HTTP.countDown(); | ||
} | ||
|
||
static void httpsStarted(@ObservesAsync HttpsServerStart start) { | ||
assertNotNull(start.options()); | ||
HTTPS.countDown(); | ||
} | ||
|
||
@PreDestroy | ||
void destroy() { | ||
COUNTER.incrementAndGet(); | ||
} | ||
|
||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...sions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/DomainSocketServerStart.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,21 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import io.vertx.core.http.HttpServerOptions; | ||
|
||
/** | ||
* Quarkus fires a CDI event of this type asynchronously when the domain socket server starts listening | ||
* on the configured host and port. | ||
* | ||
* <pre> | ||
* @ApplicationScoped | ||
* public class MyListener { | ||
* | ||
* void domainSocketStarted(@ObservesAsync DomainSocketServerStart start) { | ||
* // ...notified when the domain socket server starts listening | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
public record DomainSocketServerStart(HttpServerOptions options) { | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/HttpServerStart.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,21 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import io.vertx.core.http.HttpServerOptions; | ||
|
||
/** | ||
* Quarkus fires a CDI event of this type asynchronously when the HTTP server starts listening | ||
* on the configured host and port. | ||
* | ||
* <pre> | ||
* @ApplicationScoped | ||
* public class MyListener { | ||
* | ||
* void httpStarted(@ObservesAsync HttpServerStart start) { | ||
* // ...notified when the HTTP server starts listening | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
public record HttpServerStart(HttpServerOptions options) { | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/HttpsServerStart.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,21 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import io.vertx.core.http.HttpServerOptions; | ||
|
||
/** | ||
* Quarkus fires a CDI event of this type asynchronously when the HTTPS server starts listening | ||
* on the configured host and port. | ||
* | ||
* <pre> | ||
* @ApplicationScoped | ||
* public class MyListener { | ||
* | ||
* void httpsStarted(@ObservesAsync HttpsServerStart start) { | ||
* // ...notified when the HTTPS server starts listening | ||
* } | ||
* } | ||
* </pre> | ||
*/ | ||
public record HttpsServerStart(HttpServerOptions options) { | ||
|
||
} |
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