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 int |
activeThreadCount() |
static void |
after(Filter... filters)
Maps one or many filters to be executed after any matching routes
|
static void |
after(String path,
Filter... filters)
Maps an array of filters 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... filters)
Maps one or many filters to be executed after any matching routes
|
static void |
afterAfter(Filter filter)
Execute after any matching route even if the route throws exception
|
static void |
afterAfter(String path,
Filter filter)
Execute after route even if the route throws exception
|
static void |
awaitInitialization()
Waits for the spark server to be initialized.
|
static void |
before(Filter... filters)
Maps one or many filters to be executed before any matching routes
|
static void |
before(String path,
Filter... filters)
Maps an array of filters 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... filters)
Maps one or many filters 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 <T extends Exception> |
exception(Class<T> exceptionClass,
ExceptionHandler<? super T> 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 HaltException |
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 HaltException |
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 HaltException |
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 HaltException |
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 |
initExceptionHandler(Consumer<Exception> initExceptionHandler)
Overrides default exception handler during initialization phase
|
static void |
internalServerError(Route route)
Maps 500 internal server errors to the provided route.
|
static void |
internalServerError(String page)
Maps 500 internal server errors to the provided custom page
|
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 |
notFound(Route route)
Maps 404 Not Found errors to the provided route.
|
static void |
notFound(String page)
Maps 404 Not Found errors to the provided custom page
|
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 |
path(String path,
RouteGroup routeGroup)
Add a path-prefix to the routes declared in the routeGroup
The path() method adds a path-fragment to a path-stack, adds
routes from the routeGroup, then pops the path-fragment again.
|
static int |
port()
Retrieves the port that Spark is listening on.
|
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 |
secure(String keystoreFile,
String keystorePassword,
String truststoreFile,
String truststorePassword,
boolean needsClientCert)
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 |
webSocket(String path,
Object 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 path(String path, RouteGroup routeGroup)
path
- the path to prefix routes withrouteGroup
- group of routes (can also contain path() calls)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 before(String path, Filter... filters)
path
- the pathfilters
- the filterspublic static void after(String path, Filter filter)
path
- the pathfilter
- The filterpublic static void after(String path, Filter... filters)
path
- the pathfilters
- The filterspublic 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... filters)
filters
- The filterspublic static void after(Filter... filters)
filters
- The filterspublic static void before(String path, String acceptType, Filter... filters)
path
- the pathacceptType
- the accept typefilters
- The filterspublic static void after(String path, String acceptType, Filter... filters)
path
- the pathacceptType
- the accept typefilters
- The filterspublic static void afterAfter(String path, Filter filter)
path
- the pathfilter
- the filterpublic static void afterAfter(Filter filter)
filter
- 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 <T extends Exception> void exception(Class<T> exceptionClass, ExceptionHandler<? super T> handler)
exceptionClass
- the exception classhandler
- The handlerpublic static HaltException halt()
public static HaltException halt(int status)
status
- the status codepublic static HaltException halt(String body)
body
- The body contentpublic static HaltException 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 int port()
IllegalStateException
- when the server is not startedpublic 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 initExceptionHandler(Consumer<Exception> initExceptionHandler)
initExceptionHandler
- The custom init exception handlerpublic static void secure(String keystoreFile, String keystorePassword, String truststoreFile, String truststorePassword, boolean needsClientCert)
keystoreFile
- The keystore file location as stringkeystorePassword
- the password for the keystoretruststoreFile
- the truststore file location as string, leave null to reuse
keystoreneedsClientCert
- Whether to require client certificate to be supplied in
requesttruststorePassword
- 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 notFound(String page)
public static void internalServerError(String page)
public static void notFound(Route route)
public static void internalServerError(Route route)
public static void init()
public static ModelAndView modelAndView(Object model, String viewName)
model
- the modelviewName
- the view namepublic static int activeThreadCount()
Copyright © 2017. All rights reserved.