Package org.glassfish.tyrus.core
Class RequestContext
- java.lang.Object
-
- org.glassfish.tyrus.spi.UpgradeRequest
-
- org.glassfish.tyrus.core.RequestContext
-
- All Implemented Interfaces:
HandshakeRequest
public final class RequestContext extends UpgradeRequest
Implementation of all possible request interfaces. Should be the only point of truth.- Author:
- Pavel Bucek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RequestContext.Builder
RequestContext
builder.
-
Field Summary
-
Fields inherited from class org.glassfish.tyrus.spi.UpgradeRequest
AUTHORIZATION, CLUSTER_CONNECTION_ID_HEADER, CONNECTION, ENABLE_TRACING_HEADER, HOST, ORIGIN_HEADER, RESPONSE_CODE_MESSAGE, SEC_WS_ORIGIN_HEADER, SERVER_KEY_HASH, TRACING_THRESHOLD, UPGRADE, WEBSOCKET
-
Fields inherited from interface jakarta.websocket.server.HandshakeRequest
SEC_WEBSOCKET_EXTENSIONS, SEC_WEBSOCKET_KEY, SEC_WEBSOCKET_PROTOCOL, SEC_WEBSOCKET_VERSION
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getHeader(java.lang.String name)
Returns the header value corresponding to the name.java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getHeaders()
Get headers.java.lang.Object
getHttpSession()
Return a reference to the HttpSession that the web socket handshake that started this conversation was part of, if the implementation is part of a Java EE web container.java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getParameterMap()
Return the request parameters associated with the request.java.lang.String
getQueryString()
Return the query string associated with the request.java.lang.String
getRemoteAddr()
Get the Internet Protocol (IP) address of the client or last proxy that sent the request.java.lang.String
getRequestUri()
Get the undecoded request uri (up to the query string) of underlying HTTP handshake request.java.net.URI
getRequestURI()
Return the request URI of the handshake request.java.lang.String
getServerAddr()
Returns the host name of the server to which the request was sent.int
getServerPort()
Get the port of the last client or proxy that sent the request.java.security.Principal
getUserPrincipal()
Return the authenticated user ornull
if no user is authenticated for this handshake.boolean
isSecure()
Indicates whether this request was made using a secure channel (such as HTTPS).boolean
isUserInRole(java.lang.String role)
Checks whether the current user is in the given role.void
lock()
Make headers and parameter map read-only.
-
-
-
Method Detail
-
getHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
Get headers.- Returns:
- headers map. List items are corresponding to header declaration in HTTP request.
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Returns the header value corresponding to the name.- Specified by:
getHeader
in classUpgradeRequest
- Parameters:
name
- header name.- Returns:
List
of header values iff found,null
otherwise.
-
lock
public void lock()
Make headers and parameter map read-only.
-
getUserPrincipal
public java.security.Principal getUserPrincipal()
Description copied from interface:HandshakeRequest
Return the authenticated user ornull
if no user is authenticated for this handshake.- Returns:
- the user principal.
-
getRequestURI
public java.net.URI getRequestURI()
Description copied from interface:HandshakeRequest
Return the request URI of the handshake request.- Returns:
- the request uri of the handshake request.
-
isUserInRole
public boolean isUserInRole(java.lang.String role)
Description copied from interface:HandshakeRequest
Checks whether the current user is in the given role. Roles and role membership can be defined using deployment descriptors of the containing WAR file, if running in a Java EE web container. If the user has not been authenticated, the method returnsfalse
.- Parameters:
role
- the role being checked.- Returns:
- whether the authenticated user is in the role, or false if the user has not been authenticated.
-
getHttpSession
public java.lang.Object getHttpSession()
Description copied from interface:HandshakeRequest
Return a reference to the HttpSession that the web socket handshake that started this conversation was part of, if the implementation is part of a Java EE web container.- Returns:
- the http session or
null
if either the websocket implementation is not part of a Java EE web container, or there is no HttpSession associated with the opening handshake request.
-
getParameterMap
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getParameterMap()
Description copied from interface:HandshakeRequest
Return the request parameters associated with the request.- Returns:
- the unmodifiable map of the request parameters.
-
getQueryString
public java.lang.String getQueryString()
Description copied from interface:HandshakeRequest
Return the query string associated with the request.- Returns:
- the query string.
-
getRequestUri
public java.lang.String getRequestUri()
Description copied from class:UpgradeRequest
Get the undecoded request uri (up to the query string) of underlying HTTP handshake request.- Specified by:
getRequestUri
in classUpgradeRequest
- Returns:
- request uri.
-
isSecure
public boolean isSecure()
Description copied from class:UpgradeRequest
Indicates whether this request was made using a secure channel (such as HTTPS).- Specified by:
isSecure
in classUpgradeRequest
- Returns:
- true if the request was made using secure channel, false otherwise.
-
getRemoteAddr
public java.lang.String getRemoteAddr()
Get the Internet Protocol (IP) address of the client or last proxy that sent the request.- Returns:
- a
String
containing the IP address of the client that sent the request ornull
when method is called on client-side.
-
getServerAddr
public java.lang.String getServerAddr()
Returns the host name of the server to which the request was sent.- Returns:
- a
String
Returns the host name of the server to which the request was sent ornull
when method is called on client-side.
-
getServerPort
public int getServerPort()
Get the port of the last client or proxy that sent the request.- Returns:
- a port of the client that sent the request.
-
-