Top Description Inners Fields Constructors Methods
io.vertx.core.http.impl

public Class HttpServerImpl

extends TCPServerBase
implements HttpServer, Closeable, MetricsProvider
Class Inheritance
All Implemented Interfaces
io.vertx.core.spi.metrics.MetricsProvider, io.vertx.core.metrics.Measured, io.vertx.core.Closeable, io.vertx.core.http.HttpServer
Imports
io.netty.channel.Channel, io.netty.handler.traffic.GlobalTrafficShapingHandler, io.vertx.core.*, io.vertx.core.buffer.Buffer, io.vertx.core.http.*, io.vertx.core.impl.ContextInternal, .VertxInternal, io.vertx.core.impl.future.PromiseInternal, io.vertx.core.impl.logging.Logger, .LoggerFactory, io.vertx.core.net.SocketAddress, io.vertx.core.net.impl.*, io.vertx.core.spi.metrics.MetricsProvider, .TCPMetrics, .VertxMetrics, io.vertx.core.streams.ReadStream, java.util.function.BiConsumer, .Supplier, java.util.stream.Collectors

This class is thread-safe
Author
Tim Fox

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private Handler<HttpConnection>
private static final Handler<Throwable>
pack-priv static final boolean
private static final String
private Handler<Throwable>
private static final String
private Handler<HttpServerRequest>
pack-priv static final Logger
pack-priv final HttpServerOptions
private final HttpServerImpl.HttpStreamHandler<HttpServerRequest>
pack-priv static final boolean
pack-priv final boolean
private Handler<ServerWebSocketHandshake>
private final HttpServerImpl.HttpStreamHandler<ServerWebSocket>
Inherited from io.vertx.core.net.impl.TCPServerBase:
creatingContextvertx

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected BiConsumer<Channel, SslChannelProvider>
public Future<Void>
close()

Implements abstract io.vertx.core.net.impl.TCPServerBase.close.

Implements io.vertx.core.http.HttpServer.close.

Close the server.

public void
close(Handler<AsyncResult<Void>>
the handler
done
)

Implements io.vertx.core.http.HttpServer.close.

Like close but supplying a handler that will be called when the server is actually closed (or has failed).

public synchronized void
close(Promise<Void>
the promise to signal when close has completed
completion
)

Overrides io.vertx.core.net.impl.TCPServerBase.close.

Implements io.vertx.core.Closeable.close.

Close this resource, the completion promise must be notified when the operation has completed.

public synchronized HttpServer
connectionHandler(Handler<HttpConnection> handler)

Implements io.vertx.core.http.HttpServer.connectionHandler.

Set a connection handler for the server.

protected TCPMetrics<?>
protected SSLHelper
public synchronized HttpServer
exceptionHandler(Handler<Throwable>
the handler to set
handler
)

Implements io.vertx.core.http.HttpServer.exceptionHandler.

Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.

public HttpServer
invalidRequestHandler(Handler<HttpServerRequest> handler)

Implements io.vertx.core.http.HttpServer.invalidRequestHandler.

Set a handler for handling invalid requests.

public boolean
public Future<HttpServer>
listen()

Implements io.vertx.core.http.HttpServer.listen.

Tell the server to start listening.

public synchronized Future<HttpServer>
listen(SocketAddress address)

Implements io.vertx.core.http.HttpServer.listen.

Like listen(SocketAddress, Handler) but returns a Future of the asynchronous result

pack-priv boolean
public synchronized HttpServer
requestHandler(Handler<HttpServerRequest> handler)

Implements io.vertx.core.http.HttpServer.requestHandler.

Set the request handler for the server to requestHandler.

public Handler<HttpServerRequest>
public ReadStream<HttpServerRequest>
requestStream()

Implements io.vertx.core.http.HttpServer.requestStream.

Return the request stream for the server.

public HttpServer
webSocketHandler(Handler<ServerWebSocket> handler)

Implements io.vertx.core.http.HttpServer.webSocketHandler.

Set the WebSocket handler for the server to wsHandler.

public Handler<ServerWebSocket>
public HttpServer
public ReadStream<ServerWebSocket>
webSocketStream()

Implements io.vertx.core.http.HttpServer.webSocketStream.

Return the WebSocket stream for the server.

