Package ej.hoka.http
Class HttpServer.HttpServerBuilder
- java.lang.Object
-
- ej.hoka.http.HttpServer.HttpServerBuilder
-
- Enclosing class:
- HttpServer
public static class HttpServer.HttpServerBuilder extends java.lang.ObjectHttpServer.HttpServerBuilderbuilder.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpServer.HttpServerBuilderapiBase(java.lang.String apiBase)Add a path common base that will be appended to all routes mapped without starting with a forward slash '/'.HttpServerbuild()Builds and returns an instance ofHttpServerwith the configured parameters.HttpServer.HttpServerBuilderconnectionTimeout(int connectionTimeout)By default, server is configured to keep connection open during one minute if possible.HttpServer.HttpServerBuilderdevelopmentMode()Activate development mode.HttpServer.HttpServerBuilderencodingRegistry(EncodingRegistry encodingRegistry)If this method is not called an instance ofEncodingRegistryis used by the server.HttpServer.HttpServerBuilderport(int port)Set the server port number.HttpServer.HttpServerBuildersecure(javax.net.ServerSocketFactory ssf)Set Server Socket Factory.HttpServer.HttpServerBuildersimultaneousConnections(int simultaneousConnections)Set the max simultaneous connections.HttpServer.HttpServerBuilderstaticFilesHandler(StaticFilesHandler handler)Set the static files handler to serve static files.HttpServer.HttpServerBuilderwithStrictAcceptContentEncoding()RFC2616 14.3 Activate strict content encoding acceptance.HttpServer.HttpServerBuilderwithTrailingSlashSupport()Activate trailing slash matching support in URI.HttpServer.HttpServerBuilderworkerCount(int workerCount)Set threads count that handles incoming request.
-
-
-
Method Detail
-
port
public HttpServer.HttpServerBuilder port(int port)
Set the server port number.- Parameters:
port- server port. use 0 set setup a random available port.- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters- Throws:
java.lang.IllegalArgumentException- if port is< 0
-
simultaneousConnections
public HttpServer.HttpServerBuilder simultaneousConnections(int simultaneousConnections)
Set the max simultaneous connections.- Parameters:
simultaneousConnections- max simultaneous connections that can be handled by the server.- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters- Throws:
java.lang.IllegalArgumentException- - if simultaneousConnections is<= 0;
-
workerCount
public HttpServer.HttpServerBuilder workerCount(int workerCount)
Set threads count that handles incoming request.- Parameters:
workerCount- number of threads to handle incoming requests- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters- Throws:
java.lang.IllegalArgumentException- - if workerCount is<= 0;
-
apiBase
public HttpServer.HttpServerBuilder apiBase(@Nullable java.lang.String apiBase)
Add a path common base that will be appended to all routes mapped without starting with a forward slash '/'. This is useful when dealing with rest API to set the rest api URI base once. The base should start with a '/' and also ends with a '/'.- Parameters:
apiBase- the api base path- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters- Throws:
java.lang.IllegalArgumentException- if apiBase is null or empty
-
secure
public HttpServer.HttpServerBuilder secure(@Nullable javax.net.ServerSocketFactory ssf)
Set Server Socket Factory. this used to set ssl- Parameters:
ssf- Server socket factory to setup HTTPS- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters- Throws:
java.lang.IllegalArgumentException- if ServerSocketFactory parameter is null
-
connectionTimeout
public HttpServer.HttpServerBuilder connectionTimeout(int connectionTimeout)
By default, server is configured to keep connection open during one minute if possible. A timeout of zero is interpreted as an infinite timeout.- Parameters:
connectionTimeout- the timeout duration.- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters- Throws:
java.lang.IllegalArgumentException- if connectionTimeout< 0
-
encodingRegistry
public HttpServer.HttpServerBuilder encodingRegistry(@Nullable EncodingRegistry encodingRegistry)
If this method is not called an instance ofEncodingRegistryis used by the server.- Parameters:
encodingRegistry- the registry of available encoding handlers.- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters- Throws:
java.lang.IllegalArgumentException- if encodingRegistry is null
-
withStrictAcceptContentEncoding
public HttpServer.HttpServerBuilder withStrictAcceptContentEncoding()
RFC2616 14.3 Activate strict content encoding acceptance. The server will returns a 406 (Not Acceptable) for every request with a header Accept-Encoding with no encoding supported by the server. Register custom content encoding usingEncodingRegistry.registerContentEncoding(ContentEncoding)- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters
-
withTrailingSlashSupport
public HttpServer.HttpServerBuilder withTrailingSlashSupport()
Activate trailing slash matching support in URI. When used URI '/hello' and '/hello/' will point to different request handler otherwise URI '/hello' and '/hello/' are the same- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters
-
staticFilesHandler
public HttpServer.HttpServerBuilder staticFilesHandler(@Nullable StaticFilesHandler handler)
Set the static files handler to serve static files. Use this only for public resources.- Parameters:
handler- theStaticFilesHandlerinstance- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters- Throws:
java.lang.IllegalArgumentException- if the handler is null
-
developmentMode
public HttpServer.HttpServerBuilder developmentMode()
Activate development mode. The server will send stack trace of thrown exceptions to the clients.- Returns:
HttpServer.HttpServerBuilderto continue setting up the server parameters
-
build
public HttpServer build()
Builds and returns an instance ofHttpServerwith the configured parameters.- Returns:
- an instance of
HttpServerwith the configured parameters.
-
-