-
- All Implemented Interfaces:
-
io.javalin.http.Context
public final class DefaultContext implements Context
-
-
Constructor Summary
Constructors Constructor Description DefaultContext(HttpServletRequest req, HttpServletResponse res, JavalinConfig cfg, Map<String, Object> appAttributes, CompressionStrategy compressionStrategy, Long startTimeNanos, HandlerType handlerType, String matchedPath, Map<String, String> pathParamMap, String endpointHandlerPath, AtomicReference<Result<out Object>> resultReference)
-
Method Summary
Modifier and Type Method Description final Float
executionTimeMs()
final DefaultContext
changeBaseRequest(HttpServletRequest req)
final DefaultContext
update(HandlerEntry handlerEntry, String requestUri)
HttpServletRequest
req()
Servlet request HttpServletResponse
res()
Servlet response <T extends Any> T
appAttribute(String key)
Gets an attribute from the Javalin instance serving the request String
endpointHandlerPath()
Gets the endpoint path that was used to match request (null in before, available in endpoint/after) String
characterEncoding()
Try to obtain request encoding from Header.CONTENT_TYPE header CookieStore
cookieStore()
Gets cookie store used by this request HandlerType
method()
Gets the request method. HandlerType
handlerType()
Gets the handler type of the current handler String
matchedPath()
Gets the path that was used to match request (also includes before/after paths)
ByteArray
bodyAsBytes()
Gets the request body as a ByteArray. Map<String, List<String>>
formParamMap()
Gets a map with all the form param keys and values. Map<String, String>
pathParamMap()
Gets a map of all the pathParamAsClass keys and values. String
pathParam(String key)
Gets a path param by name (ex: pathParam("param"). Map<String, List<String>>
queryParamMap()
Gets a map with all the query param keys and values. ServletOutputStream
outputStream()
Gets output-stream you can write to. InputStream
resultStream()
Extracts input stream from latest result if possible <T extends Any> Context
future(CompletableFuture<T> future, Runnable launch, Consumer<T> callback)
The main entrypoint for all async related functionalities exposed by Context. CompletableFuture<?>
resultFuture()
Gets the current context result as a CompletableFuture (if set). -
Methods inherited from class io.javalin.http.Context
async, async, async, attribute, attribute, attributeMap, basicAuthCredentials, body, bodyAsClass, bodyAsInputStream, bodyStreamAsClass, bodyValidator, cachedSessionAttribute, cachedSessionAttribute, cachedSessionAttributeOrCompute, consumeSessionAttribute, contentLength, contentType, contentType, contentType, contextPath, cookie, cookie, cookie, cookie, cookieMap, formParam, formParamAsClass, formParams, fullUrl, future, future, header, header, headerAsClass, headerMap, host, html, ip, isMultipart, isMultipartFormData, json, jsonStream, path, pathParamAsClass, port, protocol, queryParam, queryParamAsClass, queryParams, queryString, redirect, redirect, removeCookie, removeCookie, render, render, result, result, result, resultString, scheme, sessionAttribute, sessionAttribute, sessionAttributeMap, status, status, status, statusCode, uploadedFile, uploadedFiles, uploadedFiles, url, userAgent, writeSeekableStream, writeSeekableStream
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
DefaultContext
DefaultContext(HttpServletRequest req, HttpServletResponse res, JavalinConfig cfg, Map<String, Object> appAttributes, CompressionStrategy compressionStrategy, Long startTimeNanos, HandlerType handlerType, String matchedPath, Map<String, String> pathParamMap, String endpointHandlerPath, AtomicReference<Result<out Object>> resultReference)
-
-
Method Detail
-
executionTimeMs
final Float executionTimeMs()
-
changeBaseRequest
final DefaultContext changeBaseRequest(HttpServletRequest req)
-
update
final DefaultContext update(HandlerEntry handlerEntry, String requestUri)
-
req
HttpServletRequest req()
Servlet request
-
res
HttpServletResponse res()
Servlet response
-
appAttribute
<T extends Any> T appAttribute(String key)
Gets an attribute from the Javalin instance serving the request
-
endpointHandlerPath
String endpointHandlerPath()
Gets the endpoint path that was used to match request (null in before, available in endpoint/after)
-
characterEncoding
String characterEncoding()
Try to obtain request encoding from Header.CONTENT_TYPE header
-
cookieStore
CookieStore cookieStore()
Gets cookie store used by this request
-
method
HandlerType method()
Gets the request method.
-
handlerType
HandlerType handlerType()
Gets the handler type of the current handler
-
matchedPath
String matchedPath()
Gets the path that was used to match request (also includes before/after paths)
-
bodyAsBytes
ByteArray bodyAsBytes()
Gets the request body as a ByteArray. Calling this method returns the body as a ByteArray. If io.javalin.JavalinConfig.maxRequestSize is set and body is bigger than its value, a io.javalin.http.HttpResponseException is throw, with status 413 CONTENT_TOO_LARGE.
-
formParamMap
Map<String, List<String>> formParamMap()
Gets a map with all the form param keys and values.
-
pathParamMap
Map<String, String> pathParamMap()
Gets a map of all the pathParamAsClass keys and values.
-
pathParam
String pathParam(String key)
Gets a path param by name (ex: pathParam("param").
Ex: If the handler path is /users/{user-id}, and a browser GETs /users/123, pathParam("user-id") will return "123"
-
queryParamMap
Map<String, List<String>> queryParamMap()
Gets a map with all the query param keys and values.
-
outputStream
ServletOutputStream outputStream()
Gets output-stream you can write to. This stream by default uses compression specified in Javalin configuration, if you're looking for raw, uncompressed servlet's output-stream, use
ctx.res().outputStream
.
-
resultStream
InputStream resultStream()
Extracts input stream from latest result if possible
-
future
<T extends Any> Context future(CompletableFuture<T> future, Runnable launch, Consumer<T> callback)
The main entrypoint for all async related functionalities exposed by Context.
- Parameters:
future
- Future represents any delayed in time result.launch
- Optional callback that provides a possibility to launch any kind of async execution in a thread-safe way.callback
- Optional callback used to process result from the specified future.
-
resultFuture
CompletableFuture<?> resultFuture()
Gets the current context result as a CompletableFuture (if set).
-
-
-