org.webbitserver.netty
Class NettyWebServer

java.lang.Object
  extended by org.webbitserver.netty.NettyWebServer
All Implemented Interfaces:
Endpoint<WebServer>, WebServer

public class NettyWebServer
extends Object
implements WebServer


Field Summary
protected  long nextId
           
 
Constructor Summary
NettyWebServer(Executor executor, int port)
           
NettyWebServer(Executor executor, SocketAddress socketAddress, URI publicUri)
           
NettyWebServer(int port)
           
 
Method Summary
 NettyWebServer add(HttpHandler handler)
          Add an HttpHandler.
 NettyWebServer add(String path, EventSourceHandler handler)
          Add a WebSocketHandler for dealing with WebSockets.
 NettyWebServer add(String path, HttpHandler handler)
          Add an HttpHandler that will only respond to a certain path (e.g "/some/page").
 NettyWebServer add(String path, WebSocketHandler handler)
          Add a WebSocketHandler for dealing with WebSockets.
 NettyWebServer connectionExceptionHandler(Thread.UncaughtExceptionHandler ioExceptionHandler)
          What to do when an exception occurs when attempting to read/write data from/to the underlying connection.
 Executor getExecutor()
          Get main work executor that all handlers will execute on.
 int getPort()
          Get base port that webserver is serving on.
 URI getUri()
          Get base URI that endpoint is serving on (or connected to).
 boolean isRunning()
           
 NettyWebServer maxChunkSize(int maxChunkSize)
           
 NettyWebServer maxContentLength(int maxContentLength)
           
 NettyWebServer maxHeaderSize(int maxHeaderSize)
           
 NettyWebServer maxInitialLineLength(int maxInitialLineLength)
           
protected  Object nextId()
           
protected  void setupDefaultHandlers()
           
 NettyWebServer setupSsl(InputStream keyStore, String pass)
          Setup SSL/TLS handler

This is shortcut for setupSsl(keyStore, pass, pass).

 NettyWebServer setupSsl(InputStream keyStore, String storePass, String keyPass)
          Setup SSL/TLS handler
 NettyWebServer staleConnectionTimeout(long millis)
          Number of milliseconds before a stale HTTP keep-alive connection is closed by the server.
 Future<NettyWebServer> start()
          Start in background.
 Future<WebServer> stop()
          Stop in background.
protected  long timestamp()
           
 NettyWebServer uncaughtExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler)
          What to do when an exception gets thrown in a handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nextId

protected long nextId
Constructor Detail

NettyWebServer

public NettyWebServer(int port)

NettyWebServer

public NettyWebServer(Executor executor,
                      int port)

NettyWebServer

public NettyWebServer(Executor executor,
                      SocketAddress socketAddress,
                      URI publicUri)
Method Detail

setupDefaultHandlers

protected void setupDefaultHandlers()

setupSsl

public NettyWebServer setupSsl(InputStream keyStore,
                               String pass)
                        throws WebbitException
Description copied from interface: Endpoint
Setup SSL/TLS handler

This is shortcut for setupSsl(keyStore, pass, pass).

Specified by:
setupSsl in interface Endpoint<WebServer>
Parameters:
keyStore - Keystore InputStream
pass - Store and key password
Returns:
current WebServer instance
Throws:
WebbitException - A problem loading the keystore
See Also:
#setupSsl(String, String, String)

setupSsl

public NettyWebServer setupSsl(InputStream keyStore,
                               String storePass,
                               String keyPass)
                        throws WebbitException
Description copied from interface: WebServer
Setup SSL/TLS handler

Specified by:
setupSsl in interface WebServer
Parameters:
keyStore - Keystore InputStream
storePass - Store password
keyPass - Key password
Returns:
current WebServer instance
Throws:
WebbitException - A problem loading the keystore

getUri

public URI getUri()
Description copied from interface: Endpoint
Get base URI that endpoint is serving on (or connected to).

Specified by:
getUri in interface Endpoint<WebServer>

getPort

public int getPort()
Description copied from interface: WebServer
Get base port that webserver is serving on.

Specified by:
getPort in interface WebServer

getExecutor

public Executor getExecutor()
Description copied from interface: Endpoint
Get main work executor that all handlers will execute on.

