Package spark

Class RouteImpl

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String acceptType  
      (package private) static java.lang.String DEFAULT_ACCEPT_TYPE  
      private java.lang.Object delegate  
      private java.lang.String path  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected RouteImpl​(java.lang.String path)
      Constructor
      protected RouteImpl​(java.lang.String path, java.lang.String acceptType)
      Constructor
      protected RouteImpl​(java.lang.String path, java.lang.String acceptType, java.lang.Object route)
      Constructor
    • Field Detail

      • path

        private java.lang.String path
      • acceptType

        private java.lang.String acceptType
      • delegate

        private java.lang.Object delegate
    • Constructor Detail

      • RouteImpl

        protected RouteImpl​(java.lang.String path)
        Constructor
        Parameters:
        path - The route path which is used for matching. (e.g. /hello, users/:name)
      • RouteImpl

        protected RouteImpl​(java.lang.String path,
                            java.lang.String acceptType)
        Constructor
        Parameters:
        path - The route path which is used for matching. (e.g. /hello, users/:name)
        acceptType - The accept type which is used for matching.
      • RouteImpl

        protected RouteImpl​(java.lang.String path,
                            java.lang.String acceptType,
                            java.lang.Object route)
        Constructor
        Parameters:
        path - The route path which is used for matching. (e.g. /hello, users/:name)
        acceptType - The accept type which is used for matching.
        route - The route used to create the route implementation
    • Method Detail

      • create

        public static RouteImpl create​(java.lang.String path,
                                       Route route)
        Wraps the route in RouteImpl
        Parameters:
        path - the path
        route - the route
        Returns:
        the wrapped route
      • create

        public static RouteImpl create​(java.lang.String path,
                                       java.lang.String acceptType,
                                       Route route)
        Wraps the route in RouteImpl
        Parameters:
        path - the path
        acceptType - the accept type
        route - the route
        Returns:
        the wrapped route
      • handle

        public abstract java.lang.Object handle​(Request request,
                                                Response response)
                                         throws java.lang.Exception
        Invoked when a request is made on this route's corresponding path e.g. '/hello'
        Specified by:
        handle in interface Route
        Parameters:
        request - The request object providing information about the HTTP request
        response - The response object providing functionality for modifying the response
        Returns:
        The content to be set in the response
        Throws:
        java.lang.Exception - when handle fails
      • render

        public java.lang.Object render​(java.lang.Object element)
                                throws java.lang.Exception
        This method should render the given element into something that can be send through Response element. By default this method returns the result of calling toString method in given element, but can be overridden.
        Parameters:
        element - to be rendered.
        Returns:
        body content.
        Throws:
        java.lang.Exception - when render fails
      • getAcceptType

        public java.lang.String getAcceptType()
        Returns:
        the accept type
      • getPath

        public java.lang.String getPath()
        Returns:
        the path
      • delegate

        public java.lang.Object delegate()
        Specified by:
        delegate in interface Wrapper
        Returns:
        the route used to create the route implementation