Abstract type member for the configuration to use during initialization.
Abstract type member for the configuration to use during initialization.
Examples include ServletConfig
and FilterConfig
.
Implementation detail.
Implementation detail.
A dynamic variable containing the currently-scoped request.
A dynamic variable containing the currently-scoped request. Should
not typically be invoked directly. Prefer request
.
#request
A dynamic variable containing the currently-scoped response.
A dynamic variable containing the currently-scoped response. Should
not typically be invoked directly. Prefer response
.
#response
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.
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.
Invoked when no route matches.
Invoked when no route matches. By default, calls serveStaticResource()
,
and if that fails, calls resourceNotFound()
.
This action can be overridden by a notFound block.
A free form string representing the environment.
A free form string representing the environment.
org.scalatra.Environment
is looked up as a system property, and if
absent, and init parameter. The default value is development
.
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.
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
.
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.ScalatraKernel.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()
.
Gets an init paramter from the config if it is a ServletConfig or a FilterConfig.
Gets an init paramter from the config if it is a ServletConfig or a FilterConfig.
the name of the key
an option containing the value of the parameter if defined, or
None
if the parameter is not set or the config type has no concept of
init parameters.
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
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
insensitve.
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.
A view of multiParams
.
A view of multiParams
. Returns the head element for any known param,
and is undefined for any unknown param. Invalid outside handle
.
Immediately exits from the current route.
Immediately exits from the current route.
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. Invalid outside handle
.
Defines the request path to be matched by routers.
Defines the request path to be matched by routers. The default
definition is optimized for path mapped
servlets (i.e., servlet
mapping ends in /*
). The route should match everything matched by
the /*
. In the event that the request URI equals the servlet path
with no trailing slash (e.g., mapping = /admin/*
, request URI =
'/admin'), a '/' is returned.
All other servlet mappings likely want to return request.getServletPath. Custom implementations are allowed for unusual cases.
Called by default notFound if no routes matched and no static resource could be found.
Called by default notFound if no routes matched and no static resource could be found.
The currently scoped response.
The currently scoped response. Invalid outside handle
.
The base path for URL generation
The base path for URL generation
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.
Attempts to find a static resource matching the request path.
Attempts to find a static resource matching the request path. Override to return None to stop this.
The servlet context in which this kernel runs.
The servlet context in which this kernel runs.
The current HTTP session.
The current HTTP session. Creates a session if none exists.
The current HTTP session.
The current HTTP session. If none exists, None is returned.
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
Use addRoute(HttpMethod, Iterable[RouteMatcher], =>Any)
Use after() { ... }
Use after(RouteMatcher*) { ... }
Use before() { ... }
Use before(RouteMatcher*) { ... }
An implementation of the Scalatra DSL in a servlet. This is the recommended base class for most Scalatra applications. Use a servlet if:
$ - your Scalatra routes run in a subcontext of your web application. $ - you want Scalatra to have complete control of unmatched requests. $ - you think you want a filter just for serving static content with the default servlet; ScalatraServlet can do this too $ - you don't know the difference
ScalatraFilter