public class Javalin
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected AccessManager |
accessManager |
protected java.util.Map<java.lang.Class,java.lang.Object> |
appAttributes |
protected boolean |
autogeneratedEtagsEnabled |
protected boolean |
caseSensitiveUrls |
protected java.lang.String |
contextPath |
protected boolean |
debugLogging |
protected java.lang.String |
defaultContentType |
protected boolean |
dynamicGzipEnabled |
protected io.javalin.core.ErrorMapper |
errorMapper |
protected io.javalin.core.EventManager |
eventManager |
protected io.javalin.core.ExceptionMapper |
exceptionMapper |
protected java.util.List<io.javalin.HandlerMetaInfo> |
handlerMetaInfo |
protected boolean |
hideBanner |
protected boolean |
ignoreTrailingSlashes |
protected org.eclipse.jetty.server.Server |
jettyServer |
protected org.eclipse.jetty.server.session.SessionHandler |
jettySessionHandler |
protected long |
maxRequestCacheBodySize |
protected io.javalin.core.PathMatcher |
pathMatcher |
protected int |
port |
protected boolean |
prefer405over404 |
protected RequestLogger |
requestLogger |
protected io.javalin.core.util.SinglePageHandler |
singlePageHandler |
protected boolean |
started |
protected java.util.Set<io.javalin.staticfiles.StaticFileConfig> |
staticFileConfig |
protected java.util.function.Consumer<org.eclipse.jetty.websocket.servlet.WebSocketServletFactory> |
wsFactoryConfig |
protected io.javalin.websocket.WsPathMatcher |
wsPathMatcher |
Modifier | Constructor and Description |
---|---|
protected |
Javalin() |
protected |
Javalin(org.eclipse.jetty.server.Server jettyServer,
org.eclipse.jetty.server.session.SessionHandler jettySessionHandler) |
Modifier and Type | Method and Description |
---|---|
Javalin |
accessManager(AccessManager accessManager)
Sets the access manager for the instance.
|
Javalin |
addHandler(io.javalin.core.HandlerType httpMethod,
java.lang.String path,
Handler handler)
Adds a request handler for the specified handlerType and path to the instance.
|
Javalin |
addHandler(io.javalin.core.HandlerType handlerType,
java.lang.String path,
Handler handler,
java.util.Set<Role> roles)
Adds a request handler for the specified handlerType and path to the instance.
|
Javalin |
after(Handler handler)
Adds an AFTER request handler for all routes in the instance.
|
Javalin |
after(java.lang.String path,
Handler handler)
Adds an AFTER request handler for the specified path to the instance.
|
<T> T |
attribute(java.lang.Class<T> clazz)
Retrieve an attribute stored on the instance.
|
Javalin |
attribute(java.lang.Class clazz,
java.lang.Object obj)
Registers an attribute on the instance.
|
Javalin |
before(Handler handler)
Adds a BEFORE request handler for all routes in the instance.
|
Javalin |
before(java.lang.String path,
Handler handler)
Adds a BEFORE request handler for the specified path to the instance.
|
Javalin |
connect(java.lang.String path,
Handler handler)
Adds a CONNECT request handler for the specified path to the instance.
|
Javalin |
connect(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a CONNECT request handler with the given roles for the specified path to the instance.
|
Javalin |
contextPath(java.lang.String contextPath)
Configure instance to run on specified context path (common prefix).
|
static Javalin |
create()
Creates an instance of the application for further configuration.
|
io.javalin.core.JavalinServlet |
createServlet() |
Javalin |
defaultContentType(java.lang.String contentType)
Configure instance to use the specified content-type as a default
value for all responses.
|
Javalin |
delete(java.lang.String path,
Handler handler)
Adds a DELETE request handler for the specified path to the instance.
|
Javalin |
delete(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a DELETE request handler with the given roles for the specified path to the instance.
|
Javalin |
disableDynamicGzip()
Configure instance to not gzip dynamic responses.
|
Javalin |
disableRequestCache()
Configure instance to not cache any requests.
|
Javalin |
disableStartupBanner()
Configure instance to not show banner in logs.
|
Javalin |
dontIgnoreTrailingSlashes()
Configure instance to treat '/test/' and '/test' as different URLs.
|
Javalin |
enableAutogeneratedEtags()
Configure instance to automatically add ETags for GET requests.
|
Javalin |
enableCaseSensitiveUrls()
Configure the instance to not use lower-case paths for path matching and parsing.
|
Javalin |
enableCorsForAllOrigins()
Configure instance to accept cross origin requests for all origins.
|
Javalin |
enableCorsForOrigin(java.lang.String... origin)
Configure instance to accept cross origin requests for specified origins.
|
Javalin |
enableDebugLogging()
Configure instance to log debug information for each request.
|
Javalin |
enableRouteOverview(java.lang.String path)
Configure instance to display a visual overview of all its mapped routes
on the specified path.
|
Javalin |
enableRouteOverview(java.lang.String path,
java.util.Set<Role> permittedRoles)
Configure instance to display a visual overview of all its mapped routes
on the specified path with the specified roles
The method must be called before
start() . |
Javalin |
enableSinglePageMode(java.lang.String path,
java.lang.String filePath)
Any request that would normally result in a 404 for the path and its subpaths
instead results in a 200 with the file-content from path in classpath as response body.
|
Javalin |
enableSinglePageMode(java.lang.String path,
java.lang.String filePath,
io.javalin.staticfiles.Location location)
Any request that would normally result in a 404 for the path and its subpaths
instead results in a 200 with the file-content as response body.
|
Javalin |
enableStaticFiles(java.lang.String classpathPath)
Configure instance to serve static files from path in classpath.
|
Javalin |
enableStaticFiles(java.lang.String path,
io.javalin.staticfiles.Location location)
Configure instance to serve static files from path in the specified location.
|
Javalin |
enableWebJars()
Configure instance to serve WebJars.
|
Javalin |
error(int statusCode,
ErrorHandler errorHandler)
Adds an error mapper to the instance.
|
Javalin |
event(io.javalin.JavalinEvent javalinEvent,
EventListener eventListener)
Adds a lifecycle event listener.
|
<T extends java.lang.Exception> |
exception(java.lang.Class<T> exceptionClass,
ExceptionHandler<? super T> exceptionHandler)
Adds an exception mapper to the instance.
|
Javalin |
get(java.lang.String path,
Handler handler)
Adds a GET request handler for the specified path to the instance.
|
Javalin |
get(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a GET request handler with the given roles for the specified path to the instance.
|
java.util.List<io.javalin.HandlerMetaInfo> |
getHandlerMetaInfo()
Gets the list of HandlerMetaInfo-objects
|
Javalin |
head(java.lang.String path,
Handler handler)
Adds a HEAD request handler for the specified path to the instance.
|
Javalin |
head(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a HEAD request handler with the given roles for the specified path to the instance.
|
Javalin |
maxBodySizeForRequestCache(long bodySizeInBytes)
Configure instance to stop caching requests larger than the specified body size.
|
Javalin |
options(java.lang.String path,
Handler handler)
Adds a OPTIONS request handler for the specified path to the instance.
|
Javalin |
options(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a OPTIONS request handler with the given roles for the specified path to the instance.
|
Javalin |
patch(java.lang.String path,
Handler handler)
Adds a PATCH request handler for the specified path to the instance.
|
Javalin |
patch(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a PATCH request handler with the given roles for the specified path to the instance.
|
int |
port()
Get which port instance is running on
Mostly useful if you start the instance with port(0) (random port)
|
Javalin |
port(int port)
Configure instance to run on specified port.
|
Javalin |
post(java.lang.String path,
Handler handler)
Adds a POST request handler for the specified path to the instance.
|
Javalin |
post(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a POST request handler with the given roles for the specified path to the instance.
|
Javalin |
prefer405over404()
Configure the instance to return 405 (Method Not Allowed) instead of 404 (Not Found) whenever a request method doesn't exists but there are handlers for other methods on the same requested path.
|
Javalin |
put(java.lang.String path,
Handler handler)
Adds a PUT request handler for the specified path to the instance.
|
Javalin |
put(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a PUT request handler with the given roles for the specified path to the instance.
|
Javalin |
register(Extension extension)
Registers an
Extension with the instance. |
Javalin |
requestLogger(RequestLogger requestLogger)
Configure instance use specified request-logger
The method must be called before
start() . |
Javalin |
routes(EndpointGroup endpointGroup)
Creates a temporary static instance in the scope of the endpointGroup.
|
Javalin |
server(java.util.function.Supplier<org.eclipse.jetty.server.Server> server)
Configure instance to use a custom jetty Server.
|
Javalin |
sessionHandler(java.util.function.Supplier<org.eclipse.jetty.server.session.SessionHandler> sessionHandler)
Configure instance to use a custom jetty SessionHandler.
|
Javalin |
sse(java.lang.String path,
java.util.function.Consumer<SseClient> client)
Adds a lambda handler for a Server Sent Event connection on the specified path.
|
Javalin |
sse(java.lang.String path,
java.util.function.Consumer<SseClient> client,
java.util.Set<Role> permittedRoles)
Adds a lambda handler for a Server Sent Event connection on the specified path.
|
Javalin |
start()
Synchronously starts the application instance.
|
Javalin |
start(int port)
Synchronously starts the application instance on the specified port.
|
Javalin |
stop()
Synchronously stops the application instance.
|
Javalin |
trace(java.lang.String path,
Handler handler)
Adds a TRACE request handler for the specified path to the instance.
|
Javalin |
trace(java.lang.String path,
Handler handler,
java.util.Set<Role> permittedRoles)
Adds a TRACE request handler with the given roles for the specified path to the instance.
|
Javalin |
ws(java.lang.String path,
java.util.function.Consumer<WsHandler> ws)
Adds a WebSocket handler on the specified path.
|
Javalin |
wsFactoryConfig(java.util.function.Consumer<org.eclipse.jetty.websocket.servlet.WebSocketServletFactory> wsFactoryConfig)
Configure the WebSocketServletFactory of the instance
The method must be called before
start() . |
Javalin |
wsLogger(java.util.function.Consumer<WsHandler> ws)
Configures a web socket handler to be called after every web socket event
The method must be called before
start() . |
protected org.eclipse.jetty.server.Server jettyServer
protected org.eclipse.jetty.server.session.SessionHandler jettySessionHandler
protected java.util.Set<io.javalin.staticfiles.StaticFileConfig> staticFileConfig
protected boolean ignoreTrailingSlashes
protected int port
protected java.lang.String contextPath
protected java.lang.String defaultContentType
protected long maxRequestCacheBodySize
protected boolean debugLogging
protected boolean dynamicGzipEnabled
protected boolean autogeneratedEtagsEnabled
protected boolean hideBanner
protected boolean prefer405over404
protected boolean caseSensitiveUrls
protected boolean started
protected AccessManager accessManager
protected RequestLogger requestLogger
protected io.javalin.core.util.SinglePageHandler singlePageHandler
protected io.javalin.core.PathMatcher pathMatcher
protected io.javalin.websocket.WsPathMatcher wsPathMatcher
protected io.javalin.core.ExceptionMapper exceptionMapper
protected io.javalin.core.ErrorMapper errorMapper
protected io.javalin.core.EventManager eventManager
protected java.util.List<io.javalin.HandlerMetaInfo> handlerMetaInfo
protected java.util.Map<java.lang.Class,java.lang.Object> appAttributes
protected java.util.function.Consumer<org.eclipse.jetty.websocket.servlet.WebSocketServletFactory> wsFactoryConfig
protected Javalin(org.eclipse.jetty.server.Server jettyServer, org.eclipse.jetty.server.session.SessionHandler jettySessionHandler)
protected Javalin()
public static Javalin create()
start()
is called.start()
,
start(int)
public Javalin start(int port)
public Javalin start()
create()
@NotNull public io.javalin.core.JavalinServlet createServlet()
public Javalin stop()
public Javalin prefer405over404()
start()
.public Javalin enableCaseSensitiveUrls()
start()
.public Javalin disableStartupBanner()
start()
.public Javalin dontIgnoreTrailingSlashes()
start()
.public Javalin server(@NotNull java.util.function.Supplier<org.eclipse.jetty.server.Server> server)
public Javalin sessionHandler(@NotNull java.util.function.Supplier<org.eclipse.jetty.server.session.SessionHandler> sessionHandler)
start()
.public Javalin wsFactoryConfig(@NotNull java.util.function.Consumer<org.eclipse.jetty.websocket.servlet.WebSocketServletFactory> wsFactoryConfig)
start()
.public Javalin enableStaticFiles(@NotNull java.lang.String classpathPath)
start()
.public Javalin enableStaticFiles(@NotNull java.lang.String path, @NotNull io.javalin.staticfiles.Location location)
start()
.public Javalin enableWebJars()
start()
.public Javalin enableSinglePageMode(@NotNull java.lang.String path, @NotNull java.lang.String filePath)
start()
.public Javalin enableSinglePageMode(@NotNull java.lang.String path, @NotNull java.lang.String filePath, @NotNull io.javalin.staticfiles.Location location)
start()
.public Javalin contextPath(@NotNull java.lang.String contextPath)
start()
.public int port()
public Javalin port(int port)
start()
.public Javalin enableDebugLogging()
start()
.public Javalin requestLogger(@NotNull RequestLogger requestLogger)
start()
.
Will override the default logger of enableDebugLogging()
.public Javalin enableCorsForOrigin(@NotNull java.lang.String... origin)
start()
.public Javalin enableCorsForAllOrigins()
start()
.public Javalin disableDynamicGzip()
start()
.public Javalin enableAutogeneratedEtags()
start()
.public Javalin enableRouteOverview(@NotNull java.lang.String path)
start()
.public Javalin enableRouteOverview(@NotNull java.lang.String path, @NotNull java.util.Set<Role> permittedRoles)
start()
.public Javalin defaultContentType(@NotNull java.lang.String contentType)
start()
.public Javalin maxBodySizeForRequestCache(long bodySizeInBytes)
start()
.public Javalin attribute(java.lang.Class clazz, java.lang.Object obj)
Context
through Context.appAttribute(java.lang.Class<T>)
.
Ex: app.attribute(MyExt.class, myExtInstance())
The method must be called before start()
.public <T> T attribute(java.lang.Class<T> clazz)
Context
through Context.appAttribute(java.lang.Class<T>)
.
Ex: app.attribute(MyExt.class).myMethod()
Ex: ctx.appAttribute(MyExt.class).myMethod()public Javalin disableRequestCache()
start()
.public Javalin accessManager(@NotNull AccessManager accessManager)
start()
.AccessManager
public <T extends java.lang.Exception> Javalin exception(@NotNull java.lang.Class<T> exceptionClass, @NotNull ExceptionHandler<? super T> exceptionHandler)
public Javalin event(@NotNull io.javalin.JavalinEvent javalinEvent, @NotNull EventListener eventListener)
start()
.public Javalin wsLogger(@NotNull java.util.function.Consumer<WsHandler> ws)
start()
.
Will override the default logger of enableDebugLogging()
.public Javalin error(int statusCode, @NotNull ErrorHandler errorHandler)
public Javalin register(Extension extension)
Extension
with the instance.
You're free to implement the extension as a class or a lambda expressionpublic Javalin routes(@NotNull EndpointGroup endpointGroup)
ApiBuilder
public Javalin addHandler(@NotNull io.javalin.core.HandlerType handlerType, @NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> roles)
public Javalin addHandler(@NotNull io.javalin.core.HandlerType httpMethod, @NotNull java.lang.String path, @NotNull Handler handler)
public Javalin get(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin post(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin put(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin patch(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin delete(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin head(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin trace(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin connect(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin options(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin get(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin post(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin put(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin patch(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin delete(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin head(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin trace(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin connect(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin options(@NotNull java.lang.String path, @NotNull Handler handler, @NotNull java.util.Set<Role> permittedRoles)
public Javalin before(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin before(@NotNull Handler handler)
public Javalin after(@NotNull java.lang.String path, @NotNull Handler handler)
public Javalin after(@NotNull Handler handler)
public Javalin ws(@NotNull java.lang.String path, @NotNull java.util.function.Consumer<WsHandler> ws)
public java.util.List<io.javalin.HandlerMetaInfo> getHandlerMetaInfo()
public Javalin sse(@NotNull java.lang.String path, @NotNull java.util.function.Consumer<SseClient> client)
Copyright © 2019. All Rights Reserved.