Package tech.greenfield.vertx.irked
Class RouteConfiguration
- java.lang.Object
-
- tech.greenfield.vertx.irked.RouteConfiguration
-
- Direct Known Subclasses:
RouteConfigurationField,RouteConfigurationMethod
public abstract class RouteConfiguration extends Object
Internal implementation that handles parsing route annotations and setting up the router. This is an abstract class that implements the common logic for both routing methods and routing fields.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classRouteConfiguration.RoutingContextImplException
-
Field Summary
Fields Modifier and Type Field Description protected Annotation[]annotationsprotected Controllerimplprotected org.slf4j.Loggerlogprotected Routerrouterprotected Function<Request,Request>routingContextResolverprotected Class<? extends io.vertx.ext.web.RoutingContext>routingContextType
-
Constructor Summary
Constructors Modifier Constructor Description protectedRouteConfiguration(Controller impl, Router router, Annotation[] annotations)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends Annotation>
List<io.vertx.ext.web.Route>buildRoutesFor(String prefix, Class<T> anot, tech.greenfield.vertx.irked.Router.RoutingMethod method, RequestWrapper requestWrapper)protected Function<Request,Request>findRoutingContextResolver()Check if we can statically locate an appropriate routing context supplier in the controller implementation.protected abstract <T extends Annotation>
T[]getAnnotation(Class<T> anot)protected abstract StringgetName()protected voidhandleUserException(Request r, Throwable cause, String invocationDescription)Handling logic for user exceptions thrown from a handler invocation.protected voidhandleUserException(WebSocketMessage m, Throwable cause, String invocationDescription)Handling logic for user exceptions thrown from a message handler invocation.<T extends Annotation>
Stream<String>pathsForAnnotation(String prefix, Class<T> anot)protected RequestresolveRequestContext(Request r)Try to resolve the handler requested routing context type by instantiating the requested type if needed.StringtoString()protected voidtrySetRoutingContextType(Class<?> type)protected String[]uriForAnnotations(Class<?>... anot)
-
-
-
Field Detail
-
annotations
protected Annotation[] annotations
-
router
protected Router router
-
impl
protected Controller impl
-
routingContextType
protected Class<? extends io.vertx.ext.web.RoutingContext> routingContextType
-
log
protected org.slf4j.Logger log
-
-
Constructor Detail
-
RouteConfiguration
protected RouteConfiguration(Controller impl, Router router, Annotation[] annotations)
-
-
Method Detail
-
trySetRoutingContextType
protected void trySetRoutingContextType(Class<?> type)
-
getAnnotation
protected abstract <T extends Annotation> T[] getAnnotation(Class<T> anot)
-
getName
protected abstract String getName()
-
pathsForAnnotation
public <T extends Annotation> Stream<String> pathsForAnnotation(String prefix, Class<T> anot)
-
buildRoutesFor
public <T extends Annotation> List<io.vertx.ext.web.Route> buildRoutesFor(String prefix, Class<T> anot, tech.greenfield.vertx.irked.Router.RoutingMethod method, RequestWrapper requestWrapper) throws InvalidRouteConfiguration
- Throws:
InvalidRouteConfiguration
-
handleUserException
protected void handleUserException(Request r, Throwable cause, String invocationDescription)
Handling logic for user exceptions thrown from a handler invocation. Handler developers can throw an IrkedHttpErrorexception to propagate an HTTP response to the failure handler, or an unexpected exception can be thrown which would mean a server error. BecauseHttpErrors may be wrapped by all kinds of wrappers, from IrkedHttpError.UncheckedHttpErrorto Jackson's JsonMappingException, we try hard to extractHttpErrors wherever we find them - to make the fail handler's developer's life easier.- Parameters:
r- routing context on which this handler was calledcause- User exception thrown from the handlerinvocationDescription- Description of the invocation endpoint for logging
-
handleUserException
protected void handleUserException(WebSocketMessage m, Throwable cause, String invocationDescription)
Handling logic for user exceptions thrown from a message handler invocation. Note that WebSocket does not provide robust error reporting mechanisms - unless the application handles their own error detection and reporting using an application-level protocol, the only think we can do is send a close frame with a status code (specified by IANA but almost completely useless) and a text message. As such we expect the application developer to implement their own application level error handling protocol and here we implement a "last refuge" handler that closes the socket and attempts to provide useful information while limiting internal implementation details leakage. We assume that this method will be called in two cases:- The developer threw an
HttpErrorfrom a message handler - which they shouldn't do, but we can try to give them a simple expected behavior by closing the socket with a 1002 ("Protocol Error") status and the message from the exception (it could be the HTTP status message, or a custom message). - An unexpected exception was thrown from a message handler - that the developer should have caught but didn't. In that case we will close the socket with a 1011 ("Internal Error") status and the exception message. We will also dump the full exception stack to the error log.
- Parameters:
m- message that caused the exceptioncause- User exception thrown from the handlerinvocationDescription- Description of the invocation endpoint for logging
- The developer threw an
-
findRoutingContextResolver
protected Function<Request,Request> findRoutingContextResolver()
Check if we can statically locate an appropriate routing context supplier in the controller implementation.- Returns:
- a trivial supplier, or null if none found
-
resolveRequestContext
protected Request resolveRequestContext(Request r) throws RouteConfiguration.RoutingContextImplException
Try to resolve the handler requested routing context type by instantiating the requested type if needed.- Parameters:
r- current routing context instance. This can be in itself a Request sub-type, which the handler's preferred context type might require for initialization- Returns:
- the current routing context type if it is already sufficient, or a new instance of the required type if it can be successfully trivially constructed.
- Throws:
RouteConfiguration.RoutingContextImplException- if the requested type is not a Request sub-type or it cannot be successfully constructed.
-
-