Class HttpConnection


  • public class HttpConnection
    extends java.lang.Object
    The HttpConnection is class wrapping implementation details of http connection and the implementation can change easily.
    • Constructor Detail

      • HttpConnection

        public HttpConnection​(Request request)
        Parameters:
        request - client request
    • Method Detail

      • getResponseStream

        public java.io.InputStream getResponseStream()
        Returns:
        response stream
      • connect

        public void connect()
        Opens connection.
      • getResponseHeader

        public java.lang.String getResponseHeader​(java.lang.String name)
        Parameters:
        name - header name
        Returns:
        response header
      • close

        public void close()
        Closes connection.
      • setTimeout

        public void setTimeout​(int timeout)
        Sets timeout.
        Parameters:
        timeout - timeout in milliseconds
      • setRetryCount

        public void setRetryCount​(int times)
        Sets retry count.
        Parameters:
        times - The number of times to flog a dead horse. (3 by default).
      • getResponseCode

        public int getResponseCode()
        Returns:
        response code.
      • isOpened

        public boolean isOpened()
        Returns:
        true if connection is opened else false
      • checkResponse

        protected void checkResponse()
        Called to check the response and generate an appropriate exception (on failure). If the connection is not opened then it is opened and response checked.
      • handleErrorResponse

        protected void handleErrorResponse()
                                    throws java.io.IOException
        Handles an error response received while executing a service request. Throws a ServiceException or one of its subclasses, depending on the failure conditions.
        Throws:
        java.io.IOException - error reading the error response from the service.
      • getResponseBodyAsString

        public java.lang.String getResponseBodyAsString()
        Return the response body, ensuring that the connection is closed upon completion.
        Returns:
        the response body body as the string
      • getResponseBodyAsStream

        public java.io.InputStream getResponseBodyAsStream()
        Returns:
        the response body as the stream