class ServerApplication extends Router
Configures and creates HttpServer
.
ServerApplication
is a mutable structure. With each applied change, the
application is modified and returned. After the desired settings are applied,
a server is created using one of several factory methods.
- Alphabetic
- By Inheritance
- ServerApplication
- Router
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
ServerApplication()
Creates server application.
Creates server application.
Default Configuration
Key
Value
logger
scamper.logging.ConsoleLogger
backlogSize
50
poolSize
Runtime.getRuntime().availableProcessors()
queueSize
Runtime.getRuntime().availableProcessors() * 4
bufferSize
8192
readTimeout
5000
headerLimit
100
keepAlive
(Not configured)
secure
(Not configured)
incoming
(Not configured)
outgoing
(Not configured)
error
(Sends
500 Internal Server Error
)
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
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
backlogSize(size: Int): ServerApplication.this.type
Sets backlog size.
Sets backlog size.
The
backlogSize
specifies the maximum number of incoming connections that can wait before being accepted. Incoming connections that exceed this limit are refused.- size
backlog size
- returns
this application
-
def
bufferSize(size: Int): ServerApplication.this.type
Sets buffer size.
Sets buffer size.
The
bufferSize
specifies in bytes the size of buffer used when reading from and writing to socket.The
bufferSize
also determines the maximum length of any header line. Incoming requests containing a header that exceeds this limit are sent 431 (Request Header Fields Too Large).- size
buffer size in bytes
- returns
this application
- Note
bufferSize
is also used as the optimal chunk size when writing a response with chunked transfer encoding.
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
create(host: InetAddress, port: Int): HttpServer
Creates server at given host and port.
Creates server at given host and port.
- host
host address
- port
port number
- returns
new server
-
def
create(host: String, port: Int): HttpServer
Creates server at given host and port.
Creates server at given host and port.
- host
host address
- port
port number
- returns
new server
-
def
create(port: Int): HttpServer
Creates server at given port.
Creates server at given port.
- port
port number
- returns
new server
-
def
delete(path: String)(handler: RequestHandler): ServerApplication.this.type
Adds supplied handler for DELETE requests to given router path.
Adds supplied handler for DELETE requests to given router path.
The handler is appended to existing request handler chain.
- path
router path
- handler
request handler
- returns
this router
- Definition Classes
- Router
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
error(handler: ErrorHandler): ServerApplication.this.type
Sets error handler.
Sets error handler.
- handler
error handler
- returns
this application
-
def
files(path: String, source: File): ServerApplication.this.type
Mounts file server at given path.
Mounts file server at given path.
At request time, the mount path is stripped from the router path, and the remaining path is used to locate a file in the source directory or one of its subdirectories.
File Mapping Examples
Mount Path
Source Directory
Router Path
Maps to
/images
/tmp
/images/logo.png
/tmp/logo.png
/images
/tmp
/images/icons/warning.png
/tmp/icons/warning.png
- path
router path at which directory is mounted
- source
base directory from which files are served
- returns
this router
- Definition Classes
- Router
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
get(path: String)(handler: RequestHandler): ServerApplication.this.type
Adds supplied handler for GET requests to given router path.
Adds supplied handler for GET requests to given router path.
The handler is appended to existing request handler chain.
- path
router path
- handler
request handler
- returns
this router
- Definition Classes
- Router
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
headerLimit(limit: Int): ServerApplication.this.type
Sets header limit.
Sets header limit.
The
headerLimit
specifies the maximum number of headers allowed. Incoming requests containing headers that exceed this limit are sent 431 (Request Header Fields Too Large).- limit
header limit
- returns
this application
-
def
incoming(path: String, methods: RequestMethod*)(handler: RequestHandler): ServerApplication.this.type
Adds supplied handler for requests with given path and any of supplied request methods.
Adds supplied handler for requests with given path and any of supplied request methods.
The handler is appended to existing request handler chain.
- path
request path
- methods
request methods
- handler
request handler
- returns
this application
- Definition Classes
- ServerApplication → Router
- Note
If no request methods are specified, then matches are limited to path only.
-
def
incoming(handler: RequestHandler): ServerApplication.this.type
Adds supplied request handler.
Adds supplied request handler.
The handler is appended to existing request handler chain.
- handler
request handler
- returns
this application
- Definition Classes
- ServerApplication → Router
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
keepAlive(timeout: Int, max: Int): ServerApplication.this.type
Enables persistent connections using specified timeout and max.
Enables persistent connections using specified timeout and max.
- timeout
idle timeout in seconds
- max
maximum number of requests per connection
- returns
this application
-
def
keepAlive(params: KeepAliveParameters): ServerApplication.this.type
Enables persistent connections using specified parameters.
Enables persistent connections using specified parameters.
- params
keep-alive parameters
- returns
this application
-
def
logger(logger: Logger): ServerApplication.this.type
Sets logger.
Sets logger.
- logger
logger to which server logs are written
- returns
this application
-
def
logger(file: File): ServerApplication.this.type
Sets logger to given file.
Sets logger to given file.
- file
file to which server logs are written
- returns
this application
- Note
If file exists, it is opened in append mode.
-
def
mountPath: String
Gets mount path.
Gets mount path.
- Definition Classes
- ServerApplication → Router
- Note
Mount path is always
"/"
.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
outgoing(filter: ResponseFilter): ServerApplication.this.type
Adds supplied response filter.
Adds supplied response filter.
The filter is appended to existing response filter chain.
- filter
response filter
- returns
this application
-
def
poolSize(size: Int): ServerApplication.this.type
Sets pool size.
Sets pool size.
The
poolSize
specifies the maximum number of requests processed concurrently.- size
pool size
- returns
this application
-
def
post(path: String)(handler: RequestHandler): ServerApplication.this.type
Adds supplied handler for POST requests to given router path.
Adds supplied handler for POST requests to given router path.
The handler is appended to existing request handler chain.
- path
router path
- handler
request handler
- returns
this router
- Definition Classes
- Router
-
def
put(path: String)(handler: RequestHandler): ServerApplication.this.type
Adds supplied handler for PUT requests to given router path.
Adds supplied handler for PUT requests to given router path.
The handler is appended to existing request handler chain.
- path
router path
- handler
request handler
- returns
this router
- Definition Classes
- Router
-
def
queueSize(size: Int): ServerApplication.this.type
Sets queue size.
Sets queue size.
The
queueSize
specifies the maximum number of requests that can be queued for processing. Incoming requests that exceed this limit are sent 503 (Service Unavailable).- size
queue size
- returns
this application
-
def
readTimeout(timeout: Int): ServerApplication.this.type
Sets read timeout.
Sets read timeout.
The
readTimeout
specifies how long a read from a socket blocks before it times out, whereafter 408 (Request Timeout) is sent to client.- timeout
read timeout in milliseconds
- returns
this application
-
def
reset(): ServerApplication.this.type
Resets application to default configuration.
-
def
resources(path: String, source: String, loader: ClassLoader): ServerApplication.this.type
Mounts file server (for resources) at given path.
Mounts file server (for resources) at given path.
At request time, the mount path is stripped from the router path, and the remaining path is used to locate a resource in the source directory or one of its subdirectories.
Resource Mapping Examples
Mount Path
Source Directory
Router Path
Maps to
/images
assets
/images/logo.png
assets/logo.png
/images
assets
/images/icons/warning.png
assets/icons/warning.png
- path
router path at which directory is mounted
- source
base directory from which resources are served
- loader
class loader with which resources are loaded
- returns
this router
- Definition Classes
- Router
-
def
resources(path: String, source: String): ServerApplication.this.type
Mounts file server (for resources) at given path.
Mounts file server (for resources) at given path.
At request time, the mount path is stripped from the router path, and the remaining path is used to locate a resource in the source directory or one of its subdirectories.
Resource Mapping Examples
Mount Path
Source Directory
Router Path
Maps to
/images
assets
/images/logo.png
assets/logo.png
/images
assets
/images/icons/warning.png
assets/icons/warning.png
- path
router path at which directory is mounted
- source
base directory from which resources are served
- returns
this router
- Definition Classes
- Router
- Note
The current thread's context class loader is used to load resources.
-
def
route[T](path: String)(routing: (Router) ⇒ T): ServerApplication.this.type
Adds new router at given path.
Adds new router at given path.
A new router is created and passed to routing application.
- path
router path at which new router is mounted
- routing
routing application
- returns
this router
- Definition Classes
- Router
-
def
secure(key: File, certificate: File): ServerApplication.this.type
Sets key and certificate to be used for SSL/TLS.
Sets key and certificate to be used for SSL/TLS.
- key
private key
- certificate
public key certificate
- returns
this application
-
def
secure(keyStore: File, password: Array[Char], storeType: String): ServerApplication.this.type
Sets key store to be used for SSL/TLS.
Sets key store to be used for SSL/TLS.
- keyStore
server key store
- password
key store password
- storeType
key store type (i.e., JKS, JCEKS, etc.)
- returns
this application
- Note
The password can be discarded after invoking this method.
-
def
secure(keyStore: File, password: String, storeType: String): ServerApplication.this.type
Sets key store to be used for SSL/TLS.
Sets key store to be used for SSL/TLS.
- keyStore
server key store
- password
key store password
- storeType
key store type (i.e., JKS, JCEKS, etc.)
- returns
this application
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toAbsolutePath(path: String): String
Expands supplied router path to its absolute path.
Expands supplied router path to its absolute path.
- path
router path
- Definition Classes
- Router
- Exceptions thrown
IllegalArgumentException
if router path is not*
and does not begin with/
or if it escapes mount path- Note
If
*
is supplied as router path, its absolute path is also*
.
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
websocket[T](path: String)(handler: (WebSocketSession) ⇒ T): ServerApplication.this.type
Adds WebSocket server at given router path using supplied session handler for each connection.
Adds WebSocket server at given router path using supplied session handler for each connection.
The handler is appended to existing request handler chain.
- path
WebSocket path
- handler
WebSocket session handler
- returns
this router
- Definition Classes
- Router
Provided herein is API documentation for Scamper, the HTTP library for Scala.