Packages

p

org.scalatra

servlet

package servlet

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. servlet
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait AsyncSupport extends ServletBase with ScalatraAsyncSupport
  2. trait AttributesMap extends Map[String, Any] with MutableMapWithIndifferentAccess[Any]

    Adapts attributes from servlet objects (e.g., ServletRequest, HttpSession, ServletContext) to a mutable map.

  3. case class FileItem (part: Part) extends Product with Serializable
  4. class FileMultiParams extends Map[String, Seq[FileItem]]
  5. trait FileUploadSupport extends ServletBase with HasMultipartConfig

    FileUploadSupport can be mixed into a org.scalatra.ScalatraFilter or org.scalatra.ScalatraServlet to provide easy access to data submitted as part of a multipart HTTP request.

    FileUploadSupport can be mixed into a org.scalatra.ScalatraFilter or org.scalatra.ScalatraServlet to provide easy access to data submitted as part of a multipart HTTP request. Commonly this is used for retrieving uploaded files.

    Once the trait has been mixed into your handler, you need to enable multipart configuration in your web.xml or by using @MultipartConfig annotation. To configure in web.xml add <multipart-config /> to your <servlet> element. If you prefer annotations instead, place @MultipartConfig to your handler. Both ways provide some further configuration options, such as specifying the max total request size and max size for invidual files in the request. You might want to set these to prevent users from uploading too large files.

    When the configuration has been done, you can access any files using fileParams("myFile") where myFile is the name of the parameter used to upload the file being retrieved. If you are expecting multiple files with the same name, you can use fileMultiParams("files[]") to access them all.

    To handle any errors that are caused by multipart handling, you need to configure an error handler to your handler class:

    import org.scalatra.servlet.SizeLimitExceededException
    import org.scalatra.servlet.FileUploadSupport
    
    @MultipartConfig(maxFileSize=1024*1024)
    class FileEaterServlet extends ScalatraServlet with FileUploadSupport {
      error {
        case e: SizeConstrainttExceededException => "Oh, too much! Can't take it all."
        case e: IOException                      => "Server denied me my meal, thanks anyway."
      }
    
      post("/eatfile") {
        "Thanks! You just provided me " + fileParams("lunch").size + " bytes for a lunch."
      }
    }

    }}* @note Once any handler with FileUploadSupport has accessed the request, the fileParams returned by FileUploadSupport will remain fixed for the lifetime of the request.

    Note

    Will not work on Jetty versions prior to 8.1.3. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=376324. The old scalatra-fileupload module still works for earlier versions of Jetty.

  6. trait HasMultipartConfig extends Initializable
  7. case class HttpServletRequestReadOnly (originalRequest: HttpServletRequest) extends HttpServletRequestWrapper with Product with Serializable

    Read-only immutable wrapper for an HttpServletRequest that can, for the most part, be passed around to different threads.

    Read-only immutable wrapper for an HttpServletRequest that can, for the most part, be passed around to different threads.

    This is necessary because ServletContainers will "recycle" a request once the original HTTP thread is returned, meaning that a lot of attributes are set to null (in the case of Jetty).

    Limitations of this class include the following:

    • it is mostly immutable (methods on the original request are not given stable values, nor are methods that return non-primitive types)
    • changes made to the original object or this object may not be reflected across threads
    originalRequest

    the original HttpServletRequest to wrap

  8. trait MountConfig extends AnyRef
  9. case class MultipartConfig (location: Option[String] = None, maxFileSize: Option[Long] = None, maxRequestSize: Option[Long] = None, fileSizeThreshold: Option[Int] = None) extends MountConfig with Product with Serializable
  10. case class RichRequest (r: HttpServletRequest) extends AttributesMap with Product with Serializable
  11. case class RichResponse (res: HttpServletResponse) extends Product with Serializable
  12. case class RichServletContext (sc: ServletContext) extends AttributesMap with Product with Serializable

    Extension methods to the standard ServletContext.

  13. case class RichSession (session: HttpSession) extends AttributesMap with Product with Serializable

    Extension methods to the standard HttpSession.

  14. trait ScalatraAsyncSupport extends AnyRef
  15. class ScalatraListener extends ServletContextListener
  16. trait ServletApiImplicits extends AnyRef
  17. trait ServletBase extends ScalatraBase with SessionSupport with Initializable

    ServletBase implements the Scalatra DSL with the Servlet API, and can be a base trait of a Servlet or a Filter.

  18. class SizeConstraintExceededException extends Exception

Inherited from AnyRef

Inherited from Any

Ungrouped