Interface HttpServer

All Superinterfaces:
org.mule.runtime.api.lifecycle.Disposable, org.mule.runtime.api.lifecycle.Startable, org.mule.runtime.api.lifecycle.Stoppable

@Experimental @NoImplement @MinMuleVersion("4.10.0") public interface HttpServer extends org.mule.runtime.api.lifecycle.Startable, org.mule.runtime.api.lifecycle.Stoppable, org.mule.runtime.api.lifecycle.Disposable
Represents an HTTP Server. Notice it should be started to be bound, stopped to be unbound and finally disposed to release all related components.
Since:
0.12.0
  • Method Details

    • start

      void start() throws org.mule.runtime.api.exception.MuleException
      Binds the ServerSocket to the network interface and starts listening for requests.
      Specified by:
      start in interface org.mule.runtime.api.lifecycle.Startable
      Throws:
      IOException - if there was a problem binding to the host and port specified.
      org.mule.runtime.api.exception.MuleException
    • stop

      void stop() throws org.mule.runtime.api.exception.MuleException
      Unbinds the ServerSocket to the network interface and stops listening for requests.

      Currently executing requests are not affected and may proceed normally until dispose() is called.

      Specified by:
      stop in interface org.mule.runtime.api.lifecycle.Stoppable
      Throws:
      org.mule.runtime.api.exception.MuleException
    • dispose

      void dispose()
      Removes all secondary data to get rid of the server. Cannot be undone.

      If there are any currently running requests, this method will block until either those requests are finished or a timeout elapses. The requests that were received but didn't start processing, will be finished returning a 503 status code.

      Specified by:
      dispose in interface org.mule.runtime.api.lifecycle.Disposable
    • getServerAddress

      ServerAddress getServerAddress()
      Returns:
      the server address this server is listening on.
    • getProtocol

      HttpConstants.Protocol getProtocol()
      Returns:
      the protocol (HTTP or HTTPS) this server is expecting.
    • isStopping

      boolean isStopping()
      Returns:
      true if the server is currently stopping, false if it's stopped already or if it's not doing stop.
    • isStopped

      boolean isStopped()
      Returns:
      true if the server is stopped, false otherwise.
    • enableTls

      void enableTls(org.mule.runtime.api.tls.TlsContextFactory tlsContextFactory)
      Enable TLS dynamically on this server using the supplied TLS context factory
      Parameters:
      tlsContextFactory - The TLS context factory to be used when dynamically enabled TLS at this server
    • disableTls

      void disableTls()
      Disable TLS dynamically. It should work for when the TLS was dynamically enabled or even when the TLS was statically configured in the listener configuration section of the application.
    • addRequestHandler

      EndpointLifecycleHandler addRequestHandler(Collection<String> methods, String path, RequestHandler requestHandler)
      Adds a RequestHandler on the given path and for the given methods.
      Parameters:
      methods - a list of methods to match
      path - the path to match
      requestHandler - the handler to execute upon a matching request
      Returns:
      a EndpointLifecycleHandler for the handler
    • addRequestHandler

      EndpointLifecycleHandler addRequestHandler(String path, RequestHandler requestHandler)
      Adds a RequestHandler on the given path and for all methods.
      Parameters:
      path - the path to match
      requestHandler - the handler to execute upon a matching request
      Returns:
      a EndpointLifecycleHandler for the handler
    • sse

      SseEndpointManager sse(String ssePath, Consumer<SseRequestContext> onRequest, Consumer<SseClient> onClient)
      Adds an endpoint to produce server-sent events.
      Parameters:
      ssePath - path to match.
      onRequest - callback to be executed when a request is received. It can be used to customize the SSE response and the SSE Client to be created.
      onClient - callback to be executed for each received SseClient. Note: this callback will be executed AFTER onRequest.
      Returns:
      an object that can be used to enable/disable/remove the endpoint from the server.
    • sse

      default SseEndpointManager sse(String ssePath, Consumer<SseClient> sseClientHandler)
      Adds an endpoint to produce server-sent events. Equivalent to call sse(String, Consumer, Consumer) with a no-op onRequest callback.
      Parameters:
      ssePath - path to match.
      sseClientHandler - callback to be executed for each received SseClient.
      Returns:
      an object that can be used to enable/disable/remove the endpoint from the server.