public final class HttpServer extends java.lang.Object implements NettyConnector<HttpServerRequest,HttpServerResponse>
| Modifier and Type | Class and Description |
|---|---|
static class |
HttpServer.Builder |
| Modifier and Type | Method and Description |
|---|---|
static HttpServer.Builder |
builder()
Creates a builder for
HttpServer |
static HttpServer |
create()
Build a simple Netty HTTP server listening on localhost (127.0.0.1) and
port 8080.
|
static HttpServer |
create(java.util.function.Consumer<? super HttpServerOptions.Builder> options)
Build a simple Netty HTTP server listening over bind address and port passed
through the
HttpServerOptions. |
static HttpServer |
create(int port)
Build a simple Netty HTTP server listening on localhost (127.0.0.1) and the provided
port
Use 0 to let the system assign a random port.
|
static HttpServer |
create(java.lang.String bindAddress)
Build a simple Netty HTTP server listening on the provided bind address and
port 8080.
|
static HttpServer |
create(java.lang.String bindAddress,
int port)
Build a simple Netty HTTP server listening on the provided bind address and port.
|
Mono<? extends NettyContext> |
newHandler(java.util.function.BiFunction<? super HttpServerRequest,? super HttpServerResponse,? extends Publisher<java.lang.Void>> handler)
Prepare a
BiFunction IO handler that will react on a new connected state
each
time
the returned Mono is subscribed. |
Mono<? extends NettyContext> |
newRouter(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder)
Define routes for the server through the provided
HttpServerRoutes builder. |
HttpServerOptions |
options()
Get a copy of the
HttpServerOptions currently in effect. |
BlockingNettyContext |
startRouter(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder)
Start an HttpServer with routes defined through the provided
HttpServerRoutes
builder, in a blocking fashion, and wait for it to finish initializing. |
void |
startRouterAndAwait(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder)
Start an HttpServer with routes defined through the provided
HttpServerRoutes
builder, in a fully blocking fashion, not only waiting for it to
initialize but also blocking during the full lifecycle of the server. |
void |
startRouterAndAwait(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder,
java.util.function.Consumer<BlockingNettyContext> onStart)
Start an HttpServer with routes defined through the provided
HttpServerRoutes
builder, in a fully blocking fashion, not only waiting for it to
initialize but also blocking during the full lifecycle of the server. |
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitstart, start, startAndAwait, startAndAwaitpublic static HttpServer create()
public static HttpServer create(java.util.function.Consumer<? super HttpServerOptions.Builder> options)
HttpServerOptions.
Use 0 to let the system assign a random port.options - the options for the server, including bind address and port.public static HttpServer create(int port)
port - the port to listen to, or 0 to dynamically attribute one.public static HttpServer create(java.lang.String bindAddress)
bindAddress - address to listen for (e.g. 0.0.0.0 or 127.0.0.1)public static HttpServer create(java.lang.String bindAddress, int port)
bindAddress - address to listen for (e.g. 0.0.0.0 or 127.0.0.1)port - the port to listen to, or 0 to dynamically attribute one.public static HttpServer.Builder builder()
HttpServerpublic final HttpServerOptions options()
HttpServerOptions currently in effect.public java.lang.String toString()
toString in class java.lang.Objectpublic Mono<? extends NettyContext> newHandler(java.util.function.BiFunction<? super HttpServerRequest,? super HttpServerResponse,? extends Publisher<java.lang.Void>> handler)
NettyConnectorBiFunction IO handler that will react on a new connected state
each
time
the returned Mono is subscribed. This NettyConnector shouldn't assume
any state related to the individual created/cleaned resources.
The IO handler will return Publisher to signal when to terminate the
underlying resource channel.
newHandler in interface NettyConnector<HttpServerRequest,HttpServerResponse>handler - the in/out callback returning a closing publisherMono completing with a Disposable token to dispose
the active handler (server, client connection...) or failing with the connection
error.public Mono<? extends NettyContext> newRouter(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder)
HttpServerRoutes builder.routesBuilder - provides a route builder to be mutated in order to define routes.Mono starting the router on subscribepublic BlockingNettyContext startRouter(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder)
HttpServerRoutes
builder, in a blocking fashion, and wait for it to finish initializing.
The returned BlockingNettyContext class offers a simplified API around operating
the client/server in a blocking fashion, including to shut it down.routesBuilder - provides a route builder to be mutated in order to define routes.BlockingNettyContextpublic void startRouterAndAwait(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder)
HttpServerRoutes
builder, in a fully blocking fashion, not only waiting for it to
initialize but also blocking during the full lifecycle of the server.
Since most servers will be long-lived, this is more adapted to running a server
out of a main method, only allowing shutdown of the servers through sigkill.
Note that a JVM shutdown hook is added
by this method in order to properly disconnect the client/server upon receiving
a sigkill signal.
routesBuilder - provides a route builder to be mutated in order to define routes.public void startRouterAndAwait(java.util.function.Consumer<? super HttpServerRoutes> routesBuilder, java.util.function.Consumer<BlockingNettyContext> onStart)
HttpServerRoutes
builder, in a fully blocking fashion, not only waiting for it to
initialize but also blocking during the full lifecycle of the server.
Since most servers will be long-lived, this is more adapted to running a server
out of a main method, only allowing shutdown of the servers through sigkill.
Note that a JVM shutdown hook is added
by this method in order to properly disconnect the client/server upon receiving
a sigkill signal.
routesBuilder - provides a route builder to be mutated in order to define routes.onStart - an optional callback to be invoked once the server has finished initializing.