Class HTTPConnectionTools


  • public class HTTPConnectionTools
    extends java.lang.Object
    a class that takes care about opening HttpURLConnections and sets the proper timeouts
    Since:
    9:58:25 AM
    Version:
    %I% %G%
    Author:
    Andreas Prlic
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.InputStream doPOST​(java.net.URL url, java.lang.String data)
      do a POST to a URL and return the response stream for further processing elsewhere.
      static java.io.InputStream doPOST​(java.net.URL url, java.lang.String data, int timeout)
      do a POST to a URL and return the response stream for further processing elsewhere.
      static java.io.InputStream getInputStream​(java.net.URL url)
      connect to DAS server and return result as an InputStream.
      static java.io.InputStream getInputStream​(java.net.URL url, boolean acceptGzipEncoding, int timeout)
      open a URL and return an InputStream to it if acceptGzipEncoding == true, use GZIPEncoding to compress communication
      static java.io.InputStream getInputStream​(java.net.URL url, int timeout)
      connect to DAS server and return result as an InputStream.
      static java.net.HttpURLConnection openHttpURLConnection​(java.net.URL url)
      open HttpURLConnection.
      static java.net.HttpURLConnection openHttpURLConnection​(java.net.URL url, int timeout)
      open HttpURLConnection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HTTPConnectionTools

        public HTTPConnectionTools()
    • Method Detail

      • openHttpURLConnection

        public static java.net.HttpURLConnection openHttpURLConnection​(java.net.URL url,
                                                                       int timeout)
                                                                throws java.io.IOException,
                                                                       java.net.ConnectException
        open HttpURLConnection. Recommended way to open HttpURLConnections, since this take care of setting timeouts properly for java 1.4 and 1.5
        Parameters:
        url - URL to oopen
        timeout - timeout in milli seconds
        Returns:
        a HttpURLConnection
        Throws:
        java.io.IOException
        java.net.ConnectException
      • openHttpURLConnection

        public static java.net.HttpURLConnection openHttpURLConnection​(java.net.URL url)
                                                                throws java.io.IOException,
                                                                       java.net.ConnectException
        open HttpURLConnection. Recommended way to open HttpURLConnections, since this take care of setting timeouts properly for java 1.4 and 1.5 uses the DEFAULT_CONNECTION_TIMEOUT (= 15 seconds)
        Parameters:
        url - a URL to open a http connection to
        Returns:
        HttpURLConnect the opened connection
        Throws:
        java.io.IOException
        java.net.ConnectException
      • getInputStream

        public static java.io.InputStream getInputStream​(java.net.URL url,
                                                         int timeout)
                                                  throws java.io.IOException
        connect to DAS server and return result as an InputStream. always asks for response to be in GZIP encoded
        Parameters:
        url - the URL to connect to
        timeout - the timeout for the connection
        Returns:
        an InputStream
        Throws:
        java.io.IOException
        DASException - if DAS server returns error response code
      • getInputStream

        public static java.io.InputStream getInputStream​(java.net.URL url)
                                                  throws java.io.IOException
        connect to DAS server and return result as an InputStream. always asks for response to be in GZIP encoded
        Parameters:
        url - the URL to connect to
        Returns:
        an InputStream
        Throws:
        java.io.IOException
        DASException - if DAS server returns error response code
      • getInputStream

        public static java.io.InputStream getInputStream​(java.net.URL url,
                                                         boolean acceptGzipEncoding,
                                                         int timeout)
                                                  throws java.io.IOException
        open a URL and return an InputStream to it if acceptGzipEncoding == true, use GZIPEncoding to compress communication
        Parameters:
        url -
        acceptGzipEncoding -
        Returns:
        an InputStream to the URL
        Throws:
        java.io.IOException
        DASException - if DAS server returns error response code
      • doPOST

        public static java.io.InputStream doPOST​(java.net.URL url,
                                                 java.lang.String data)
                                          throws java.io.IOException
        do a POST to a URL and return the response stream for further processing elsewhere.
        Parameters:
        url -
        Returns:
        InputStream of response
        Throws:
        java.io.IOException
      • doPOST

        public static java.io.InputStream doPOST​(java.net.URL url,
                                                 java.lang.String data,
                                                 int timeout)
                                          throws java.io.IOException
        do a POST to a URL and return the response stream for further processing elsewhere.
        Parameters:
        url -
        Returns:
        InputStream of response
        Throws:
        java.io.IOException