Class HttpRequest

    • Field Detail

      • BUFFER_CHUNK_SIZE

        protected static final int BUFFER_CHUNK_SIZE
        Size of the buffers / chunks used when sending files to the HTTP server.

        When trying to upload large amount of data the internal connection buffer can become too large and exceed the heap size, leading to an OutOfMemoryError. This was fixed in JDK 1.5 by introducing HttpURLConnection.setChunkedStreamingMode(int).

        As per CARGO-1418, use a sensible chunk size for fast links.
        See Also:
        Constant Field Values
    • Constructor Detail

      • HttpRequest

        public HttpRequest​(URL url)
        Constructor.
        Parameters:
        url - URL to be called.
      • HttpRequest

        public HttpRequest​(URL url,
                           long timeout)
        Constructor.
        Parameters:
        url - URL to be called.
        timeout - Request timeout.
    • Method Detail

      • addRequestProperty

        public void addRequestProperty​(String propertyName,
                                       String propertyValue)
        Parameters:
        propertyName - Name of request header property.
        propertyValue - Value of request header property.
      • setRequestBody

        public void setRequestBody​(String requestBody)
        Parameters:
        requestBody - String request body to set.
      • setAuthentication

        public void setAuthentication​(String username,
                                      String password)
        Set HTTP authentication.
        Parameters:
        username - User name.
        password - Password.
      • get

        public HttpResult get()
        Returns:
        Result of HTTP GET call of this connection.
      • post

        public HttpResult post()
        Returns:
        Result of HTTP POST call of this connection.
      • put

        public HttpResult put()
        Returns:
        Result of HTTP PUT call of this connection.
      • delete

        public HttpResult delete()
        Returns:
        Result of HTTP DELETE call of this connection.
      • writeOutputStream

        protected void writeOutputStream​(HttpURLConnection connection)
                                  throws IOException
        If necessary, writes to the output stream of the HTTP URL connection. By default, the requestBody is written as output.
        Parameters:
        connection - the HTTP URL connection to read from
        Throws:
        IOException - if an error happens during the connection establishment or write
      • extractCharset

        protected static Charset extractCharset​(String contentType)
        Extract charset from Content-Type header.
        Parameters:
        contentType - Content-Type header.
        Returns:
        Character set extracted, UTF-8 if no valid charset found.
      • extractHeaderComponent

        protected static String extractHeaderComponent​(String header,
                                                       String component)
        Extract a component of a header.
        Parameters:
        header - header to extract from
        component - component to extract
        Returns:
        Extracted component, null if component doesn't exist in header