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 overRouterthat aims 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 static classSimplifiedRouter.SafeRequestInterceptorprivate static classSimplifiedRouter.SafeRoutingContextHandler
-
Field Summary
Fields Modifier and Type Field Description private Map<io.vertx.core.http.HttpMethod,Boolean>httpMethodsThatMayReadBodyprivate RequestInterceptorHandlerinterceptorHandlerprivate KosConfigurationkosConfigurationprivate io.vertx.core.logging.Loggerlogprivate io.vertx.ext.web.Routerrouter
-
Constructor Summary
Constructors Modifier Constructor Description SimplifiedRouter(KosConfiguration kosConfiguration, io.vertx.ext.web.Router router, Map<io.vertx.core.http.HttpMethod,Boolean> httpMethodsThatMayReadBody)privateSimplifiedRouter(KosConfiguration kosConfiguration, 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(RequestInterceptor interceptor)Registers aHandlerto intercept all requests.voidintercept(RequestInterceptor interceptor, boolean tryHandleExceptions)Registers aHandlerto 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(KosConfiguration kosConfiguration, io.vertx.ext.web.Router router)Creates an instance ofSimplifiedRouterthat will automatically read the request body payload for PATCH, POST and PUT.static SimplifiedRouterwrapWithNoAutoBodyReader(KosConfiguration kosConfiguration, io.vertx.ext.web.Router router)Creates a basic instance ofSimplifiedRouter.
-
-
-
Field Detail
-
log
private final io.vertx.core.logging.Logger log
-
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
-
kosConfiguration
private final KosConfiguration kosConfiguration
-
-
Constructor Detail
-
SimplifiedRouter
public SimplifiedRouter(KosConfiguration kosConfiguration, io.vertx.ext.web.Router router, Map<io.vertx.core.http.HttpMethod,Boolean> httpMethodsThatMayReadBody)
-
SimplifiedRouter
private SimplifiedRouter(KosConfiguration kosConfiguration, 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 aHandlerto intercept all requests.- Parameters:
interceptor- the interceptor handler.
-
intercept
public void intercept(RequestInterceptor interceptor, boolean tryHandleExceptions)
Registers aHandlerto 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.
-
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(KosConfiguration kosConfiguration, 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(KosConfiguration kosConfiguration, 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>
-
-