Class 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.
    • Field Detail

      • router

        protected Router router
      • routingContextType

        protected Class<? extends io.vertx.ext.web.RoutingContext> routingContextType
      • log

        protected org.slf4j.Logger log
    • Method Detail

      • trySetRoutingContextType

        protected void trySetRoutingContextType​(Class<?> type)
      • uriForAnnotations

        protected String[] uriForAnnotations​(Class<?>... anot)
      • getAnnotation

        protected abstract <T extends Annotation> T[] getAnnotation​(Class<T> anot)
      • getName

        protected abstract String getName()
      • 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 Irked HttpError exception to propagate an HTTP response to the failure handler, or an unexpected exception can be thrown which would mean a server error. Because HttpErrors may be wrapped by all kinds of wrappers, from Irked HttpError.UncheckedHttpError to Jackson's JsonMappingException, we try hard to extract HttpErrors wherever we find them - to make the fail handler's developer's life easier.
        Parameters:
        r - routing context on which this handler was called
        cause - User exception thrown from the handler
        invocationDescription - 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 HttpError from 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 exception
        cause - User exception thrown from the handler
        invocationDescription - Description of the invocation endpoint for logging
      • 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.