Interface Middleware
-
- All Superinterfaces:
java.util.function.BiFunction<HttpRequestContext,MiddlewareChain,java.util.concurrent.CompletionStage<HttpResult>>
- All Known Implementing Classes:
AccessLogger,AuthBasic,PathFilterMiddleware,RequestValidator,Router,ServeStatic,SupportJson
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Middleware extends java.util.function.BiFunction<HttpRequestContext,MiddlewareChain,java.util.concurrent.CompletionStage<HttpResult>>
An interface defines functions which will be applied in HTTP request-response cycle.- Since:
- 1.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.concurrent.CompletionStage<HttpResult>apply(HttpRequestContext ctx, MiddlewareChain next)Apply thisMiddlewareto the givenHttpRequestContext.default voidclose()Closes thisMiddlewareand releases any system resources associated with it.default voidonServerClosed()This method will be invoked by framework when theHttpServerwhich thisMiddlewarebelongs to is just be closed.
-
-
-
Method Detail
-
apply
java.util.concurrent.CompletionStage<HttpResult> apply(HttpRequestContext ctx, MiddlewareChain next)
Apply thisMiddlewareto the givenHttpRequestContext.- Specified by:
applyin interfacejava.util.function.BiFunction<HttpRequestContext,MiddlewareChain,java.util.concurrent.CompletionStage<HttpResult>>- Parameters:
ctx- theHttpRequestContextobject of the current HTTP requestnext- theMiddlewareChainfor invoking the nextMiddleware- Returns:
- a
CompletionStage<HttpResult>
-
onServerClosed
default void onServerClosed() throws java.lang.ExceptionThis method will be invoked by framework when theHttpServerwhich thisMiddlewarebelongs to is just be closed.This method is equivalent to
close().- Throws:
java.lang.Exception- if any error occurs
-
close
default void close() throws java.lang.ExceptionCloses thisMiddlewareand releases any system resources associated with it.Default do nothing.
- Throws:
java.lang.Exception- if any error occurs
-
-