Class HTTPResponse

    • Constructor Detail

      • HTTPResponse

        public HTTPResponse​(int statusCode)
        Creates a new minimal HTTP response with the specified status code.
        Parameters:
        statusCode - The HTTP status code.
    • Method Detail

      • getStatusCode

        public int getStatusCode()
        Gets the HTTP status code.
        Returns:
        The HTTP status code.
      • indicatesSuccess

        public boolean indicatesSuccess()
        Returns true if the HTTP status code indicates success (2xx).
        Returns:
        true if the HTTP status code indicates success, else false.
      • ensureStatusCode

        public void ensureStatusCode​(int... expectedStatusCode)
                              throws ParseException
        Ensures this HTTP response has the specified status code.
        Parameters:
        expectedStatusCode - The expected status code(s).
        Throws:
        ParseException - If the status code of this HTTP response doesn't match the expected.
      • getStatusMessage

        public String getStatusMessage()
        Gets the HTTP status message.
        Returns:
        The HTTP status message, null if not specified.
      • setStatusMessage

        public void setStatusMessage​(String message)
        Sets the HTTP status message.
        Parameters:
        message - The HTTP status message, null if not specified.
      • getLocation

        public URI getLocation()
        Gets the Location header value (for redirects).
        Returns:
        The header value, null if not specified.
      • setLocation

        public void setLocation​(URI location)
        Sets the Location header value (for redirects).
        Parameters:
        location - The header value, null if not specified.
      • getCacheControl

        public String getCacheControl()
        Gets the Cache-Control header value.
        Returns:
        The header value, null if not specified.
      • setCacheControl

        public void setCacheControl​(String cacheControl)
        Sets the Cache-Control header value.
        Parameters:
        cacheControl - The header value, null if not specified.
      • getPragma

        public String getPragma()
        Gets the Pragma header value.
        Returns:
        The header value, null if not specified.
      • setPragma

        public void setPragma​(String pragma)
        Sets the Pragma header value.
        Parameters:
        pragma - The header value, null if not specified.
      • getWWWAuthenticate

        public String getWWWAuthenticate()
        Gets the WWW-Authenticate header value.
        Returns:
        The header value, null if not specified.
      • setWWWAuthenticate

        public void setWWWAuthenticate​(String wwwAuthenticate)
        Sets the WWW-Authenticate header value.
        Parameters:
        wwwAuthenticate - The header value, null if not specified.
      • getContent

        public String getContent()
        Gets the raw response content.
        Returns:
        The raw response content, null if none.
      • getContentAsJSONObject

        public net.minidev.json.JSONObject getContentAsJSONObject()
                                                           throws ParseException
        Gets the response content as a JSON object.
        Returns:
        The response content as a JSON object.
        Throws:
        ParseException - If the Content-Type header isn't application/json, the response content is null, empty or couldn't be parsed to a valid JSON object.
      • getContentAsJSONArray

        public net.minidev.json.JSONArray getContentAsJSONArray()
                                                         throws ParseException
        Gets the response content as a JSON array.
        Returns:
        The response content as a JSON array.
        Throws:
        ParseException - If the Content-Type header isn't application/json, the response content is null, empty or couldn't be parsed to a valid JSON array.
      • getContentAsJWT

        public com.nimbusds.jwt.JWT getContentAsJWT()
                                             throws ParseException
        Gets the response content as a JSON Web Token (JWT).
        Returns:
        The response content as a JSON Web Token (JWT).
        Throws:
        ParseException - If the Content-Type header isn't application/jwt, the response content is null, empty or couldn't be parsed to a valid JSON Web Token (JWT).
      • setContent

        public void setContent​(String content)
        Sets the raw response content.
        Parameters:
        content - The raw response content, null if none.
      • getEntityContentType

        public com.nimbusds.common.contenttype.ContentType getEntityContentType()
        Gets the Content-Type header value.
        Returns:
        The Content-Type header value, null if not specified or parsing failed.
      • setEntityContentType

        public void setEntityContentType​(com.nimbusds.common.contenttype.ContentType ct)
        Sets the Content-Type header value.
        Parameters:
        ct - The Content-Type header value, null if not specified.
      • setContentType

        public void setContentType​(String ct)
                            throws ParseException
        Sets the Content-Type header value.
        Parameters:
        ct - The Content-Type header value, null if not specified.
        Throws:
        ParseException - If the header value couldn't be parsed to a valid content type.
      • ensureEntityContentType

        public void ensureEntityContentType()
                                     throws ParseException
        Ensures this HTTP message has a Content-Type header value.
        Throws:
        ParseException - If the Content-Type header is missing.
      • ensureEntityContentType

        public void ensureEntityContentType​(com.nimbusds.common.contenttype.ContentType contentType)
                                     throws ParseException
        Ensures this HTTP message has the specified Content-Type header value. This method compares only the primary type and subtype; any content type parameters, such as charset, are ignored.
        Parameters:
        contentType - The expected content type. Must not be null.
        Throws:
        ParseException - If the Content-Type header is missing or its primary and subtype don't match.
      • getHeaderValue

        public String getHeaderValue​(String name)
        Gets an HTTP header's value.
        Parameters:
        name - The header name. Must not be null.
        Returns:
        The first header value, null if not specified.
      • getHeaderValues

        public List<String> getHeaderValues​(String name)
        Gets an HTTP header's value(s).
        Parameters:
        name - The header name. Must not be null.
        Returns:
        The header value(s), null if not specified.
      • setHeader

        public void setHeader​(String name,
                              String... values)
        Sets an HTTP header.
        Parameters:
        name - The header name. Must not be null.
        values - The header value(s). If null and a header with the same name is specified, it will be deleted.
      • getHeaderMap

        public Map<String,​List<String>> getHeaderMap()
        Returns the HTTP headers.
        Returns:
        The HTTP headers.
      • getClientIPAddress

        public String getClientIPAddress()
        Gets the client IP address.
        Returns:
        The client IP address, null if not specified.
      • setClientIPAddress

        public void setClientIPAddress​(String clientIPAddress)
        Sets the client IP address.
        Parameters:
        clientIPAddress - The client IP address, null if not specified.