-
- All Implemented Interfaces:
public abstract class WsContext
The WsContext class holds Jetty's Session and provides (convenient) delegate methods. It adds functionality similar to the API found in io.javalin.http.Context. It also adds a send method, which calls RemoteEndpoint.sendString on Session.getRemote
-
-
Method Summary
Modifier and Type Method Description final String
getSessionId()
final String
matchedPath()
Returns the path that was used to match this request final <T extends Any> Unit
sendAsClass(T message)
Reified version of sendAsClass (Kotlin only) final Unit
sendAsClass(Object message, Type type)
Serializes object to a JSON-string using the registered io.javalin.json.JsonMapper and sends it over the socket final Unit
send(Object message)
Serializes object to a JSON-string using the registered io.javalin.json.JsonMapper and sends it over the socket final Unit
send(String message)
Sends a String over the socket final Unit
send(ByteBuffer message)
Sends a ByteBuffer over the socket final Unit
sendPing(ByteBuffer applicationData)
Sends a ping over the socket final Unit
sendPing()
Sends a ping over the socket final Unit
enableAutomaticPings(Long interval, TimeUnit unit, ByteBuffer applicationData)
Enables automatic pings at the specified interval, preventing the connection from timing out final Unit
enableAutomaticPings(Long interval, TimeUnit unit)
Enables automatic pings at the specified interval, preventing the connection from timing out final Unit
enableAutomaticPings(Long interval)
Enables automatic pings at the specified interval, preventing the connection from timing out final Unit
enableAutomaticPings()
Enables automatic pings at the specified interval, preventing the connection from timing out final Unit
disableAutomaticPings()
Disables automatic pings final String
queryString()
Returns the full query String, or null if no query is present final Map<String, List<String>>
queryParamMap()
Returns a Map of all the query parameters final List<String>
queryParams(String key)
Returns a List of all the query parameters for the given key, or an empty List if no such parameter exists final String
queryParam(String key)
Returns the first query parameter for the given key, or null if no such parameter exists final <T extends Any> Validator<T>
queryParamAsClass(String key, Class<T> clazz)
Creates a typed io.javalin.validation.Validator for the queryParam value final <T extends Any> Validator<T>
queryParamAsClass(String key)
Reified version of queryParamAsClass (Kotlin only) final Map<String, String>
pathParamMap()
Returns a Map of all the path parameters final String
pathParam(String key)
Returns a path param by name (ex: pathParam("param")). final <T extends Any> Validator<T>
pathParamAsClass(String key, Class<T> clazz)
Creates a typed io.javalin.validation.Validator for the pathParam value final <T extends Any> Validator<T>
pathParamAsClass(String key)
Reified version of pathParamAsClass (Kotlin only) final String
host()
Returns the host as a String final String
header(String header)
Gets a request header by name, or null. final Map<String, String>
headerMap()
Gets a Map with all the header keys and values final <T extends Any> Validator<T>
headerAsClass(String header, Class<T> clazz)
Creates a typed io.javalin.validation.Validator for the header value final String
cookie(String name)
Gets a request cookie by name, or null. final Map<String, String>
cookieMap()
Gets a Map with all the request cookies final Unit
attribute(String key, Object value)
Sets an attribute on the request. final <T extends Any> T
attribute(String key)
Gets the specified attribute from the request. final Map<String, Object>
attributeMap()
Gets a Map with all the attribute keys and values on the request final <T extends Any> T
sessionAttribute(String key)
Gets a session attribute by name final Map<String, Object>
sessionAttributeMap()
Gets a Map with all the session attributes final Unit
closeSession()
Close the session final Unit
closeSession(CloseStatus closeStatus)
Close the session with a CloseStatus final Unit
closeSession(Integer code, String reason)
Close the session with a code and reason Boolean
equals(Object other)
Integer
hashCode()
-
-
Constructor Detail
-
WsContext
WsContext(String sessionId, Session session)
-
-
Method Detail
-
getSessionId
final String getSessionId()
-
matchedPath
final String matchedPath()
Returns the path that was used to match this request
-
sendAsClass
final <T extends Any> Unit sendAsClass(T message)
Reified version of sendAsClass (Kotlin only)
-
sendAsClass
final Unit sendAsClass(Object message, Type type)
Serializes object to a JSON-string using the registered io.javalin.json.JsonMapper and sends it over the socket
-
send
final Unit send(Object message)
Serializes object to a JSON-string using the registered io.javalin.json.JsonMapper and sends it over the socket
-
send
final Unit send(ByteBuffer message)
Sends a ByteBuffer over the socket
-
sendPing
@JvmOverloads() final Unit sendPing(ByteBuffer applicationData)
Sends a ping over the socket
-
sendPing
@JvmOverloads() final Unit sendPing()
Sends a ping over the socket
-
enableAutomaticPings
@JvmOverloads() final Unit enableAutomaticPings(Long interval, TimeUnit unit, ByteBuffer applicationData)
Enables automatic pings at the specified interval, preventing the connection from timing out
-
enableAutomaticPings
@JvmOverloads() final Unit enableAutomaticPings(Long interval, TimeUnit unit)
Enables automatic pings at the specified interval, preventing the connection from timing out
-
enableAutomaticPings
@JvmOverloads() final Unit enableAutomaticPings(Long interval)
Enables automatic pings at the specified interval, preventing the connection from timing out
-
enableAutomaticPings
@JvmOverloads() final Unit enableAutomaticPings()
Enables automatic pings at the specified interval, preventing the connection from timing out
-
disableAutomaticPings
final Unit disableAutomaticPings()
Disables automatic pings
-
queryString
final String queryString()
Returns the full query String, or null if no query is present
-
queryParamMap
final Map<String, List<String>> queryParamMap()
Returns a Map of all the query parameters
-
queryParams
final List<String> queryParams(String key)
-
queryParam
final String queryParam(String key)
Returns the first query parameter for the given key, or null if no such parameter exists
-
queryParamAsClass
final <T extends Any> Validator<T> queryParamAsClass(String key, Class<T> clazz)
Creates a typed io.javalin.validation.Validator for the queryParam value
-
queryParamAsClass
final <T extends Any> Validator<T> queryParamAsClass(String key)
Reified version of queryParamAsClass (Kotlin only)
-
pathParamMap
final Map<String, String> pathParamMap()
Returns a Map of all the path parameters
-
pathParam
final String pathParam(String key)
Returns 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"
-
pathParamAsClass
final <T extends Any> Validator<T> pathParamAsClass(String key, Class<T> clazz)
Creates a typed io.javalin.validation.Validator for the pathParam value
-
pathParamAsClass
final <T extends Any> Validator<T> pathParamAsClass(String key)
Reified version of pathParamAsClass (Kotlin only)
-
headerAsClass
final <T extends Any> Validator<T> headerAsClass(String header, Class<T> clazz)
Creates a typed io.javalin.validation.Validator for the header value
-
attribute
final Unit attribute(String key, Object value)
Sets an attribute on the request. Attributes are available to other handlers in the request lifecycle.
-
attribute
final <T extends Any> T attribute(String key)
Gets the specified attribute from the request.
-
attributeMap
final Map<String, Object> attributeMap()
Gets a Map with all the attribute keys and values on the request
-
sessionAttribute
final <T extends Any> T sessionAttribute(String key)
Gets a session attribute by name
-
sessionAttributeMap
final Map<String, Object> sessionAttributeMap()
Gets a Map with all the session attributes
-
closeSession
final Unit closeSession()
Close the session
-
closeSession
final Unit closeSession(CloseStatus closeStatus)
Close the session with a CloseStatus
-
closeSession
final Unit closeSession(Integer code, String reason)
Close the session with a code and reason
-
-
-
-