Package spark

Class RouteImpl

java.lang.Object
spark.RouteImpl
All Implemented Interfaces:
Route, Wrapper
Direct Known Subclasses:
ResponseTransformerRouteImpl, TemplateViewRouteImpl

public abstract class RouteImpl extends Object implements Route, Wrapper
RouteImpl is created from a path, acceptType and Route. This is encapsulate the information needed in the route matcher in a single container.
  • Field Details

  • Constructor Details

    • RouteImpl

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

      protected RouteImpl(String path, 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(String path, String acceptType, 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 Details

    • withPrefix

      public RouteImpl withPrefix(String prefix)
      Parameters:
      prefix - the prefix
      Returns:
      itself for easy chaining
    • create

      public static RouteImpl create(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(String path, 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 Object handle(Request request, Response response) throws 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:
      Exception - when handle fails
    • render

      public Object render(Object element) throws 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:
      Exception - when render fails
    • getAcceptType

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

      public String getPath()
      Returns:
      the path
    • delegate

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