Class HttpServer

java.lang.Object
io.vertx.reactivex.core.http.HttpServer
All Implemented Interfaces:
io.vertx.lang.rx.RxDelegate, Measured

public class HttpServer extends Object implements io.vertx.lang.rx.RxDelegate, Measured
An HTTP and WebSockets server.

You receive HTTP requests by providing a requestHandler(Handler). As requests arrive on the server the handler will be called with the requests.

You receive WebSockets by providing a webSocketHandler(Handler). As WebSocket connections arrive on the server, the WebSocket is passed to the handler.

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.

  • Field Details

    • __TYPE_ARG

      public static final io.vertx.lang.rx.TypeArg<HttpServer> __TYPE_ARG
  • Constructor Details

    • HttpServer

      public HttpServer(HttpServer delegate)
    • HttpServer

      public HttpServer(Object delegate)
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getDelegate

      public HttpServer getDelegate()
      Specified by:
      getDelegate in interface Measured
      Specified by:
      getDelegate in interface io.vertx.lang.rx.RxDelegate
    • isMetricsEnabled

      public boolean isMetricsEnabled()
      Whether the metrics are enabled for this measured object
      Specified by:
      isMetricsEnabled in interface Measured
      Returns:
      true if metrics are enabled
    • requestHandler

      public HttpServer requestHandler(Handler<HttpServerRequest> handler)
      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.
      Parameters:
      handler -
      Returns:
      a reference to this, so the API can be used fluently
    • invalidRequestHandler

      public HttpServer invalidRequestHandler(Handler<HttpServerRequest> handler)
      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.
      invalid reference
      io.vertx.reactivex.core.http.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 is used.

      Parameters:
      handler -
      Returns:
      a reference to this, so the API can be used fluently
    • connectionHandler

      public HttpServer connectionHandler(Handler<HttpConnection> handler)
      Set a connection handler for the server.
      The handler will always be called on the event-loop thread.
      Parameters:
      handler -
      Returns:
      a reference to this, so the API can be used fluently
    • webSocketHandshakeHandler

      public HttpServer webSocketHandshakeHandler(Handler<ServerWebSocketHandshake> handler)
      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.

      Parameters:
      handler -
      Returns:
    • exceptionHandler

      public HttpServer exceptionHandler(Handler<Throwable> handler)
      Set an exception handler called for socket errors happening before the HTTP connection is established, e.g. during the TLS handshake.
      Parameters:
      handler - the handler to set
      Returns:
      a reference to this, so the API can be used fluently
    • webSocketHandler

      public HttpServer webSocketHandler(Handler<ServerWebSocket> handler)
      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.
      Parameters:
      handler -
      Returns:
      a reference to this, so the API can be used fluently
    • updateSSLOptions

      public Future<Boolean> updateSSLOptions(ServerSSLOptions options)
      Update the server with new SSL options, the update happens if the options object is valid and different from the existing options object.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new SSL options
      Returns:
      a future signaling the update success
    • rxUpdateSSLOptions

      public Single<Boolean> rxUpdateSSLOptions(ServerSSLOptions options)
      Update the server with new SSL options, the update happens if the options object is valid and different from the existing options object.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new SSL options
      Returns:
      a future signaling the update success
    • updateSSLOptions

      public Future<Boolean> updateSSLOptions(ServerSSLOptions options, boolean force)

      Update the server with new SSL options, the update happens if the options object is valid and different from the existing options object.

      The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new SSL options
      force - force the update when options are equals
      Returns:
      a future signaling the update success
    • rxUpdateSSLOptions

      public Single<Boolean> rxUpdateSSLOptions(ServerSSLOptions options, boolean force)

      Update the server with new SSL options, the update happens if the options object is valid and different from the existing options object.

      The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new SSL options
      force - force the update when options are equals
      Returns:
      a future signaling the update success
    • updateTrafficShapingOptions

      public Future<Boolean> updateTrafficShapingOptions(TrafficShapingOptions options)

      Update the server with new traffic options, the update happens if the options object is valid and different from the existing options object.

      The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new traffic shaping options
      Returns:
      a future signaling the update success
    • rxUpdateTrafficShapingOptions

      public Single<Boolean> rxUpdateTrafficShapingOptions(TrafficShapingOptions options)

      Update the server with new traffic options, the update happens if the options object is valid and different from the existing options object.

      The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new traffic shaping options
      Returns:
      a future signaling the update success
    • listen

      public Future<HttpServer> listen()
      Tell the server to start listening. The server will listen on the port and host specified in the 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:
      a future completed with the listen operation result
    • rxListen

      public Single<HttpServer> rxListen()
      Tell the server to start listening. The server will listen on the port and host specified in the 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:
      a future completed with the listen operation result
    • listen

      public Future<HttpServer> listen(int port, String host)
      Tell the server to start listening. The server will listen on the port and host specified here, ignoring any value set in the 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.

      Parameters:
      port - the port to listen on
      host - the host to listen on
      Returns:
      a future completed with the listen operation result
    • rxListen

      public Single<HttpServer> rxListen(int port, String host)
      Tell the server to start listening. The server will listen on the port and host specified here, ignoring any value set in the 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.

      Parameters:
      port - the port to listen on
      host - the host to listen on
      Returns:
      a future completed with the listen operation result
    • listen

      public Future<HttpServer> listen(SocketAddress address)
      Tell the server to start listening on the given address supplying a handler that will be called when the server is actually listening (or has failed).
      Parameters:
      address - the address to listen on
      Returns:
      a future completed with the listen operation result
    • rxListen

      public Single<HttpServer> rxListen(SocketAddress address)
      Tell the server to start listening on the given address supplying a handler that will be called when the server is actually listening (or has failed).
      Parameters:
      address - the address to listen on
      Returns:
      a future completed with the listen operation result
    • listen

      public Future<HttpServer> listen(int port)
      Like listen() but the server will listen on host "0.0.0.0" and port specified here ignoring any value in the HttpServerOptions that was used when creating the server.
      Parameters:
      port - the port to listen on
      Returns:
      a future completed with the listen operation result
    • rxListen

      public Single<HttpServer> rxListen(int port)
      Like listen() but the server will listen on host "0.0.0.0" and port specified here ignoring any value in the HttpServerOptions that was used when creating the server.
      Parameters:
      port - the port to listen on
      Returns:
      a future completed with the listen operation result
    • close

      public Future<Void> 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:
      a future completed with the result
    • rxClose

      public Completable rxClose()
      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:
      a future completed with the result
    • shutdown

      public Future<Void> shutdown()
      Shutdown with a 30 seconds timeout (shutdown(Duration.ofSeconds(30))).
      Returns:
      a future completed when shutdown has completed
    • rxShutdown

      public Completable rxShutdown()
      Shutdown with a 30 seconds timeout (shutdown(Duration.ofSeconds(30))).
      Returns:
      a future completed when shutdown has completed
    • shutdown

      public Future<Void> shutdown(long timeout, TimeUnit unit)
      Calls shutdown().
      Parameters:
      timeout -
      unit -
      Returns:
    • rxShutdown

      public Completable rxShutdown(long timeout, TimeUnit unit)
      Calls shutdown().
      Parameters:
      timeout -
      unit -
      Returns:
    • actualPort

      public int actualPort()
      The actual port the server is listening on. This is useful if you bound the server specifying 0 as port number signifying an ephemeral port
      Returns:
      the actual port the server is listening on.
    • shutdown

      public Future<Void> shutdown(Duration timeout)
      Initiate the server shutdown sequence.

      Connections are taken out of service and closed when all inflight requests are processed. When all connections are closed the server is closed. When the timeout expires, all unclosed connections are immediately closed.

      • HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
      • HTTP/1.x server connection will be closed after the current response is sent
      Parameters:
      timeout - the amount of time after which all resources are forcibly closed
      Returns:
      a future notified when the client is closed
    • rxShutdown

      public Completable rxShutdown(Duration timeout)
      Initiate the server shutdown sequence.

      Connections are taken out of service and closed when all inflight requests are processed. When all connections are closed the server is closed. When the timeout expires, all unclosed connections are immediately closed.

      • HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
      • HTTP/1.x server connection will be closed after the current response is sent
      Parameters:
      timeout - the amount of time after which all resources are forcibly closed
      Returns:
      a future notified when the client is closed
    • newInstance

      public static HttpServer newInstance(HttpServer arg)