Package spark
Class RouteImpl
- java.lang.Object
-
- spark.RouteImpl
-
- Direct Known Subclasses:
ResponseTransformerRouteImpl
,TemplateViewRouteImpl
public abstract class RouteImpl extends java.lang.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 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)
Constructorprotected
RouteImpl(java.lang.String path, java.lang.String acceptType)
Constructorprotected
RouteImpl(java.lang.String path, java.lang.String acceptType, java.lang.Object route)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static RouteImpl
create(java.lang.String path, java.lang.String acceptType, Route route)
Wraps the route in RouteImplstatic RouteImpl
create(java.lang.String path, Route route)
Wraps the route in RouteImpljava.lang.Object
delegate()
java.lang.String
getAcceptType()
java.lang.String
getPath()
abstract java.lang.Object
handle(Request request, Response response)
Invoked when a request is made on this route's corresponding path e.g.java.lang.Object
render(java.lang.Object element)
This method should render the given element into something that can be send through Response element.RouteImpl
withPrefix(java.lang.String prefix)
Prefix the path (used forService.path(java.lang.String, spark.RouteGroup)
)
-
-
-
Field Detail
-
DEFAULT_ACCEPT_TYPE
static final java.lang.String DEFAULT_ACCEPT_TYPE
- See Also:
- Constant Field Values
-
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
-
withPrefix
public RouteImpl withPrefix(java.lang.String prefix)
Prefix the path (used forService.path(java.lang.String, spark.RouteGroup)
)- Parameters:
prefix
- the prefix- Returns:
- itself for easy chaining
-
create
public static RouteImpl create(java.lang.String path, Route route)
Wraps the route in RouteImpl- Parameters:
path
- the pathroute
- 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 pathacceptType
- the accept typeroute
- 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 interfaceRoute
- Parameters:
request
- The request object providing information about the HTTP requestresponse
- 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
-
-