Class ServletUpgradeRequest
- java.lang.Object
-
- org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest
-
- All Implemented Interfaces:
UpgradeRequest
- Direct Known Subclasses:
ServletWebSocketRequest
public class ServletUpgradeRequest extends java.lang.Object implements UpgradeRequest
Servlet specificUpgradeRequestimplementation.
-
-
Constructor Summary
Constructors Constructor Description ServletUpgradeRequest(javax.servlet.http.HttpServletRequest httpRequest)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddExtensions(java.lang.String... configs)Add WebSocket Extension Configuration(s) to requestvoidaddExtensions(ExtensionConfig... configs)Add WebSocket Extension Configuration(s) to Upgrade Request.voidclearHeaders()Remove all headers from request.voidcomplete()java.security.cert.X509Certificate[]getCertificates()java.util.List<java.net.HttpCookie>getCookies()Get the list of Cookies on the Upgrade requestjava.util.List<ExtensionConfig>getExtensions()Get the list of WebSocket Extension Configurations for this Upgrade Request.java.lang.StringgetHeader(java.lang.String name)Get a specific Header value from Upgrade RequestintgetHeaderInt(java.lang.String name)Get the specific Header value, as anint, from the Upgrade Request.java.util.Map<java.lang.String,java.util.List<java.lang.String>>getHeaders()Get the headers as a Map of keys to value lists.java.util.List<java.lang.String>getHeaders(java.lang.String name)Get the specific header values (for multi-value headers)java.lang.StringgetHost()The host of the Upgrade Request URIjavax.servlet.http.HttpServletRequestgetHttpServletRequest()Return the underlying HttpServletRequest that existed at Upgrade time.java.lang.StringgetHttpVersion()The HTTP version used for this Upgrade Requestjava.lang.StringgetLocalAddress()Equivalent toServletRequest.getLocalAddr()java.util.LocalegetLocale()Equivalent toServletRequest.getLocale()java.util.Enumeration<java.util.Locale>getLocales()Equivalent toServletRequest.getLocales()java.lang.StringgetLocalHostName()Equivalent toServletRequest.getLocalName()intgetLocalPort()Equivalent toServletRequest.getLocalPort()java.net.InetSocketAddressgetLocalSocketAddress()Return aInetSocketAddressfor the local socket.java.lang.StringgetMethod()The HTTP method for this Upgrade Request.java.lang.StringgetOrigin()The WebSocket Origin of this Upgrade Requestjava.util.Map<java.lang.String,java.util.List<java.lang.String>>getParameterMap()Returns a map of the query parameters of the request.java.security.PrincipalgetPrincipal()Deprecated.usegetUserPrincipal()insteadjava.lang.StringgetProtocolVersion()Get the WebSocket Protocol Versionjava.lang.StringgetQueryString()Get the Query String of the request URI.java.lang.StringgetRemoteAddress()Equivalent toServletRequest.getRemoteAddr()java.lang.StringgetRemoteHostName()Equivalent toServletRequest.getRemoteHost()intgetRemotePort()Equivalent toServletRequest.getRemotePort()java.net.InetSocketAddressgetRemoteSocketAddress()Return aInetSocketAddressfor the remote socket.java.lang.StringgetRequestPath()java.net.URIgetRequestURI()Get the Request URIjava.lang.ObjectgetServletAttribute(java.lang.String name)java.util.Map<java.lang.String,java.lang.Object>getServletAttributes()java.util.Map<java.lang.String,java.util.List<java.lang.String>>getServletParameters()javax.servlet.http.HttpSessiongetSession()Return the HttpSession if it exists.java.util.List<java.lang.String>getSubProtocols()Get the list of offered WebSocket sub-protocols.java.security.PrincipalgetUserPrincipal()Equivalent toHttpServletRequest.getUserPrincipal()booleanhasSubProtocol(java.lang.String test)Test if a specific sub-protocol is offeredbooleanisOrigin(java.lang.String test)Test if supplied Origin is the same as the RequestbooleanisSecure()Test if connection is secure.booleanisUserInRole(java.lang.String role)voidsetCookies(java.util.List<java.net.HttpCookie> cookies)Set the list of Cookies on the requestvoidsetExtensions(java.util.List<ExtensionConfig> configs)Set the list of WebSocket Extension configurations on the request.voidsetHeader(java.lang.String name, java.lang.String value)Set a specific header valuevoidsetHeader(java.lang.String name, java.util.List<java.lang.String> values)Set a specific header with multi-value fieldvoidsetHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)Sets multiple headers on the request.voidsetHttpVersion(java.lang.String httpVersion)Set the HTTP Version to use.voidsetMethod(java.lang.String method)Set the HTTP method to use.voidsetRequestURI(java.net.URI uri)Set the Request URI to use for this request.voidsetServletAttribute(java.lang.String name, java.lang.Object value)voidsetSession(java.lang.Object session)Set the Session associated with this request.voidsetSubProtocols(java.lang.String... protocols)Set the offered WebSocket Sub-Protocol list.voidsetSubProtocols(java.util.List<java.lang.String> subProtocols)Set the offered WebSocket Sub-Protocol list.
-
-
-
Method Detail
-
addExtensions
public void addExtensions(ExtensionConfig... configs)
Description copied from interface:UpgradeRequestAdd WebSocket Extension Configuration(s) to Upgrade Request.This is merely the list of requested Extensions to use, see
UpgradeResponse.getExtensions()for what was negotiated- Specified by:
addExtensionsin interfaceUpgradeRequest- Parameters:
configs- the configuration(s) to add
-
addExtensions
public void addExtensions(java.lang.String... configs)
Description copied from interface:UpgradeRequestAdd WebSocket Extension Configuration(s) to requestThis is merely the list of requested Extensions to use, see
UpgradeResponse.getExtensions()for what was negotiated- Specified by:
addExtensionsin interfaceUpgradeRequest- Parameters:
configs- the configuration(s) to add
-
clearHeaders
public void clearHeaders()
Description copied from interface:UpgradeRequestRemove all headers from request.- Specified by:
clearHeadersin interfaceUpgradeRequest
-
complete
public void complete()
-
getCertificates
public java.security.cert.X509Certificate[] getCertificates()
-
getCookies
public java.util.List<java.net.HttpCookie> getCookies()
Description copied from interface:UpgradeRequestGet the list of Cookies on the Upgrade request- Specified by:
getCookiesin interfaceUpgradeRequest- Returns:
- the list of Cookies
-
getExtensions
public java.util.List<ExtensionConfig> getExtensions()
Description copied from interface:UpgradeRequestGet the list of WebSocket Extension Configurations for this Upgrade Request.This is merely the list of requested Extensions to use, see
UpgradeResponse.getExtensions()for what was negotiated- Specified by:
getExtensionsin interfaceUpgradeRequest- Returns:
- the list of Extension configurations (in the order they were specified)
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Description copied from interface:UpgradeRequestGet a specific Header value from Upgrade Request- Specified by:
getHeaderin interfaceUpgradeRequest- Parameters:
name- the name of the header- Returns:
- the value of the header (null if header does not exist)
-
getHeaderInt
public int getHeaderInt(java.lang.String name)
Description copied from interface:UpgradeRequestGet the specific Header value, as anint, from the Upgrade Request.- Specified by:
getHeaderIntin interfaceUpgradeRequest- Parameters:
name- the name of the header- Returns:
- the value of the header as an
int(-1 if header does not exist)
-
getHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
Description copied from interface:UpgradeRequestGet the headers as a Map of keys to value lists.- Specified by:
getHeadersin interfaceUpgradeRequest- Returns:
- the headers
-
getHeaders
public java.util.List<java.lang.String> getHeaders(java.lang.String name)
Description copied from interface:UpgradeRequestGet the specific header values (for multi-value headers)- Specified by:
getHeadersin interfaceUpgradeRequest- Parameters:
name- the header name- Returns:
- the value list (null if no header exists)
-
getHost
public java.lang.String getHost()
Description copied from interface:UpgradeRequestThe host of the Upgrade Request URI- Specified by:
getHostin interfaceUpgradeRequest- Returns:
- host of the request URI
-
getHttpServletRequest
public javax.servlet.http.HttpServletRequest getHttpServletRequest()
Return the underlying HttpServletRequest that existed at Upgrade time.Note: many features of the HttpServletRequest are invalid when upgraded, especially ones that deal with body content, streams, readers, and responses.
- Returns:
- a limited version of the underlying HttpServletRequest
-
getHttpVersion
public java.lang.String getHttpVersion()
Description copied from interface:UpgradeRequestThe HTTP version used for this Upgrade RequestAs of RFC6455 (December 2011) this is always
HTTP/1.1- Specified by:
getHttpVersionin interfaceUpgradeRequest- Returns:
- the HTTP Version used
-
getLocalAddress
public java.lang.String getLocalAddress()
Equivalent toServletRequest.getLocalAddr()- Returns:
- the local address
-
getLocale
public java.util.Locale getLocale()
Equivalent toServletRequest.getLocale()- Returns:
- the preferred
Localefor the client
-
getLocales
public java.util.Enumeration<java.util.Locale> getLocales()
Equivalent toServletRequest.getLocales()- Returns:
- an Enumeration of preferred Locale objects
-
getLocalHostName
public java.lang.String getLocalHostName()
Equivalent toServletRequest.getLocalName()- Returns:
- the local host name
-
getLocalPort
public int getLocalPort()
Equivalent toServletRequest.getLocalPort()- Returns:
- the local port
-
getLocalSocketAddress
public java.net.InetSocketAddress getLocalSocketAddress()
Return aInetSocketAddressfor the local socket.Warning: this can cause a DNS lookup
- Returns:
- the local socket address
-
getMethod
public java.lang.String getMethod()
Description copied from interface:UpgradeRequestThe HTTP method for this Upgrade Request.As of RFC6455 (December 2011) this is always
GET- Specified by:
getMethodin interfaceUpgradeRequest- Returns:
- the HTTP method used
-
getOrigin
public java.lang.String getOrigin()
Description copied from interface:UpgradeRequestThe WebSocket Origin of this Upgrade RequestSee RFC6455: Section 10.2 for details.
Equivalent to
UpgradeRequest.getHeader(String)passed the "Origin" header.- Specified by:
getOriginin interfaceUpgradeRequest- Returns:
- the Origin header
-
getParameterMap
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getParameterMap()
Description copied from interface:UpgradeRequestReturns a map of the query parameters of the request.- Specified by:
getParameterMapin interfaceUpgradeRequest- Returns:
- a unmodifiable map of query parameters of the request.
-
getPrincipal
@Deprecated public java.security.Principal getPrincipal()
Deprecated.usegetUserPrincipal()instead- Returns:
- the principal
-
getProtocolVersion
public java.lang.String getProtocolVersion()
Description copied from interface:UpgradeRequestGet the WebSocket Protocol VersionAs of RFC6455, Jetty only supports version
13- Specified by:
getProtocolVersionin interfaceUpgradeRequest- Returns:
- the WebSocket protocol version
-
getQueryString
public java.lang.String getQueryString()
Description copied from interface:UpgradeRequestGet the Query String of the request URI.- Specified by:
getQueryStringin interfaceUpgradeRequest- Returns:
- the request uri query string
-
getRemoteAddress
public java.lang.String getRemoteAddress()
Equivalent toServletRequest.getRemoteAddr()- Returns:
- the remote address
-
getRemoteHostName
public java.lang.String getRemoteHostName()
Equivalent toServletRequest.getRemoteHost()- Returns:
- the remote host name
-
getRemotePort
public int getRemotePort()
Equivalent toServletRequest.getRemotePort()- Returns:
- the remote port
-
getRemoteSocketAddress
public java.net.InetSocketAddress getRemoteSocketAddress()
Return aInetSocketAddressfor the remote socket.Warning: this can cause a DNS lookup
- Returns:
- the remote socket address
-
getRequestPath
public java.lang.String getRequestPath()
-
getRequestURI
public java.net.URI getRequestURI()
Description copied from interface:UpgradeRequestGet the Request URI- Specified by:
getRequestURIin interfaceUpgradeRequest- Returns:
- the request URI
-
getServletAttribute
public java.lang.Object getServletAttribute(java.lang.String name)
-
getServletAttributes
public java.util.Map<java.lang.String,java.lang.Object> getServletAttributes()
-
getServletParameters
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getServletParameters()
-
getSession
public javax.servlet.http.HttpSession getSession()
Return the HttpSession if it exists.Note: this is equivalent to
HttpServletRequest.getSession(boolean)and will not create a new HttpSession.- Specified by:
getSessionin interfaceUpgradeRequest- Returns:
- the Servlet HTTPSession on server side UpgradeRequests
-
getSubProtocols
public java.util.List<java.lang.String> getSubProtocols()
Description copied from interface:UpgradeRequestGet the list of offered WebSocket sub-protocols.- Specified by:
getSubProtocolsin interfaceUpgradeRequest- Returns:
- the list of offered sub-protocols
-
getUserPrincipal
public java.security.Principal getUserPrincipal()
Equivalent toHttpServletRequest.getUserPrincipal()- Specified by:
getUserPrincipalin interfaceUpgradeRequest- Returns:
- the user principal
-
hasSubProtocol
public boolean hasSubProtocol(java.lang.String test)
Description copied from interface:UpgradeRequestTest if a specific sub-protocol is offered- Specified by:
hasSubProtocolin interfaceUpgradeRequest- Parameters:
test- the sub-protocol to test for- Returns:
- true if sub-protocol exists on request
-
isOrigin
public boolean isOrigin(java.lang.String test)
Description copied from interface:UpgradeRequestTest if supplied Origin is the same as the Request- Specified by:
isOriginin interfaceUpgradeRequest- Parameters:
test- the supplied origin- Returns:
- true if the supplied origin matches the request origin
-
isSecure
public boolean isSecure()
Description copied from interface:UpgradeRequestTest if connection is secure.- Specified by:
isSecurein interfaceUpgradeRequest- Returns:
- true if connection is secure.
-
isUserInRole
public boolean isUserInRole(java.lang.String role)
-
setCookies
public void setCookies(java.util.List<java.net.HttpCookie> cookies)
Description copied from interface:UpgradeRequestSet the list of Cookies on the request- Specified by:
setCookiesin interfaceUpgradeRequest- Parameters:
cookies- the cookies to use
-
setExtensions
public void setExtensions(java.util.List<ExtensionConfig> configs)
Description copied from interface:UpgradeRequestSet the list of WebSocket Extension configurations on the request.- Specified by:
setExtensionsin interfaceUpgradeRequest- Parameters:
configs- the list of extension configurations
-
setHeader
public void setHeader(java.lang.String name, java.util.List<java.lang.String> values)Description copied from interface:UpgradeRequestSet a specific header with multi-value fieldOverrides any previous value for this named header
- Specified by:
setHeaderin interfaceUpgradeRequest- Parameters:
name- the name of the headervalues- the multi-value field
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)Description copied from interface:UpgradeRequestSet a specific header valueOverrides any previous value for this named header
- Specified by:
setHeaderin interfaceUpgradeRequest- Parameters:
name- the header to setvalue- the value to set it to
-
setHeaders
public void setHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
Description copied from interface:UpgradeRequestSets multiple headers on the request.Only sets those headers provided, does not remove headers that exist on request and are not provided in the parameter for this method.
Convenience method vs calling
UpgradeRequest.setHeader(String, List)multiple times.- Specified by:
setHeadersin interfaceUpgradeRequest- Parameters:
headers- the headers to set
-
setHttpVersion
public void setHttpVersion(java.lang.String httpVersion)
Description copied from interface:UpgradeRequestSet the HTTP Version to use.As of RFC6455 (December 2011) this should always be
HTTP/1.1- Specified by:
setHttpVersionin interfaceUpgradeRequest- Parameters:
httpVersion- the HTTP version to use.
-
setMethod
public void setMethod(java.lang.String method)
Description copied from interface:UpgradeRequestSet the HTTP method to use.As of RFC6455 (December 2011) this is always
GET- Specified by:
setMethodin interfaceUpgradeRequest- Parameters:
method- the HTTP method to use.
-
setRequestURI
public void setRequestURI(java.net.URI uri)
Description copied from interface:UpgradeRequestSet the Request URI to use for this request.Must be an absolute URI with scheme
'ws'or'wss'- Specified by:
setRequestURIin interfaceUpgradeRequest- Parameters:
uri- the Request URI
-
setServletAttribute
public void setServletAttribute(java.lang.String name, java.lang.Object value)
-
setSession
public void setSession(java.lang.Object session)
Description copied from interface:UpgradeRequestSet the Session associated with this request.Typically used to associate the Servlet HttpSession object.
- Specified by:
setSessionin interfaceUpgradeRequest- Parameters:
session- the session object to associate with this request
-
setSubProtocols
public void setSubProtocols(java.util.List<java.lang.String> subProtocols)
Description copied from interface:UpgradeRequestSet the offered WebSocket Sub-Protocol list.- Specified by:
setSubProtocolsin interfaceUpgradeRequest- Parameters:
subProtocols- the offered sub-protocol list
-
setSubProtocols
public void setSubProtocols(java.lang.String... protocols)
Description copied from interface:UpgradeRequestSet the offered WebSocket Sub-Protocol list.- Specified by:
setSubProtocolsin interfaceUpgradeRequest- Parameters:
protocols- the offered sub-protocol list
-
-