Package kos.core
Class SimplifiedRouter
- java.lang.Object
-
- kos.core.SimplifiedRouter
-
- All Implemented Interfaces:
io.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>
public class SimplifiedRouter extends Object implements io.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>
Small layer that wrapsRouteraiming to simplify a few common aspects regarding route configuration, like intercepting requests and the reading body requests in a POST, PUT and PATCH requests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSimplifiedRouter.SafeRequestInterceptorprivate classSimplifiedRouter.SafeRoutingContextHandler
-
Field Summary
Fields Modifier and Type Field Description private Map<io.vertx.core.http.HttpMethod,Boolean>httpMethodsThatMayReadBodyprivate RequestInterceptorHandlerinterceptorHandlerprivate KosContextkosContextprivate io.vertx.ext.web.Routerrouter
-
Constructor Summary
Constructors Modifier Constructor Description SimplifiedRouter(KosContext kosContext, io.vertx.ext.web.Router router, Map<io.vertx.core.http.HttpMethod,Boolean> httpMethodsThatMayReadBody)privateSimplifiedRouter(KosContext kosContext, io.vertx.ext.web.Router router, RequestInterceptorHandler interceptor, Map<io.vertx.core.http.HttpMethod,Boolean> httpMethodsThatMayReadBody)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidhandle(io.vertx.core.http.HttpServerRequest event)voidintercept(io.vertx.core.Handler<io.vertx.ext.web.RoutingContext> interceptor)Registers aHandlerto intercept all received requests.voidintercept(RequestInterceptor interceptor)Registers aRequestInterceptorto intercept all requests.voidintercept(RequestInterceptor interceptor, boolean tryHandleExceptions)Registers aRequestInterceptorto intercept all requests.voidroute(io.vertx.core.http.HttpMethod method, String path, io.vertx.core.Handler<io.vertx.ext.web.RoutingContext> handler)Routes requests made topathto a particular handler.voidroute(io.vertx.core.http.HttpMethod method, String path, RequestHandler handler)Routes requests made topathto a particular handler.io.vertx.ext.web.Routerunwrap()Returns the wrapped Vert.xRouter.static SimplifiedRouterwrapWithAutoBodyReader(KosContext kosContext, io.vertx.ext.web.Router router)Creates an instance ofSimplifiedRouterthat will automatically read the request body payload for PATCH, POST and PUT.static SimplifiedRouterwrapWithNoAutoBodyReader(KosContext kosContext, io.vertx.ext.web.Router router)Creates a basic instance ofSimplifiedRouter.
-
-
-
Field Detail
-
router
private final io.vertx.ext.web.Router router
-
interceptorHandler
private final RequestInterceptorHandler interceptorHandler
-
httpMethodsThatMayReadBody
private final Map<io.vertx.core.http.HttpMethod,Boolean> httpMethodsThatMayReadBody
-
kosContext
private final KosContext kosContext
-
-
Constructor Detail
-
SimplifiedRouter
public SimplifiedRouter(KosContext kosContext, io.vertx.ext.web.Router router, Map<io.vertx.core.http.HttpMethod,Boolean> httpMethodsThatMayReadBody)
-
SimplifiedRouter
private SimplifiedRouter(KosContext kosContext, io.vertx.ext.web.Router router, RequestInterceptorHandler interceptor, Map<io.vertx.core.http.HttpMethod,Boolean> httpMethodsThatMayReadBody)
-
-
Method Detail
-
unwrap
public io.vertx.ext.web.Router unwrap()
Returns the wrapped Vert.xRouter.- Returns:
- the wrapped Vert.x
Router
-
intercept
public void intercept(RequestInterceptor interceptor)
Registers aRequestInterceptorto intercept all requests.- Parameters:
interceptor- the interceptor handler.
-
intercept
public void intercept(RequestInterceptor interceptor, boolean tryHandleExceptions)
Registers aRequestInterceptorto intercept all requests.- Parameters:
tryHandleExceptions- if set true, it will wrap the interceptor and try to handle possible exceptions that might be thrown. It won't be capable to handle those that might happen on a different thread though.interceptor- the interceptor handler.
-
intercept
public void intercept(io.vertx.core.Handler<io.vertx.ext.web.RoutingContext> interceptor)
Registers aHandlerto intercept all received requests.- Parameters:
interceptor- The interceptor handler
-
route
public void route(io.vertx.core.http.HttpMethod method, String path, RequestHandler handler)Routes requests made topathto a particular handler.- Parameters:
method- Http Method used by this endpointpath- relative URI used by this endpointhandler- request handler
-
route
public void route(io.vertx.core.http.HttpMethod method, String path, io.vertx.core.Handler<io.vertx.ext.web.RoutingContext> handler)Routes requests made topathto a particular handler.- Parameters:
method- Http Method used by this endpointpath- relative URI used by this endpointhandler- request handler
-
wrapWithAutoBodyReader
public static SimplifiedRouter wrapWithAutoBodyReader(KosContext kosContext, io.vertx.ext.web.Router router)
Creates an instance ofSimplifiedRouterthat will automatically read the request body payload for PATCH, POST and PUT.- Parameters:
router- the router instance that will be wrapped- Returns:
- An instance of
SimplifiedRouter
-
wrapWithNoAutoBodyReader
public static SimplifiedRouter wrapWithNoAutoBodyReader(KosContext kosContext, io.vertx.ext.web.Router router)
Creates a basic instance ofSimplifiedRouter. Developers that use instances created by this method should configure themselves how to read the request body payload.- Parameters:
router- the router instance that will be wrapped- Returns:
- An instance of
SimplifiedRouter
-
handle
public void handle(io.vertx.core.http.HttpServerRequest event)
- Specified by:
handlein interfaceio.vertx.core.Handler<io.vertx.core.http.HttpServerRequest>
-
-