pack-priv boolean
Inherited from io.vertx.core.net.impl.TCPServerBase:
actualPortbindcreateTrafficShapingHandlergetMetricsisListeningisMetricsEnabledsniEntrySizesslContextProviderupdateSSLOptionsupdateTrafficShapingOptions

Field Detail

connectionHandlerback to summary
private Handler<HttpConnection> connectionHandler
DEFAULT_EXCEPTION_HANDLERback to summary
private static final Handler<Throwable> DEFAULT_EXCEPTION_HANDLER
DISABLE_WEBSOCKETSback to summary
pack-priv static final boolean DISABLE_WEBSOCKETS
DISABLE_WEBSOCKETS_PROP_NAMEback to summary
private static final String DISABLE_WEBSOCKETS_PROP_NAME
exceptionHandlerback to summary
private Handler<Throwable> exceptionHandler
FLASH_POLICY_HANDLER_PROP_NAMEback to summary
private static final String FLASH_POLICY_HANDLER_PROP_NAME
invalidRequestHandlerback to summary
private Handler<HttpServerRequest> invalidRequestHandler
logback to summary
pack-priv static final Logger log

Hides io.vertx.core.net.impl.TCPServerBase.log.

optionsback to summary
pack-priv final HttpServerOptions options

Hides io.vertx.core.net.impl.TCPServerBase.options.

requestStreamback to summary
private final HttpServerImpl.HttpStreamHandler<HttpServerRequest> requestStream
USE_FLASH_POLICY_HANDLERback to summary
pack-priv static final boolean USE_FLASH_POLICY_HANDLER
useH2UniformStreamByteDistributorback to summary
pack-priv final boolean useH2UniformStreamByteDistributor
webSocketHandshakeHandlerback to summary
private Handler<ServerWebSocketHandshake> webSocketHandshakeHandler
wsStreamback to summary
private final HttpServerImpl.HttpStreamHandler<ServerWebSocket> wsStream

Constructor Detail

HttpServerImplback to summary
public HttpServerImpl(VertxInternal vertx, HttpServerOptions options)

Method Detail

childHandlerback to summary
protected BiConsumer<Channel, SslChannelProvider> childHandler(ContextInternal context, SocketAddress address, GlobalTrafficShapingHandler trafficShapingHandler)

Implements abstract io.vertx.core.net.impl.TCPServerBase.childHandler.

Annotations
@Override
closeback to summary
public Future<Void> close()

Implements abstract io.vertx.core.net.impl.TCPServerBase.close.

Implements io.vertx.core.http.HttpServer.close.

Doc from io.vertx.core.http.HttpServer.close.

Close the server. Any open HTTP connections will be closed.

The close happens asynchronously and the server may not be closed until some time after the call has returned.

Returns:Future<Void>

a future completed with the result

Annotations
@Override
closeback to summary
public void close(Handler<AsyncResult<Void>> done)

Implements io.vertx.core.http.HttpServer.close.

Doc from io.vertx.core.http.HttpServer.close.

Like close but supplying a handler that will be called when the server is actually closed (or has failed).

Parameters
done:Handler<AsyncResult<Void>>

the handler

Annotations
@Override
closeback to summary
public synchronized void close(Promise<Void> completion)

Overrides io.vertx.core.net.impl.TCPServerBase.close.

Implements io.vertx.core.Closeable.close.

Doc from io.vertx.core.Closeable.close.

Close this resource, the completion promise must be notified when the operation has completed.

Parameters
completion:Promise<Void>

the promise to signal when close has completed

connectionHandlerback to summary
public synchronized HttpServer connectionHandler(Handler<HttpConnection> handler)

Implements io.vertx.core.http.HttpServer.connectionHandler.

Doc from io.vertx.core.http.HttpServer.connectionHandler.

Set a connection handler for the server.
The handler will always be called on the event-loop thread.

Returns:HttpServer

a reference to this, so the API can be used fluently

Annotations
@Override
createMetricsback to summary
protected TCPMetrics<?> createMetrics(SocketAddress localAddress)

Overrides io.vertx.core.net.impl.TCPServerBase.createMetrics.

Annotations
@Override
createSSLHelperback to summary
protected SSLHelper createSSLHelper()

Overrides io.vertx.core.net.impl.TCPServerBase.createSSLHelper.

