Class MockLowLevelHttpResponse

    • Field Detail

      • content

        private java.io.InputStream content
        Input stream content of HTTP response or null by default.
      • contentType

        private java.lang.String contentType
        Content type of HTTP response or null by default.
      • statusCode

        private int statusCode
        Status code of HTTP response or 200 by default.
      • reasonPhrase

        private java.lang.String reasonPhrase
        HTTP reason phrase or null for none.
      • headerNames

        private java.util.List<java.lang.String> headerNames
        List of header names of HTTP response (empty array list by default).
      • headerValues

        private java.util.List<java.lang.String> headerValues
        List of header values of HTTP response (empty array list by default).
      • contentEncoding

        private java.lang.String contentEncoding
        Content encoding or null for none.
      • contentLength

        private long contentLength
        Content length or -1 if unknown.
      • isDisconnected

        private boolean isDisconnected
        Whether disconnect() has been called.
    • Constructor Detail

      • MockLowLevelHttpResponse

        public MockLowLevelHttpResponse()
    • Method Detail

      • addHeader

        public MockLowLevelHttpResponse addHeader​(java.lang.String name,
                                                  java.lang.String value)
        Adds a header to the response.
        Parameters:
        name - header name
        value - header value
      • setContent

        public MockLowLevelHttpResponse setContent​(java.lang.String stringContent)
        Sets the response content to the given content string.

        If the input string is null, it will set the content to null. Else, it will use TestableByteArrayInputStream with the UTF-8 encoded string content.

        Parameters:
        stringContent - content string or null for none
      • setZeroContent

        public MockLowLevelHttpResponse setZeroContent()
        Sets the content to null and the content length to 0. Note that the result will have a content length header whose value is 0.
        Since:
        1.18
      • getContent

        public java.io.InputStream getContent()
                                       throws java.io.IOException
        Description copied from class: LowLevelHttpResponse
        Returns the HTTP response content input stream or null for none.
        Specified by:
        getContent in class LowLevelHttpResponse
        Throws:
        java.io.IOException - I/O exception
      • getHeaderCount

        public int getHeaderCount()
        Description copied from class: LowLevelHttpResponse
        Returns the number of HTTP response headers.

        Note that multiple headers of the same name need to be supported, in which case each header value is treated as a separate header.

        Specified by:
        getHeaderCount in class LowLevelHttpResponse
      • getHeaderNames

        public final java.util.List<java.lang.String> getHeaderNames()
        Returns the list of header names of HTTP response.
        Since:
        1.5
      • setHeaderNames

        public MockLowLevelHttpResponse setHeaderNames​(java.util.List<java.lang.String> headerNames)
        Sets the list of header names of HTTP response.

        Default value is an empty list.

        Since:
        1.5
      • getHeaderValues

        public final java.util.List<java.lang.String> getHeaderValues()
        Returns the list of header values of HTTP response.

        Default value is an empty list.

        Since:
        1.5
      • setHeaderValues

        public MockLowLevelHttpResponse setHeaderValues​(java.util.List<java.lang.String> headerValues)
        Sets the list of header values of HTTP response.
        Since:
        1.5
      • setContent

        public MockLowLevelHttpResponse setContent​(java.io.InputStream content)
        Sets the input stream content of HTTP response or null for none.
        Since:
        1.5
      • setContentType

        public MockLowLevelHttpResponse setContentType​(java.lang.String contentType)
        Sets the content type of HTTP response or null for none.
        Since:
        1.5
      • setContentEncoding

        public MockLowLevelHttpResponse setContentEncoding​(java.lang.String contentEncoding)
        Sets the content encoding or null for none.
        Since:
        1.5
      • setContentLength

        public MockLowLevelHttpResponse setContentLength​(long contentLength)
        Sets the content length or -1 for unknown.

        By default it is -1.

        Since:
        1.5
      • setStatusCode

        public MockLowLevelHttpResponse setStatusCode​(int statusCode)
        Sets the status code of HTTP response.

        Default value is 200.

        Since:
        1.5
      • setReasonPhrase

        public MockLowLevelHttpResponse setReasonPhrase​(java.lang.String reasonPhrase)
        Sets the HTTP reason phrase or null for none.
        Since:
        1.6
      • disconnect

        public void disconnect()
                        throws java.io.IOException
        Description copied from class: LowLevelHttpResponse
        Default implementation does nothing, but subclasses may override to attempt to abort the connection or release allocated system resources for this connection.
        Overrides:
        disconnect in class LowLevelHttpResponse
        Throws:
        java.io.IOException - I/O exception
      • isDisconnected

        public boolean isDisconnected()
        Returns whether disconnect() has been called.
        Since:
        1.14