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

      • 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.
      • 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.
      • getDPoPNonce

        public Nonce getDPoPNonce()
        Gets the DPoP-Nonce header value.
        Returns:
        The DPoP-Nonce header value, null if not specified or parsing failed.
      • setDPoPNonce

        public void setDPoPNonce​(Nonce nonce)
        Sets the DPoP-Nonce header value.
        Parameters:
        nonce - The DPoP-Nonce header value, null if not specified.
      • getContentAsJSONArray

        @Deprecated
        public net.minidev.json.JSONArray getContentAsJSONArray()
                                                         throws ParseException
        Deprecated.
        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

        @Deprecated
        public com.nimbusds.jwt.JWT getContentAsJWT()
                                             throws ParseException
        Deprecated.
        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).
      • 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.
      • ensureEntityContentType

        public void ensureEntityContentType​(com.nimbusds.common.contenttype.ContentType contentType,
                                            String subTypeSuffix)
                                     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.
        subTypeSuffix - Acceptable sub type suffix if the expected content type doesn't match, null if not specified.
        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.
      • setBody

        public void setBody​(String body)
        Sets the HTTP message body.
        Parameters:
        body - The HTTP message body, null if not specified.
      • getBodyAsFormParameters

        public Map<String,​List<String>> getBodyAsFormParameters()
                                                               throws ParseException
        Gets the response body as a form parameters map.
        Returns:
        The form parameters as a map.
        Throws:
        ParseException - If the Content-Type header isn't application/x-www-form-urlencoded or the response couldn't be parsed to a valid form.
      • getBodyAsJSONObject

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

        public net.minidev.json.JSONArray getBodyAsJSONArray()
                                                      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 or has no +json suffix, the response content is null, empty or couldn't be parsed to a valid JSON array.
      • getBodyAsJWT

        public com.nimbusds.jwt.JWT getBodyAsJWT()
                                          throws ParseException
        Gets the response body as a JSON Web Token (JWT).
        Returns:
        The response body as a JSON Web Token (JWT).
        Throws:
        ParseException - If the Content-Type header isn't application/jwt or has no +jwt suffix, the response content is null, empty or couldn't be parsed to a valid JSON Web Token (JWT).
      • 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.