Annotations
@Override
exceptionHandlerback to summary
public synchronized HttpServer exceptionHandler(Handler<Throwable> handler)

Implements io.vertx.core.http.HttpServer.exceptionHandler.

Doc from io.vertx.core.http.HttpServer.exceptionHandler.

Set an exception handler called for socket errors happening before the HTTP connection is established, e.g during the TLS handshake.

Parameters
handler:Handler<Throwable>

the handler to set

Returns:HttpServer

a reference to this, so the API can be used fluently

Annotations
@Override
invalidRequestHandlerback to summary
public HttpServer invalidRequestHandler(Handler<HttpServerRequest> handler)

Implements io.vertx.core.http.HttpServer.invalidRequestHandler.

Doc from io.vertx.core.http.HttpServer.invalidRequestHandler.

Set a handler for handling invalid requests. When an invalid request is received by the server this handler will be called with the request. The handler can send any HTTP response, when the response ends, the server shall close the connection. HttpServerRequest#decoderResult() can be used to obtain the Netty decoder result and the failure cause reported by the decoder.

Currently this handler is only used for HTTP/1.x requests.

When no specific handler is set, the HttpServerRequest#DEFAULT_INVALID_REQUEST_HANDLER is used.

Returns:HttpServer

a reference to this, so the API can be used fluently

Annotations
@Override
isClosedback to summary
public boolean isClosed()
listenback to summary
public Future<HttpServer> listen()

Implements io.vertx.core.http.HttpServer.listen.

Doc from io.vertx.core.http.HttpServer.listen.

Tell the server to start listening. The server will listen on the port and host specified in the io.vertx.core.http.HttpServerOptions that was used when creating the server.

The listen happens asynchronously and the server may not be listening until some time after the call has returned.

Returns:Future<HttpServer>

a future completed with the listen operation result

Annotations
@Override
listenback to summary
public synchronized Future<HttpServer> listen(SocketAddress address)

Implements io.vertx.core.http.HttpServer.listen.

Doc from io.vertx.core.http.HttpServer.listen.

Like listen(SocketAddress, Handler) but returns a Future of the asynchronous result

Annotations
@Override
requestAcceptback to summary
pack-priv boolean requestAccept()
requestHandlerback to summary
public synchronized HttpServer requestHandler(Handler<HttpServerRequest> handler)

Implements io.vertx.core.http.HttpServer.requestHandler.

Doc from io.vertx.core.http.HttpServer.requestHandler.

Set the request handler for the server to requestHandler. As HTTP requests are received by the server, instances of HttpServerRequest will be created and passed to this handler.

Returns:HttpServer

a reference to this, so the API can be used fluently

Annotations
@Override
requestHandlerback to summary
public Handler<HttpServerRequest> requestHandler()

Implements io.vertx.core.http.HttpServer.requestHandler.

Returns:Handler<HttpServerRequest>

Doc from io.vertx.core.http.HttpServer.requestHandler.

the request handler

Annotations
@Override
requestStreamback to summary
public ReadStream<HttpServerRequest> requestStream()

Implements io.vertx.core.http.HttpServer.requestStream.

Doc from io.vertx.core.http.HttpServer.requestStream.

Return the request stream for the server. As HTTP requests are received by the server, instances of HttpServerRequest will be created and passed to the stream io.vertx.core.streams.ReadStream#handler(io.vertx.core.Handler).

Returns:ReadStream<HttpServerRequest>

the request stream

Annotations
@Override
webSocketHandlerback to summary
public HttpServer webSocketHandler(Handler<ServerWebSocket> handler)

Implements io.vertx.core.http.HttpServer.webSocketHandler.

Doc from io.vertx.core.http.HttpServer.webSocketHandler.

Set the WebSocket handler for the server to wsHandler. If a WebSocket connect handshake is successful a new ServerWebSocket instance will be created and passed to the handler.

Returns:HttpServer

a reference to this, so the API can be used fluently

Annotations
@Override
webSocketHandlerback to summary
public Handler<ServerWebSocket> webSocketHandler()

Implements io.vertx.core.http.HttpServer.webSocketHandler.

Returns:Handler<ServerWebSocket>

Doc from io.vertx.core.http.HttpServer.webSocketHandler.

the WebSocket handler

