public class Spark extends Object
Modifier and Type | Field and Description |
---|---|
static Redirect |
redirect
Statically import this for redirect utility functionality, see
Redirect |
static Service.StaticFiles |
staticFiles
Statically import this for static files utility functionality, see
Service.StaticFiles |
Modifier | Constructor and Description |
---|---|
protected |
Spark() |
Modifier and Type | Method and Description |
---|---|
static void |
after(Filter filter)
Maps a filter to be executed after any matching routes
|
static void |
after(String path,
Filter filter)
Maps a filter to be executed after any matching routes
|
static void |
after(String path,
String acceptType,
Filter filter)
Maps a filter to be executed after any matching routes
|
static void |
awaitInitialization()
Waits for the spark server to be initialized.
|
static void |
before(Filter filter)
Maps a filter to be executed before any matching routes
|
static void |
before(String path,
Filter filter)
Maps a filter to be executed before any matching routes
|
static void |
before(String path,
String acceptType,
Filter filter)
Maps a filter to be executed before any matching routes
|
static void |
connect(String path,
Route route)
Map the route for HTTP CONNECT requests
|
static void |
connect(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP CONNECT requests
|
static void |
connect(String path,
String acceptType,
Route route)
Map the route for HTTP CONNECT requests
|
static void |
connect(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP CONNECT requests
|
static void |
connect(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP CONNECT requests
|
static void |
connect(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP CONNECT requests
|
static void |
delete(String path,
Route route)
Map the route for HTTP DELETE requests
|
static void |
delete(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP DELETE requests
|
static void |
delete(String path,
String acceptType,
Route route)
Map the route for HTTP DELETE requests
|
static void |
delete(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP DELETE requests
|
static void |
delete(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP DELETE requests
|
static void |
delete(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP DELETE requests
|
static void |
exception(Class<? extends Exception> exceptionClass,
ExceptionHandler handler)
Maps an exception handler to be executed when an exception occurs during routing
|
static void |
externalStaticFileLocation(String externalFolder)
Sets the external folder serving static files.
|
static void |
get(String path,
Route route)
Map the route for HTTP GET requests
|
static void |
get(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP GET requests
|
static void |
get(String path,
String acceptType,
Route route)
Map the route for HTTP GET requests
|
static void |
get(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP GET requests
|
static void |
get(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP GET requests
|
static void |
get(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP GET requests
|
static void |
halt()
Immediately stops a request within a filter or route
NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise
halt will not work
|
static void |
halt(int status)
Immediately stops a request within a filter or route with specified status code
NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise
halt will not work
|
static void |
halt(int status,
String body)
Immediately stops a request within a filter or route with specified status code and body content
NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise
halt will not work
|
static void |
halt(String body)
Immediately stops a request within a filter or route with specified body content
NOTE: When using this don't catch exceptions of type HaltException, or if catched, re-throw otherwise
halt will not work
|
static void |
head(String path,
Route route)
Map the route for HTTP HEAD requests
|
static void |
head(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP HEAD requests
|
static void |
head(String path,
String acceptType,
Route route)
Map the route for HTTP HEAD requests
|
static void |
head(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP HEAD requests
|
static void |
head(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP HEAD requests
|
static void |
head(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP HEAD requests
|
static void |
init()
Initializes the Spark server.
|
static void |
ipAddress(String ipAddress)
Set the IP address that Spark should listen on.
|
static ModelAndView |
modelAndView(Object model,
String viewName)
Constructs a ModelAndView with the provided model and view name
|
static void |
options(String path,
Route route)
Map the route for HTTP OPTIONS requests
|
static void |
options(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP OPTIONS requests
|
static void |
options(String path,
String acceptType,
Route route)
Map the route for HTTP OPTIONS requests
|
static void |
options(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP OPTIONS requests
|
static void |
options(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP OPTIONS requests
|
static void |
options(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP OPTIONS requests
|
static void |
patch(String path,
Route route)
Map the route for HTTP PATCH requests
|
static void |
patch(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP PATCH requests
|
static void |
patch(String path,
String acceptType,
Route route)
Map the route for HTTP PATCH requests
|
static void |
patch(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP PATCH requests
|
static void |
patch(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP PATCH requests
|
static void |
patch(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP PATCH requests
|
static void |
port(int port)
Set the port that Spark should listen on.
|
static void |
post(String path,
Route route)
Map the route for HTTP POST requests
|
static void |
post(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP POST requests
|
static void |
post(String path,
String acceptType,
Route route)
Map the route for HTTP POST requests
|
static void |
post(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP POST requests
|
static void |
post(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP POST requests
|
static void |
post(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP POST requests
|
static void |
put(String path,
Route route)
Map the route for HTTP PUT requests
|
static void |
put(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP PUT requests
|
static void |
put(String path,
String acceptType,
Route route)
Map the route for HTTP PUT requests
|
static void |
put(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP PUT requests
|
static void |
put(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP PUT requests
|
static void |
put(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP PUT requests
|
static void |
secure(String keystoreFile,
String keystorePassword,
String truststoreFile,
String truststorePassword)
Set the connection to be secure, using the specified keystore and
truststore.
|
static void |
setIpAddress(String ipAddress)
Deprecated.
replaced by
ipAddress(String) |
static void |
setPort(int port)
Deprecated.
replaced by
port(int) |
static void |
setSecure(String keystoreFile,
String keystorePassword,
String truststoreFile,
String truststorePassword)
Deprecated.
replaced by
secure(String, String, String, String) |
static void |
staticFileLocation(String folder)
Sets the folder in classpath serving static files.
|
static void |
stop()
Stops the Spark server and clears all routes
|
static void |
threadPool(int maxThreads)
Configures the embedded web server's thread pool.
|
static void |
threadPool(int maxThreads,
int minThreads,
int idleTimeoutMillis)
Configures the embedded web server's thread pool.
|
static void |
trace(String path,
Route route)
Map the route for HTTP TRACE requests
|
static void |
trace(String path,
Route route,
ResponseTransformer transformer)
Map the route for HTTP TRACE requests
|
static void |
trace(String path,
String acceptType,
Route route)
Map the route for HTTP TRACE requests
|
static void |
trace(String path,
String acceptType,
Route route,
ResponseTransformer transformer)
Map the route for HTTP TRACE requests
|
static void |
trace(String path,
String acceptType,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP TRACE requests
|
static void |
trace(String path,
TemplateViewRoute route,
TemplateEngine engine)
Map the route for HTTP TRACE requests
|
static void |
webSocket(String path,
Class<?> handler)
Maps the given path to the given WebSocket handler.
|
static void |
webSocketIdleTimeoutMillis(int timeoutMillis)
Sets the max idle timeout in milliseconds for WebSocket connections.
|
public static final Redirect redirect
Redirect
public static final Service.StaticFiles staticFiles
Service.StaticFiles
public static void get(String path, Route route)
path
- the pathroute
- The routepublic static void post(String path, Route route)
path
- the pathroute
- The routepublic static void put(String path, Route route)
path
- the pathroute
- The routepublic static void patch(String path, Route route)
path
- the pathroute
- The routepublic static void delete(String path, Route route)
path
- the pathroute
- The routepublic static void head(String path, Route route)
path
- the pathroute
- The routepublic static void trace(String path, Route route)
path
- the pathroute
- The routepublic static void connect(String path, Route route)
path
- the pathroute
- The routepublic static void options(String path, Route route)
path
- the pathroute
- The routepublic static void before(String path, Filter filter)
path
- the pathfilter
- The filterpublic static void after(String path, Filter filter)
path
- the pathfilter
- The filterpublic static void get(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void post(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void put(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void patch(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void delete(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void head(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void trace(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void connect(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void options(String path, String acceptType, Route route)
path
- the pathacceptType
- the accept typeroute
- The routepublic static void before(Filter filter)
filter
- The filterpublic static void after(Filter filter)
filter
- The filterpublic static void before(String path, String acceptType, Filter filter)
path
- the pathacceptType
- the accept typefilter
- The filterpublic static void after(String path, String acceptType, Filter filter)
path
- the pathacceptType
- the accept typefilter
- The filterpublic static void get(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void get(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void post(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void post(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void put(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void put(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void delete(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void delete(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void patch(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void patch(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void head(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void head(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void trace(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void trace(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void connect(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void connect(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void options(String path, TemplateViewRoute route, TemplateEngine engine)
path
- the pathroute
- The routeengine
- the template enginepublic static void options(String path, String acceptType, TemplateViewRoute route, TemplateEngine engine)
path
- the pathacceptType
- the accept typeroute
- The routeengine
- the template enginepublic static void get(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void get(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void post(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void post(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void put(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void put(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void delete(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void delete(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void head(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void head(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void connect(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void connect(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void trace(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void trace(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void options(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void options(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void patch(String path, Route route, ResponseTransformer transformer)
path
- the pathroute
- The routetransformer
- the response transformerpublic static void patch(String path, String acceptType, Route route, ResponseTransformer transformer)
path
- the pathacceptType
- the accept typeroute
- The routetransformer
- the response transformerpublic static void exception(Class<? extends Exception> exceptionClass, ExceptionHandler handler)
exceptionClass
- the exception classhandler
- The handlerpublic static void halt()
public static void halt(int status)
status
- the status codepublic static void halt(String body)
body
- The body contentpublic static void halt(int status, String body)
status
- The status codebody
- The body contentpublic static void setIpAddress(String ipAddress)
ipAddress(String)
ipAddress
- The ipAddresspublic static void ipAddress(String ipAddress)
ipAddress
- The ipAddresspublic static void setPort(int port)
port(int)
port
- The port numberpublic static void port(int port)
port
- The port numberpublic static void setSecure(String keystoreFile, String keystorePassword, String truststoreFile, String truststorePassword)
secure(String, String, String, String)
keystoreFile
- The keystore file location as stringkeystorePassword
- the password for the keystoretruststoreFile
- the truststore file location as string, leave null to reuse
keystoretruststorePassword
- the trust store passwordpublic static void secure(String keystoreFile, String keystorePassword, String truststoreFile, String truststorePassword)
keystoreFile
- The keystore file location as stringkeystorePassword
- the password for the keystoretruststoreFile
- the truststore file location as string, leave null to reuse
keystoretruststorePassword
- the trust store passwordpublic static void threadPool(int maxThreads)
maxThreads
- max nbr of threads.public static void threadPool(int maxThreads, int minThreads, int idleTimeoutMillis)
maxThreads
- max nbr of threads.minThreads
- min nbr of threads.idleTimeoutMillis
- thread idle timeout (ms).public static void staticFileLocation(String folder)
Service.StaticFiles
folder
- the folder in classpath.public static void externalStaticFileLocation(String externalFolder)
Service.StaticFiles
externalFolder
- the external folder serving static files.public static void awaitInitialization()
public static void stop()
public static void webSocket(String path, Class<?> handler)
This is currently only available in the embedded server mode.
path
- the WebSocket path.handler
- the handler class that will manage the WebSocket connection to the given path.public static void webSocketIdleTimeoutMillis(int timeoutMillis)
timeoutMillis
- The max idle timeout in milliseconds.public static void init()
public static ModelAndView modelAndView(Object model, String viewName)
model
- the modelviewName
- the view nameCopyright © 2016. All rights reserved.