Called if no route matches the current request for any method.
Called if no route matches the current request for any method. The default implementation varies between servlet and filter.
The effective path against which routes are matched.
The effective path against which routes are matched. The definition varies between servlets and filters.
The base path for URL generation
The base path for URL generation
Prepends a new route for the given HTTP method.
Prepends a new route for the given HTTP method.
Can be overriden so that subtraits can use their own logic. Possible examples: $ - restricting protocols $ - namespace routes based on class name $ - raising errors on overlapping entries.
This is the method invoked by get(), post() etc.
org.scalatra.ScalatraKernel#removeRoute
Adds a filter to run after the route.
Adds a filter to run after the route. The filter only runs if each routeMatcher returns Some. If the routeMatchers list is empty, the filter runs for all routes.
Adds a filter to run before the route.
Adds a filter to run before the route. The filter only runs if each routeMatcher returns Some. If the routeMatchers list is empty, the filter runs for all routes.
Converts a boolean expression to a route matcher.
Converts a boolean expression to a route matcher.
a block that evaluates to a boolean
a route matcher based on block
. The route matcher should
return Some
if the block is true and None
if the block is false.
The configuration, typically a ServletConfig or FilterConfig.
The configuration, typically a ServletConfig or FilterConfig.
Gets the content type of the current response.
Gets the content type of the current response.
A partial function to infer the content type from the action result.
A partial function to infer the content type from the action result.
$ - "text/plain" for String $ - "application/octet-stream" for a byte array $ - "text/html" for any other result
Sets the content type of the current response.
Sets the content type of the current response.
The default character encoding for requests and responses.
The default character encoding for requests and responses.
get
Called if no route matches the current request method, but routes match for other methods.
Called if no route matches the current request method, but routes
match for other methods. By default, sends an HTTP status of 405
and an Allow
header containing a comma-delimited list of the allowed
methods.
Defines an error handler for exceptions thrown in either the before block or a route action.
Defines an error handler for exceptions thrown in either the before block or a route action.
If the error handler does not match, the result falls through to the previously defined error handler. The default error handler simply rethrows the exception.
The error handler is run before the after filters, and the result is rendered like a standard response. It is the error handler's responsibility to set any appropriate status code.
The error handler function, called if an exception is thrown during before filters or the routes.
The error handler function, called if an exception is thrown during before filters or the routes.
Executes routes in the context of the current request and response.
Executes routes in the context of the current request and response.
$ 1. Executes each before filter with runFilters
.
$ 2. Executes the routes in the route registry with runRoutes
for
the request's method.
a. The result of runRoutes becomes the _action result_.
b. If no route matches the requested method, but matches are
found for other methods, then the doMethodNotAllowed
hook is
run with each matching method.
c. If no route matches any method, then the doNotFound
hook is
run, and its return value becomes the action result.
$ 3. If an exception is thrown during the before filters or the route
$ actions, then it is passed to the errorHandler
function, and its
$ result becomes the action result.
$ 4. Executes the after filters with runFilters
.
$ 5. The action result is passed to renderResponse
.
Explicitly sets the request-scoped format.
Explicitly sets the request-scoped format. This takes precedence over whatever was inferred from the request.
Explicitly sets the request-scoped format.
Explicitly sets the request-scoped format. This takes precedence over whatever was inferred from the request.
Builds a full URL from the given relative path.
Builds a full URL from the given relative path. Takes into account the port configuration, https, ...
a relative path
the full URL
The Scalatra DSL core methods take a list of org.scalatra.RouteMatcher and a block as the action body.
The Scalatra DSL core methods take a list of org.scalatra.RouteMatcher and a block as the action body. The return value of the block is rendered through the pipeline and sent to the client as the response body.
See org.scalatra.ScalatraBase#renderResponseBody for the detailed behaviour and how to handle your response body more explicitly, and see how different return types are handled.
The block is executed in the context of a CoreDsl instance, so all the methods defined in this trait are also available inside the block.
get("/") { <form action="/echo"> <label>Enter your name</label> <input type="text" name="name"/> </form> } post("/echo") { "hello {params('name)}!" }
ScalatraKernel provides implicit transformation from boolean blocks, strings and regular expressions to org.scalatra.RouteMatcher, so you can write code naturally.
get("/", request.getRemoteHost == "127.0.0.1") { "Hello localhost!" }
Immediately halts processing of a request.
Immediately halts processing of a request. Can be called from either a before filter or a route.
the status to set on the response, or null to leave the status unchanged.
a result to render through the render pipeline as the body
headers to add to the response
the HTTP status reason to set, or null to leave unchanged.
Handles a request and renders a response.
Handles a request and renders a response.
$ 1. If the request lacks a character encoding, defaultCharacterEncoding
is set to the request.
$ 2. Sets the response's character encoding to defaultCharacterEncoding
.
$ 3. Binds the current request
, response
, and multiParams
, and calls
executeRoutes()
.
head
Gets an init paramter from the config.
Gets an init paramter from the config.
the name of the key
an option containing the value of the parameter if defined, or
None
if the parameter is not set.
Initializes the kernel.
Initializes the kernel. Used to provide context that is unavailable
when the instance is constructed, for example the servlet lifecycle.
Should set the config
variable to the parameter.
the configuration.
Invokes a route or filter.
Invokes a route or filter. The multiParams gathered from the route matchers are merged into the existing route params, and then the action is run.
the matched route to execute
the result of the matched route's action wrapped in Some
,
or None
if the action calls pass
.
A boolean flag representing whether the kernel is in development mode.
A boolean flag representing whether the kernel is in development mode.
The default is true if the environment
begins with "dev", case-insensitive.
Defines a block to run if matching routes are found only for other methods.
Defines a block to run if matching routes are found only for other methods. The set of matching methods is passed to the block.
The current multiparams.
The current multiparams. Multiparams are a result of merging the
standard request params (query string or post params) with the route
parameters extracted from the route matchers of the current route.
The default value for an unknown param is the empty sequence. Invalid
outside handle
.
Defines a block to run if no matching routes are found, or if all matching routes pass.
Defines a block to run if no matching routes are found, or if all matching routes pass.
get
Immediately exits from the current route.
Immediately exits from the current route.
patch
Path pattern is decoupled from requests.
Path pattern is decoupled from requests. This adapts the PathPattern to a RouteMatcher by supplying the request path.
get
get
Sends a redirect response and immediately halts the current action.
Sends a redirect response and immediately halts the current action.
Converts a regular expression to a route matcher.
Converts a regular expression to a route matcher.
the regular expression
a route matcher based on regex
Removes _all_ the actions of a given route for a given HTTP method.
Removes _all_ the actions of a given route for a given HTTP method. If addRoute is overridden then this should probably be overriden too.
org.scalatra.ScalatraKernel#addRoute
The render pipeline is a partial function of Any => Any.
The render pipeline is a partial function of Any => Any. It is called recursively until it returns (). () indicates that the response has been rendered.
Renders the action result to the response.
Renders the action result to the response. $ - If the content type is still null, call the contentTypeInferrer. $ - Call the render pipeline on the result.
Renders the action result to the response body via the render pipeline.
Renders the action result to the response body via the render pipeline.
#renderPipeline
The currently scoped request.
The currently scoped request. Valid only inside the handle
method.
The currently scoped response.
The currently scoped response. Valid only inside the handle
method.
The routes registered in this kernel.
The routes registered in this kernel.
Invokes each filters with invoke
.
Invokes each filters with invoke
. The results of the filters
are discarded.
Lazily invokes routes with invoke
.
Lazily invokes routes with invoke
. The results of the routes
are returned as a stream.
Implicit convert a (String) => Option[T]
function into a TypeConverter[T]
Implicit convert a (String) => Option[T]
function into a TypeConverter[T]
The servlet context in which this kernel runs.
The servlet context in which this kernel runs.
The current session.
The current session. Creates a session if none exists.
The current session.
The current session. If none exists, None is returned.
Gets the status code of the current response.
Gets the status code of the current response.
Sets the status code of the current response.
Sets the status code of the current response.
Pluggable way to convert a path expression to a route matcher.
Pluggable way to convert a path expression to a route matcher. The default implementation is compatible with Sinatra's route syntax.
a path expression
a route matcher based on path
Error handler for HTTP response status code range.
Error handler for HTTP response status code range. You can intercept every response code previously specified with #status or even generic 404 error.
trap(403) { "You are not authorized" } }*
}}
error
Returns a context-relative, session-aware URL for a path and specified parameters.
Returns a context-relative, session-aware URL for a path and specified
parameters.
Finally, the result is run through response.encodeURL
for a session
ID, if necessary.
the base path. If a path begins with '/', then the context path will be prepended to the result
params, to be appended in the form of a query string
the path plus the query string, if any. The path is run through
response.encodeURL
to add any necessary session tracking parameters.
Executes the block with the given request bound to the request
method.
Executes the block with the given request bound to the request
method.
Executes the block with the given response bound to the response
method.
Executes the block with the given response bound to the response
method.
(Since version 2.1.0) Do not invoke directly. Use withRequest
to change the binding, or request to get the value
(Since version 2.1.0) Do not invoke directly. Use withResponse
to change the binding, or response
to get the value
(Since version 2.1.0) Use servletContext instead
(Since version 2.1.0) Use status_=(Int) instead
(Since version 2.2) This got folded into core, so you can remove the TypeParamSupport trait safely.