Annotations
@Override
webSocketHandshakeHandlerback to summary
public HttpServer webSocketHandshakeHandler(Handler<ServerWebSocketHandshake> handler)

Implements io.vertx.core.http.HttpServer.webSocketHandshakeHandler.

Doc from io.vertx.core.http.HttpServer.webSocketHandshakeHandler.

Set a handler for WebSocket handshake.

When an inbound HTTP request presents a WebSocket upgrade, this handler is called first. The handler can chose to ServerWebSocketHandshake#accept() or ServerWebSocketHandshake#reject() the request.

Setting no handler, implicitly accepts any HTTP request connection presenting an upgrade header and upgrades it to a WebSocket.

Annotations
@Override
webSocketStreamback to summary
public ReadStream<ServerWebSocket> webSocketStream()

Implements io.vertx.core.http.HttpServer.webSocketStream.

Doc from io.vertx.core.http.HttpServer.webSocketStream.

Return the WebSocket stream for the server. If a WebSocket connect handshake is successful a new ServerWebSocket instance will be created and passed to the stream io.vertx.core.streams.ReadStream#handler(io.vertx.core.Handler).

Returns:ReadStream<ServerWebSocket>

the WebSocket stream

Annotations
@Override
wsAcceptback to summary
pack-priv boolean wsAccept()
io.vertx.core.http.impl back to summary

pack-priv Class HttpServerImpl.HttpStreamHandler<C extends ReadStream<Buffer>>

extends Object
implements ReadStream<C extends ReadStream<Buffer>>
Class Inheritance
All Implemented Interfaces
io.vertx.core.streams.ReadStream, io.vertx.core.streams.StreamBase

Field Summary

Modifier and TypeField and Description
private long
private Handler<Void>
private Handler<C>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv Handler<Void>
public ReadStream<T>
endHandler(Handler<Void> endHandler)

public ReadStream<T>
public ReadStream<T>
fetch(long amount)

Implements io.vertx.core.streams.ReadStream.fetch.

Fetch the specified amount of elements.

pack-priv Handler<C>
public ReadStream<T>
handler(Handler<C> handler)

public ReadStream<T>
pause()

Implements io.vertx.core.streams.ReadStream.pause.

Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

public ReadStream<T>
resume()

Implements io.vertx.core.streams.ReadStream.resume.

Resume reading, and sets the buffer in flowing mode.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

demandback to summary
private long demand
endHandlerback to summary
private Handler<Void> endHandler
handlerback to summary
private Handler<C> handler

Constructor Detail

HttpStreamHandlerback to summary
pack-priv HttpStreamHandler()

Method Detail

acceptback to summary
pack-priv boolean accept()
endHandlerback to summary
pack-priv Handler<Void> endHandler()
endHandlerback to summary
public ReadStream<T> endHandler(Handler<Void> endHandler)
Annotations
@Override
exceptionHandlerback to summary
public ReadStream<T> exceptionHandler(Handler<Throwable> handler)
Annotations
@Override
fetchback to summary
public ReadStream<T> fetch(long amount)

Implements io.vertx.core.streams.ReadStream.fetch.

Doc from io.vertx.core.streams.ReadStream.fetch.

Fetch the specified amount of elements. If the ReadStream has been paused, reading will recommence with the specified amount of items, otherwise the specified amount will be added to the current stream demand.

Returns:ReadStream<T>

a reference to this, so the API can be used fluently

Annotations
@Override
handlerback to summary
pack-priv Handler<C> handler()
handlerback to summary
public ReadStream<T> handler(Handler<C> handler)
Annotations
@Override
pauseback to summary
public ReadStream<T> pause()

Implements io.vertx.core.streams.ReadStream.pause.

Doc from io.vertx.core.streams.ReadStream.pause.

Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

While it's paused, no data will be sent to the data handler.

Returns:ReadStream<T>

a reference to this, so the API can be used fluently

Annotations
@Override
resumeback to summary
public ReadStream<T> resume()

Implements io.vertx.core.streams.ReadStream.resume.

Doc from io.vertx.core.streams.ReadStream.resume.

Resume reading, and sets the buffer in flowing mode.

If the ReadStream has been paused, reading will recommence on it.

Returns:ReadStream<T>

a reference to this, so the API can be used fluently

Annotations
@Override