Class ClientUpgradeRequest

  • All Implemented Interfaces:
    UpgradeRequest

    public final class ClientUpgradeRequest
    extends java.lang.Object
    implements UpgradeRequest
    Client based UpgradeRequest API
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ABNF_REQUIRED_QUOTING
      ABNF from RFC 2616, RFC 822, and RFC 6455 specified characters requiring quoting.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addExtensions​(java.lang.String... configs)
      Add WebSocket Extension Configuration(s) to request
      void addExtensions​(ExtensionConfig... configs)
      Add WebSocket Extension Configuration(s) to Upgrade Request.
      java.util.List<java.net.HttpCookie> getCookies()
      Get the list of Cookies on the Upgrade request
      java.util.List<ExtensionConfig> getExtensions()
      Get the list of WebSocket Extension Configurations for this Upgrade Request.
      java.lang.String getHeader​(java.lang.String name)
      Get a specific Header value from Upgrade Request
      int getHeaderInt​(java.lang.String name)
      Get the specific Header value, as an int, 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.String getHost()
      The host of the Upgrade Request URI
      java.lang.String getHttpVersion()
      The HTTP version used for this Upgrade Request
      java.lang.String getMethod()
      The HTTP method for this Upgrade Request.
      java.lang.String getOrigin()
      The WebSocket Origin of this Upgrade Request
      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getParameterMap()
      Returns a map of the query parameters of the request.
      java.lang.String getProtocolVersion()
      Get the WebSocket Protocol Version
      java.lang.String getQueryString()
      Get the Query String of the request URI.
      java.net.URI getRequestURI()
      Get the Request URI
      java.util.List<java.lang.String> getSubProtocols()
      Get the list of offered WebSocket sub-protocols.
      long getTimeout()  
      java.security.Principal getUserPrincipal()
      Get the User Principal for this request.
      boolean hasSubProtocol​(java.lang.String test)
      Test if a specific sub-protocol is offered
      boolean isSecure()
      Test if connection is secure.
      static java.lang.String joinValues​(java.util.List<java.lang.String> values)  
      void setCookies​(java.util.List<java.net.HttpCookie> cookies)
      Set the list of Cookies on the request
      void setExtensions​(java.util.List<ExtensionConfig> configs)
      Set the list of WebSocket Extension configurations on the request.
      void setHeader​(java.lang.String name, java.lang.String value)
      Set a specific header value
      void setHeader​(java.lang.String name, java.util.List<java.lang.String> values)
      Set a specific header with multi-value field
      void setHeaders​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
      Sets multiple headers on the request.
      void setSubProtocols​(java.lang.String... protocols)
      Set the offered WebSocket Sub-Protocol list.
      void setSubProtocols​(java.util.List<java.lang.String> protocols)
      Set the offered WebSocket Sub-Protocol list.
      void setTimeout​(long timeout, java.util.concurrent.TimeUnit unit)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ABNF_REQUIRED_QUOTING

        public static final java.lang.String ABNF_REQUIRED_QUOTING
        ABNF from RFC 2616, RFC 822, and RFC 6455 specified characters requiring quoting.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ClientUpgradeRequest

        public ClientUpgradeRequest()
      • ClientUpgradeRequest

        @Deprecated
        public ClientUpgradeRequest​(java.net.URI uri)
        Deprecated.
    • Method Detail

      • getCookies

        public java.util.List<java.net.HttpCookie> getCookies()
        Description copied from interface: UpgradeRequest
        Get the list of Cookies on the Upgrade request
        Specified by:
        getCookies in interface UpgradeRequest
        Returns:
        the list of Cookies
      • getExtensions

        public java.util.List<ExtensionConfig> getExtensions()
        Description copied from interface: UpgradeRequest
        Get 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:
        getExtensions in interface UpgradeRequest
        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: UpgradeRequest
        Get a specific Header value from Upgrade Request
        Specified by:
        getHeader in interface UpgradeRequest
        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: UpgradeRequest
        Get the specific Header value, as an int, from the Upgrade Request.
        Specified by:
        getHeaderInt in interface UpgradeRequest
        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: UpgradeRequest
        Get the headers as a Map of keys to value lists.
        Specified by:
        getHeaders in interface UpgradeRequest
        Returns:
        the headers
      • getHeaders

        public java.util.List<java.lang.String> getHeaders​(java.lang.String name)
        Description copied from interface: UpgradeRequest
        Get the specific header values (for multi-value headers)
        Specified by:
        getHeaders in interface UpgradeRequest
        Parameters:
        name - the header name
        Returns:
        the value list (null if no header exists)
      • getHost

        public java.lang.String getHost()
        Description copied from interface: UpgradeRequest
        The host of the Upgrade Request URI
        Specified by:
        getHost in interface UpgradeRequest
        Returns:
        host of the request URI
      • getParameterMap

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getParameterMap()
        Description copied from interface: UpgradeRequest
        Returns a map of the query parameters of the request.
        Specified by:
        getParameterMap in interface UpgradeRequest
        Returns:
        a unmodifiable map of query parameters of the request.
      • getProtocolVersion

        public java.lang.String getProtocolVersion()
        Description copied from interface: UpgradeRequest
        Get the WebSocket Protocol Version

        As of RFC6455, Jetty only supports version 13

        Specified by:
        getProtocolVersion in interface UpgradeRequest
        Returns:
        the WebSocket protocol version
      • getQueryString

        public java.lang.String getQueryString()
        Description copied from interface: UpgradeRequest
        Get the Query String of the request URI.
        Specified by:
        getQueryString in interface UpgradeRequest
        Returns:
        the request uri query string
      • getRequestURI

        public java.net.URI getRequestURI()
        Description copied from interface: UpgradeRequest
        Get the Request URI
        Specified by:
        getRequestURI in interface UpgradeRequest
        Returns:
        the request URI
      • getSubProtocols

        public java.util.List<java.lang.String> getSubProtocols()
        Description copied from interface: UpgradeRequest
        Get the list of offered WebSocket sub-protocols.
        Specified by:
        getSubProtocols in interface UpgradeRequest
        Returns:
        the list of offered sub-protocols
      • getUserPrincipal

        public java.security.Principal getUserPrincipal()
        Description copied from interface: UpgradeRequest
        Get the User Principal for this request.

        Only applicable when using UpgradeRequest from server side.

        Specified by:
        getUserPrincipal in interface UpgradeRequest
        Returns:
        the user principal
      • hasSubProtocol

        public boolean hasSubProtocol​(java.lang.String test)
        Description copied from interface: UpgradeRequest
        Test if a specific sub-protocol is offered
        Specified by:
        hasSubProtocol in interface UpgradeRequest
        Parameters:
        test - the sub-protocol to test for
        Returns:
        true if sub-protocol exists on request
      • isSecure

        public boolean isSecure()
        Description copied from interface: UpgradeRequest
        Test if connection is secure.
        Specified by:
        isSecure in interface UpgradeRequest
        Returns:
        true if connection is secure.
      • addExtensions

        public void addExtensions​(ExtensionConfig... configs)
        Add WebSocket Extension Configuration(s) to Upgrade Request.

        This is merely the list of requested Extensions to use, see UpgradeResponse.getExtensions() for what was negotiated

        Parameters:
        configs - the configuration(s) to add
      • addExtensions

        public void addExtensions​(java.lang.String... configs)
        Add WebSocket Extension Configuration(s) to request

        This is merely the list of requested Extensions to use, see UpgradeResponse.getExtensions() for what was negotiated

        Parameters:
        configs - the configuration(s) to add
      • setCookies

        public void setCookies​(java.util.List<java.net.HttpCookie> cookies)
        Set the list of Cookies on the request
        Parameters:
        cookies - the cookies to use
      • setExtensions

        public void setExtensions​(java.util.List<ExtensionConfig> configs)
        Set the list of WebSocket Extension configurations on the request.
        Parameters:
        configs - the list of extension configurations
      • setHeader

        public void setHeader​(java.lang.String name,
                              java.util.List<java.lang.String> values)
        Set a specific header with multi-value field

        Overrides any previous value for this named header

        Parameters:
        name - the name of the header
        values - the multi-value field
      • setHeader

        public void setHeader​(java.lang.String name,
                              java.lang.String value)
        Set a specific header value

        Overrides any previous value for this named header

        Parameters:
        name - the header to set
        value - the value to set it to
      • setHeaders

        public void setHeaders​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
        Sets 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 setHeader(String, List) multiple times.

        Parameters:
        headers - the headers to set
      • setSubProtocols

        public void setSubProtocols​(java.util.List<java.lang.String> protocols)
        Set the offered WebSocket Sub-Protocol list.
        Parameters:
        protocols - the offered sub-protocol list
      • setSubProtocols

        public void setSubProtocols​(java.lang.String... protocols)
        Set the offered WebSocket Sub-Protocol list.
        Parameters:
        protocols - the offered sub-protocol list
      • setTimeout

        public void setTimeout​(long timeout,
                               java.util.concurrent.TimeUnit unit)
        Parameters:
        timeout - the total timeout for the request/response conversation of the WebSocket handshake; use zero or a negative value to disable the timeout
        unit - the timeout unit
      • getTimeout

        public long getTimeout()
        Returns:
        the total timeout for this request, in milliseconds; zero or negative if the timeout is disabled
      • joinValues

        public static java.lang.String joinValues​(java.util.List<java.lang.String> values)