Specified by:
getExecutor in interface Endpoint<WebServer>

staleConnectionTimeout

public NettyWebServer staleConnectionTimeout(long millis)
Description copied from interface: WebServer
Number of milliseconds before a stale HTTP keep-alive connection is closed by the server. A HTTP connection is considered stale if it remains open without sending more data within the timeout window.

Specified by:
staleConnectionTimeout in interface WebServer

add

public NettyWebServer add(HttpHandler handler)
Description copied from interface: WebServer
Add an HttpHandler. When a request comes in the first HttpHandler will be invoked. The HttpHandler should either handle the request, or pass the request onto the next HttpHandler (using HttpControl.nextHandler()). This is repeated until a HttpHandler returns a response. If there are no remaining handlers, the webserver shall return 404 NOT FOUND to the browser.

HttpHandlers are attempted in the order in which they are added to the WebServer.

Specified by:
add in interface WebServer
See Also:
HttpHandler

add

public NettyWebServer add(String path,
                          HttpHandler handler)
Description copied from interface: WebServer
Add an HttpHandler that will only respond to a certain path (e.g "/some/page").

This is shortcut for add(newPathMatchHandler(path, handler)).

Specified by:
add in interface WebServer
See Also:
HttpHandler, WebServer.add(HttpHandler), PathMatchHandler

add

public NettyWebServer add(String path,
                          WebSocketHandler handler)
Description copied from interface: WebServer
Add a WebSocketHandler for dealing with WebSockets.

This is shortcut for add(new PathMatchHandler(path, newHttpToWebSocketHandler(handler))).

Specified by:
add in interface WebServer
See Also:
WebSocketHandler, HttpHandler, WebServer.add(HttpHandler), HttpToWebSocketHandler, PathMatchHandler

add

public NettyWebServer add(String path,
                          EventSourceHandler handler)
Description copied from interface: WebServer
Add a WebSocketHandler for dealing with WebSockets.

This is shortcut for add(new PathMatchHandler(path, newHttpToEventSourceHandler(handler))).

Specified by:
add in interface WebServer
See Also:
HttpHandler, WebServer.add(HttpHandler), HttpToEventSourceHandler, PathMatchHandler

start

public Future<NettyWebServer> start()
Description copied from interface: Endpoint
Start in background. This returns immediately, but the endpoint may still not be ready to accept incoming requests (or have established a connection - if this is a client). To wait until it's fully started, call Future.get() on the returned future.

Specified by:
start in interface Endpoint<WebServer>

isRunning

public boolean isRunning()

stop

public Future<WebServer> stop()
Description copied from interface: Endpoint
Stop in background. This returns immediately, but the endpoint may still be shutting down. To wait until it's fully stopped, call Future.get() on the returned future.

Specified by:
stop in interface Endpoint<WebServer>

uncaughtExceptionHandler

public NettyWebServer uncaughtExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler)
Description copied from interface: Endpoint
What to do when an exception gets thrown in a handler.

Defaults to using PrintStackTraceExceptionHandler. It is suggested that apps supply their own implementation (e.g. to log somewhere).

Specified by:
uncaughtExceptionHandler in interface Endpoint<WebServer>

connectionExceptionHandler

public NettyWebServer connectionExceptionHandler(Thread.UncaughtExceptionHandler ioExceptionHandler)
Description copied from interface: Endpoint
What to do when an exception occurs when attempting to read/write data from/to the underlying connection. e.g. If an HTTP request disconnects before it was expected.

Defaults to using SilentExceptionHandler as this is a common thing to happen on a network, and most systems should not care.

Specified by:
connectionExceptionHandler in interface Endpoint<WebServer>

maxChunkSize

public NettyWebServer maxChunkSize(int maxChunkSize)
See Also:
HttpRequestDecoder

maxContentLength

public NettyWebServer maxContentLength(int maxContentLength)
See Also:
HttpChunkAggregator

maxHeaderSize

public NettyWebServer maxHeaderSize(int maxHeaderSize)
See Also:
HttpRequestDecoder

maxInitialLineLength

public NettyWebServer maxInitialLineLength(int maxInitialLineLength)
See Also:
HttpRequestDecoder

timestamp

protected long timestamp()

nextId

protected Object nextId()


Copyright © 2013. All Rights Reserved.