-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26767 from cescoffier/vertx-server-customizer
Allows Vert.x HTTP Options customization
- Loading branch information
Showing
4 changed files
with
143 additions
and
3 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
...ment/src/test/java/io/quarkus/vertx/http/customizers/HttpServerOptionsCustomizerTest.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.customizers; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.event.Observes; | ||
import javax.inject.Inject; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.vertx.http.HttpServerOptionsCustomizer; | ||
import io.restassured.RestAssured; | ||
import io.vertx.core.http.HttpServerOptions; | ||
import io.vertx.mutiny.ext.web.Router; | ||
|
||
public class HttpServerOptionsCustomizerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(MyBean.class, MyCustomizer.class)); | ||
|
||
@Inject | ||
MyCustomizer customizer; | ||
|
||
@Test | ||
void test() { | ||
Assertions.assertThat(customizer.count()).isEqualTo(1); | ||
Assertions.assertThat(RestAssured.get("http://localhost:9998").body().asString()).isEqualTo("hello"); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyBean { | ||
|
||
public void init(@Observes Router router) { | ||
router.get().handler(rc -> rc.endAndForget("hello")); | ||
} | ||
|
||
} | ||
|
||
@ApplicationScoped | ||
public static class MyCustomizer implements HttpServerOptionsCustomizer { | ||
|
||
AtomicInteger count = new AtomicInteger(); | ||
|
||
@Override | ||
public void customizeHttpServer(HttpServerOptions options) { | ||
count.incrementAndGet(); | ||
options.setPort(9998); | ||
} | ||
|
||
@Override | ||
public void customizeHttpsServer(HttpServerOptions options) { | ||
count.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void customizeDomainSocketServer(HttpServerOptions options) { | ||
count.incrementAndGet(); | ||
} | ||
|
||
public int count() { | ||
return count.get(); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...s/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/HttpServerOptionsCustomizer.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,37 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import io.vertx.core.http.HttpServerOptions; | ||
|
||
/** | ||
* Interface exposed by beans willing to customizing the HTTP server options. | ||
* <p> | ||
* This interface is composed of three methods allowing the customization of the different servers: HTTP, HTTPS and | ||
* domain socket. | ||
* <p> | ||
* The passed {@link HttpServerOptions} must be customized in the body of the implementation. The default implementations | ||
* are no-op. | ||
*/ | ||
public interface HttpServerOptionsCustomizer { | ||
|
||
/** | ||
* Allows customizing the HTTP server options. | ||
*/ | ||
default void customizeHttpServer(HttpServerOptions options) { | ||
// NO-OP | ||
} | ||
|
||
/** | ||
* Allows customizing the HTTPS server options. | ||
*/ | ||
default void customizeHttpsServer(HttpServerOptions options) { | ||
// NO-OP | ||
} | ||
|
||
/** | ||
* Allows customizing the server listening on a domain socket if any. | ||
*/ | ||
default void customizeDomainSocketServer(HttpServerOptions options) { | ||
// NO-OP | ||
} | ||
|
||
} |
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