- 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
-
Field Summary
Fields inherited from interface org.mule.runtime.api.lifecycle.Disposable
PHASE_NAMEFields inherited from interface org.mule.runtime.api.lifecycle.Startable
PHASE_NAMEFields inherited from interface org.mule.runtime.api.lifecycle.Stoppable
PHASE_NAME -
Method Summary
Modifier and TypeMethodDescriptionaddRequestHandler(String path, RequestHandler requestHandler) Adds aRequestHandleron the given path and for all methods.addRequestHandler(Collection<String> methods, String path, RequestHandler requestHandler) Adds aRequestHandleron the given path and for the given methods.voidDisable TLS dynamically.voiddispose()Removes all secondary data to get rid of the server.voidenableTls(org.mule.runtime.api.tls.TlsContextFactory tlsContextFactory) Enable TLS dynamically on this server using the supplied TLS context factorybooleanbooleandefault SseEndpointManagerAdds an endpoint to produce server-sent events.Adds an endpoint to produce server-sent events.voidstart()Binds the ServerSocket to the network interface and starts listening for requests.voidstop()Unbinds the ServerSocket to the network interface and stops listening for requests.
-
Method Details
-
start
void start() throws org.mule.runtime.api.exception.MuleExceptionBinds the ServerSocket to the network interface and starts listening for requests.- Specified by:
startin interfaceorg.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.MuleExceptionUnbinds 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:
stopin interfaceorg.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:
disposein interfaceorg.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 aRequestHandleron the given path and for the given methods.- Parameters:
methods- a list of methods to matchpath- the path to matchrequestHandler- the handler to execute upon a matching request- Returns:
- a
EndpointLifecycleHandlerfor the handler
-
addRequestHandler
Adds aRequestHandleron the given path and for all methods.- Parameters:
path- the path to matchrequestHandler- the handler to execute upon a matching request- Returns:
- a
EndpointLifecycleHandlerfor 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 receivedSseClient. Note: this callback will be executed AFTERonRequest.- Returns:
- an object that can be used to enable/disable/remove the endpoint from the server.
-
sse
Adds an endpoint to produce server-sent events. Equivalent to callsse(String, Consumer, Consumer)with a no-oponRequestcallback.- Parameters:
ssePath- path to match.sseClientHandler- callback to be executed for each receivedSseClient.- Returns:
- an object that can be used to enable/disable/remove the endpoint from the server.
-