Package com.hexagonkt.http.server
Class HttpServer
-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public final class HttpServer implements CloseableServer that listen to HTTP connections on a port and address and route requests to handlers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classHttpServer.Companion
-
Field Summary
Fields Modifier and Type Field Description private final IntegerruntimePortprivate final URLbindingprivate final StringportNameprivate final HttpHandlerhandlerprivate final HttpServerSettingssettingspublic final static HttpServer.CompanionCompanion
-
Constructor Summary
Constructors Constructor Description HttpServer(HttpServerPort adapter, HttpServerSettings settings, Function1<HandlerBuilder, Unit> block)Create a server with a builder (HandlerBuilder) to set up handlers. HttpServer(HttpServerPort adapter, HttpHandler handler, HttpServerSettings settings)
-
Method Summary
Modifier and Type Method Description final IntegergetRuntimePort()final URLgetBinding()final StringgetPortName()The port name of the server. final HttpHandlergetHandler()final HttpServerSettingsgetSettings()Unitclose()final Booleanstarted()Check whether the server has been started. final Unitstart()Start the server with the adapter instance and adds a shutdown hook for stopping the server. final Unitstop()Stop the server. -
-
Constructor Detail
-
HttpServer
HttpServer(HttpServerPort adapter, HttpServerSettings settings, Function1<HandlerBuilder, Unit> block)
Create a server with a builder (HandlerBuilder) to set up handlers.- Parameters:
adapter- The server engine.settings- Server settings.block- Handlers' setup block.
-
HttpServer
HttpServer(HttpServerPort adapter, HttpHandler handler, HttpServerSettings settings)
-
-
Method Detail
-
getRuntimePort
final Integer getRuntimePort()
-
getBinding
final URL getBinding()
-
getPortName
final String getPortName()
The port name of the server.
-
getHandler
final HttpHandler getHandler()
-
getSettings
final HttpServerSettings getSettings()
-
close
Unit close()
-
started
final Boolean started()
Check whether the server has been started.
- Returns:
True if the server has started, else false.
-
start
final Unit start()
Start the server with the adapter instance and adds a shutdown hook for stopping the server.
-
stop
final Unit stop()
Stop the server.
-
-
-
-