trait ScalatraBase extends ScalatraContext with CoreDsl with DynamicScope with Initializable with ServletApiImplicits with ScalatraParamsImplicits with DefaultImplicitConversions with SessionSupport
The base implementation of the Scalatra DSL. Intended to be portable to all supported backends.
- Alphabetic
- By Inheritance
- ScalatraBase
- DefaultImplicitConversions
- LowPriorityImplicitConversions
- LowestPriorityImplicitConversions
- TypeConverterSupport
- ScalatraParamsImplicits
- Initializable
- DynamicScope
- RequestResponseScope
- CoreDsl
- Control
- Handler
- ScalatraContext
- CookieContext
- SessionSupport
- ServletApiImplicits
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
Abstract Value Members
- implicit abstract def configWrapper(config: ConfigT): Config
- Attributes
- protected
- Definition Classes
- Initializable
- abstract val doNotFound: Action
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.
- Attributes
- protected
- abstract def requestPath(implicit request: HttpServletRequest): String
The effective path against which routes are matched.
The effective path against which routes are matched. The definition varies between servlets and filters.
- abstract def routeBasePath(implicit request: HttpServletRequest): String
The base path for URL generation
The base path for URL generation
- Attributes
- protected
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def addRoute(method: HttpMethod, transformers: Seq[RouteTransformer], action: => Any): Route
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.
- Attributes
- protected
- See also
org.scalatra.ScalatraKernel#removeRoute
- def addSessionId(uri: String)(implicit response: HttpServletResponse): String
- Attributes
- protected
- def addStatusRoute(codes: Range, action: => Any): Unit
- Attributes
- protected[scalatra]
- def after(transformers: RouteTransformer*)(fun: => Any): Unit
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.
- Definition Classes
- ScalatraBase → CoreDsl
- implicit val anyToBoolean: TypeConverter[Any, Boolean]
- Definition Classes
- LowPriorityImplicitConversions
- implicit val anyToByte: TypeConverter[Any, Byte]
- Definition Classes
- LowPriorityImplicitConversions
- implicit val anyToDouble: TypeConverter[Any, Double]
- Definition Classes
- LowPriorityImplicitConversions
- implicit val anyToFloat: TypeConverter[Any, Float]
- Definition Classes
- LowPriorityImplicitConversions
- implicit val anyToInt: TypeConverter[Any, Int]
- Definition Classes
- LowPriorityImplicitConversions
- implicit val anyToLong: TypeConverter[Any, Long]
- Definition Classes
- LowPriorityImplicitConversions
- implicit val anyToShort: TypeConverter[Any, Short]
- Definition Classes
- LowPriorityImplicitConversions
- implicit val anyToString: TypeConverter[Any, String]
- Definition Classes
- LowPriorityImplicitConversions
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def before(transformers: RouteTransformer*)(fun: => Any): Unit
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.
- Definition Classes
- ScalatraBase → CoreDsl
- implicit def booleanBlock2RouteMatcher(block: => Boolean): RouteMatcher
Converts a boolean expression to a route matcher.
Converts a boolean expression to a route matcher.
- block
a block that evaluates to a boolean
- returns
a route matcher based on
block. The route matcher should returnSomeif the block is true andNoneif the block is false.
- Attributes
- protected
- See also
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- val config: ConfigT
The configuration, typically a ServletConfig or FilterConfig.
- def contentType: String
Gets the content type of the current response.
Gets the content type of the current response.
- Definition Classes
- ScalatraContext
- def contentTypeInferrer: ContentTypeInferrer
A partial function to infer the content type from the action result.
A partial function to infer the content type from the action result.
- returns
$ - "text/plain" for String $ - "application/octet-stream" for a byte array $ - "text/html" for any other result
- Attributes
- protected
- def contentType_=(contentType: String): Unit
Sets the content type of the current response.
Sets the content type of the current response.
- Definition Classes
- ScalatraContext
- def contextPath: String
- Attributes
- protected
- implicit def cookieOptions: CookieOptions
- Definition Classes
- CookieContext
- def cookies(implicit request: HttpServletRequest): SweetCookies
- Definition Classes
- CookieContext
- val decodePercentEncodedPath: Boolean
Set whether to decode when the path returned by the
requestPathmethod is Percent-Eoconding.Set whether to decode when the path returned by the
requestPathmethod is Percent-Eoconding. Default is decode (true).- Attributes
- protected
- val defaultCharacterEncoding: String
The default character encoding for requests and responses.
The default character encoding for requests and responses.
- Attributes
- protected
- implicit def defaultStringToSeq[T](implicit arg0: ClassTag[T], elementConverter: TypeConverter[String, T]): TypeConverter[String, Seq[T]]
- Definition Classes
- DefaultImplicitConversions
- def delete(transformers: RouteTransformer*)(action: => Any): Route
- Definition Classes
- ScalatraBase → CoreDsl
- See also
get
- val doMethodNotAllowed: (Set[HttpMethod]) => Any
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
Allowheader containing a comma-delimited list of the allowed methods.- Attributes
- protected
- implicit def enrichRequest(request: HttpServletRequest): RichRequest
- Definition Classes
- ServletApiImplicits
- implicit def enrichResponse(response: HttpServletResponse): RichResponse
- Definition Classes
- ServletApiImplicits
- implicit def enrichServletContext(servletContext: ServletContext): RichServletContext
- Definition Classes
- ServletApiImplicits
- implicit def enrichSession(session: HttpSession): RichSession
- Definition Classes
- ServletApiImplicits
- def environment: String
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def error(handler: ErrorHandler): Unit
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.
- Definition Classes
- ScalatraBase → CoreDsl
- val errorHandler: ErrorHandler
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.
- Attributes
- protected
- def executeRoutes(): Unit
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 withrunRoutesfor 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 thedoMethodNotAllowedhook is run with each matching method. c. If no route matches any method, then thedoNotFoundhook 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 theerrorHandlerfunction, and its $ result becomes the action result. $ 4. Executes the after filters withrunFilters. $ 5. The action result is passed torenderResponse.- Attributes
- protected
- def extractStatusCode(e: HaltException): Int
- Attributes
- protected
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def format_=(formatValue: String): Unit
Explicitly sets the request-scoped format.
Explicitly sets the request-scoped format. This takes precedence over whatever was inferred from the request.
- Definition Classes
- ScalatraContext
- def format_=(formatValue: Symbol): Unit
Explicitly sets the request-scoped format.
Explicitly sets the request-scoped format. This takes precedence over whatever was inferred from the request.
- Definition Classes
- ScalatraContext
- def fullUrl(path: String, params: Iterable[(String, Any)] = Iterable.empty, includeContextPath: Boolean = true, includeServletPath: Boolean = true, withSessionId: Boolean = true)(implicit request: HttpServletRequest, response: HttpServletResponse): String
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, ...
- path
a relative path
- returns
the full URL
- def get(transformers: RouteTransformer*)(action: => Any): Route
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!" }
- Definition Classes
- ScalatraBase → CoreDsl
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def halt(result: ActionResult): Nothing
- Definition Classes
- Control
- def halt[T](status: Integer = null, body: T = (), headers: Map[String, String] = Map.empty): Nothing
Immediately halts processing of a request.
Immediately halts processing of a request. Can be called from either a before filter or a route.
- status
the status to set on the response, or null to leave the status unchanged.
- body
a result to render through the render pipeline as the body
- headers
headers to add to the response
- Definition Classes
- Control
- def handle(request: HttpServletRequest, response: HttpServletResponse): Unit
Handles a request and renders a response.
Handles a request and renders a response.
$ 1. If the request lacks a character encoding,
defaultCharacterEncodingis set to the request.$ 2. Sets the response's character encoding to
defaultCharacterEncoding.$ 3. Binds the current
request,response, andmultiParams, and callsexecuteRoutes().- Definition Classes
- ScalatraBase → Handler
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def head(transformers: RouteTransformer*)(action: => Any): Route
- Definition Classes
- ScalatraBase → CoreDsl
- See also
head
- def initParameter(name: String): Option[String]
Gets an init paramter from the config.
Gets an init paramter from the config.
- name
the name of the key
- returns
an option containing the value of the parameter if defined, or
Noneif the parameter is not set.
- def initialize(config: ConfigT): Unit
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
configvariable to the parameter.- config
the configuration.
- Definition Classes
- ScalatraBase → Initializable
- def invoke(matchedRoute: MatchedRoute): Option[Any]
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.
- matchedRoute
the matched route to execute
- returns
the result of the matched route's action wrapped in
Some, orNoneif the action callspass.
- Attributes
- protected
- def isAsyncExecutable(result: Any): Boolean
- Attributes
- protected
- def isDevelopmentMode: Boolean
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
environmentbegins with "dev", case-insensitive. - def isHttps(implicit request: HttpServletRequest): Boolean
- Attributes
- protected
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- implicit def lowestPriorityAny2T[T](implicit arg0: ClassTag[T]): TypeConverter[Any, T]
- Definition Classes
- LowestPriorityImplicitConversions
- def methodNotAllowed(f: (Set[HttpMethod]) => Any): Unit
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.
- Definition Classes
- ScalatraBase → CoreDsl
- def multiParams(implicit request: HttpServletRequest): MultiParams
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. - def multiParams(key: String)(implicit request: HttpServletRequest): Seq[String]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def needsHttps: Boolean
- Attributes
- protected
- def notFound(fun: => Any): Unit
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.
- Definition Classes
- ScalatraBase → CoreDsl
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def options(transformers: RouteTransformer*)(action: => Any): Route
- Definition Classes
- ScalatraBase → CoreDsl
- See also
get
- def params(implicit request: HttpServletRequest): Params
- def params(key: String)(implicit request: HttpServletRequest): String
- def pass(): Nothing
Immediately exits from the current route.
Immediately exits from the current route.
- Definition Classes
- Control
- def patch(transformers: RouteTransformer*)(action: => Any): Route
- Definition Classes
- ScalatraBase → CoreDsl
- See also
patch
- implicit def pathPatternParser2RouteMatcher(pattern: PathPattern): RouteMatcher
Path pattern is decoupled from requests.
Path pattern is decoupled from requests. This adapts the PathPattern to a RouteMatcher by supplying the request path.
- Attributes
- protected
- def post(transformers: RouteTransformer*)(action: => Any): Route
- Definition Classes
- ScalatraBase → CoreDsl
- See also
get
- def put(transformers: RouteTransformer*)(action: => Any): Route
- Definition Classes
- ScalatraBase → CoreDsl
- See also
get
- def redirect(uri: String)(implicit request: HttpServletRequest, response: HttpServletResponse): Nothing
Sends a redirect response and immediately halts the current action.
- implicit def regex2RouteMatcher(regex: Regex): RouteMatcher
Converts a regular expression to a route matcher.
Converts a regular expression to a route matcher.
- regex
the regular expression
- returns
a route matcher based on
regex
- Attributes
- protected
- See also
- def relativeUrl(path: String, params: Iterable[(String, Any)] = Iterable.empty, includeContextPath: Boolean = true, includeServletPath: Boolean = true)(implicit request: HttpServletRequest, response: HttpServletResponse): String
- def removeRoute(method: String, route: Route): Unit
- Attributes
- protected
- def removeRoute(method: HttpMethod, route: Route): Unit
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.
- Attributes
- protected
- See also
org.scalatra.ScalatraKernel#addRoute
- def renderHaltException(e: HaltException): Unit
- Attributes
- protected
- def renderPipeline: RenderPipeline
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.
- Attributes
- protected
- def renderResponse(actionResult: Any): Unit
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.
- Attributes
- protected
- def renderResponseBody(actionResult: Any): Unit
Renders the action result to the response body via the render pipeline.
Renders the action result to the response body via the render pipeline.
- Attributes
- protected
- See also
#renderPipeline
- def renderUncaughtException(e: Throwable)(implicit request: HttpServletRequest, response: HttpServletResponse): Unit
- Attributes
- protected
- implicit def request: HttpServletRequest
The currently scoped request.
The currently scoped request. Valid only inside the
handlemethod.- Definition Classes
- DynamicScope → RequestResponseScope
- implicit def response: HttpServletResponse
The currently scoped response.
The currently scoped response. Valid only inside the
handlemethod.- Definition Classes
- DynamicScope → RequestResponseScope
- lazy val routes: RouteRegistry
The routes registered in this kernel.
- def runFilters(filters: Iterable[Route]): Unit
Invokes each filters with
invoke.Invokes each filters with
invoke. The results of the filters are discarded.- Attributes
- protected
- def runRoutes(routes: Iterable[Route]): Stream[Any]
Lazily invokes routes with
invoke.Lazily invokes routes with
invoke. The results of the routes are returned as a stream.- Attributes
- protected
- implicit def safe[S, T](f: (S) => T): TypeConverter[S, T]
- Definition Classes
- TypeConverterSupport
- implicit def safeOption[S, T](f: (S) => Option[T]): TypeConverter[S, T]
Implicit convert a
(String) => Option[T]function into aTypeConverter[T]Implicit convert a
(String) => Option[T]function into aTypeConverter[T]- Definition Classes
- TypeConverterSupport
- implicit def scalatraContext: ScalatraContext
- Attributes
- protected[this]
- Definition Classes
- ScalatraContext
- implicit def seqHead[T](implicit arg0: ClassTag[T], elementConverter: TypeConverter[String, T]): TypeConverter[Seq[String], T]
- Definition Classes
- DefaultImplicitConversions
- implicit def seqToSeq[T](implicit arg0: ClassTag[T], elementConverter: TypeConverter[String, T]): TypeConverter[Seq[String], Seq[T]]
- Definition Classes
- DefaultImplicitConversions
- def serverHost(implicit request: HttpServletRequest): String
- def serverPort(implicit request: HttpServletRequest): Int
- def servletContext: ServletContext
The servlet context in which this kernel runs.
The servlet context in which this kernel runs.
- Definition Classes
- ScalatraBase → ScalatraContext
- def session(key: String)(implicit request: HttpServletRequest): Any
- Definition Classes
- SessionSupport
- implicit def session(implicit request: HttpServletRequest): HttpSession
The current session.
The current session. Creates a session if none exists.
- Definition Classes
- SessionSupport
- def sessionOption(implicit request: HttpServletRequest): Option[HttpSession]
The current session.
The current session. If none exists, None is returned.
- Definition Classes
- SessionSupport
- def setMultiparams[S](matchedRoute: Option[MatchedRoute], originalParams: MultiParams)(implicit request: HttpServletRequest): Unit
- Attributes
- protected
- def shutdown(): Unit
- Attributes
- protected
- Definition Classes
- Initializable
- def status: Int
Gets the status code of the current response.
Gets the status code of the current response.
- Definition Classes
- ScalatraContext
- def status_=(code: Int): Unit
Sets the status code of the current response.
Sets the status code of the current response.
- Definition Classes
- ScalatraContext
- implicit def string2RouteMatcher(path: String): RouteMatcher
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.
- path
a path expression
- returns
a route matcher based on
path
- Attributes
- protected
- implicit val stringToBoolean: TypeConverter[String, Boolean]
- Definition Classes
- DefaultImplicitConversions
- implicit val stringToByte: TypeConverter[String, Byte]
- Definition Classes
- DefaultImplicitConversions
- def stringToDate(format: => String): TypeConverter[String, Date]
- Definition Classes
- DefaultImplicitConversions
- def stringToDateFormat(format: => DateFormat): TypeConverter[String, Date]
- Definition Classes
- DefaultImplicitConversions
- implicit val stringToDouble: TypeConverter[String, Double]
- Definition Classes
- DefaultImplicitConversions
- implicit val stringToFloat: TypeConverter[String, Float]
- Definition Classes
- DefaultImplicitConversions
- implicit val stringToInt: TypeConverter[String, Int]
- Definition Classes
- DefaultImplicitConversions
- implicit val stringToLong: TypeConverter[String, Long]
- Definition Classes
- DefaultImplicitConversions
- implicit val stringToSelf: TypeConverter[String, String]
- Definition Classes
- DefaultImplicitConversions
- def stringToSeq[T](elementConverter: TypeConverter[String, T], separator: String = ",")(implicit arg0: ClassTag[T]): TypeConverter[String, Seq[T]]
- Definition Classes
- DefaultImplicitConversions
- implicit val stringToShort: TypeConverter[String, Short]
- Definition Classes
- DefaultImplicitConversions
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- implicit def toTypedMultiParams(params: MultiParams): TypedMultiParams
- Definition Classes
- ScalatraParamsImplicits
- implicit def toTypedParams(params: Params): TypedParams
- Definition Classes
- ScalatraParamsImplicits
- def trap(codes: Range)(block: => Any): Unit
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" } }*
}}
- Definition Classes
- ScalatraBase → CoreDsl
- def trap(code: Int)(block: => Any): Unit
- Definition Classes
- CoreDsl
- See also
error
- def url(path: String, params: Iterable[(String, Any)] = Iterable.empty, includeContextPath: Boolean = true, includeServletPath: Boolean = true, absolutize: Boolean = true, withSessionId: Boolean = true)(implicit request: HttpServletRequest, response: HttpServletResponse): String
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.encodeURLfor a session ID, if necessary.- path
the base path. If a path begins with '/', then the context path will be prepended to the result
- params
params, to be appended in the form of a query string
- returns
the path plus the query string, if any. The path is run through
response.encodeURLto add any necessary session tracking parameters.
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withRequest[A](request: HttpServletRequest)(f: => A): A
Executes the block with the given request bound to the
requestmethod.Executes the block with the given request bound to the
requestmethod.- Attributes
- protected
- Definition Classes
- DynamicScope → RequestResponseScope
- def withRequestResponse[A](request: HttpServletRequest, response: HttpServletResponse)(f: => A): A
- Attributes
- protected[scalatra]
- Definition Classes
- DynamicScope → RequestResponseScope
- def withResponse[A](response: HttpServletResponse)(f: => A): A
Executes the block with the given response bound to the
responsemethod.Executes the block with the given response bound to the
responsemethod.- Attributes
- protected
- Definition Classes
- DynamicScope → RequestResponseScope
- def withRouteMultiParams[S](matchedRoute: Option[MatchedRoute])(thunk: => S)(implicit request: HttpServletRequest): S
- Attributes
- protected[scalatra]