Class HTTPGetUtil

java.lang.Object
org.cdlib.mrt.utility.HTTPGetUtil

public class HTTPGetUtil extends Object
This class will contain utilities for HTTP transactions
Author:
dloy USE Proxy: String proxyHost = "uc3-mrtingest-stg02.cdlib.org"; int proxyPort = 65002; File outFile = new File("/home/loy/tmp/http/example.txt"); HashMapinvalid input: '<'String, String> headers = new HashMapinvalid input: '<'>(); HTTPGetUtil getUtil = HTTPGetUtil.build(proxyHost, proxyPort, headers); FileUtil.url2File(urlS, outFile, getUtil
  • Field Details

  • Constructor Details

  • Method Details

    • build

      public static HTTPGetUtil build(String proxyHost, Integer proxyPort, HashMap headers) throws TException
      Build HTTPGetUtil
      Parameters:
      proxyHost - service name (not url) of forward proxy - null=no proxy
      proxyPort - service port of forward prosy - if proxy required
      headers - map of headers to be used for each GET request
      Returns:
      HTTPGETUtil
      Throws:
      TException
    • build

      public static HTTPGetUtil build(int timeout, String proxyHost, Integer proxyPort, HashMap headers) throws TException
      Build HTTPGetUtil
      Parameters:
      timeout - process timeout
      proxyHost - service name (not url) of forward proxy - null=no proxy
      proxyPort - service port of forward prosy - if proxy required
      headers - map of headers to be used for each GET request
      Returns:
      HTTPGETUtil
      Throws:
      TException
    • getStreamResponse

      public HttpResponse<InputStream> getStreamResponse(String requestURLS) throws TException
      Get java HttpResponse for Get
      Parameters:
      requestURLS - Url for content
      Returns:
      java HttpResponse
      Throws:
      TException
    • getObject

      public InputStream getObject(String requestURLS) throws TException
      Send this manifestFile to mrt store
      Parameters:
      requestURLS - url for content
      Returns:
      InputStream content
    • addHeaders

      public HttpRequest.Builder addHeaders(HttpRequest.Builder requestBuilder)
    • getStreamResponse

      public HttpResponse<InputStream> getStreamResponse(String requestURLS, long startByte, long endByte) throws TException
      Send this manifestFile to mrt store
      Parameters:
      requestURLS - stream source of content
      startByte - starting byte (from 0) for extraction
      endByte - ending byte (from 0) for extraction
      Returns:
      InputStream for content
    • getObjectStream

      public InputStream getObjectStream(String requestURLS, long startByte, long endByte) throws TException
      Send this manifestFile to mrt store
      Parameters:
      manifestFile -
      Returns:
    • isChunked

      public static boolean isChunked(HttpResponse response)
    • getObject

      public InputStream getObject(String requestURL, int timeout, int retry) throws TException
      getObject with timeout and retry
      Parameters:
      requestURL - build inputStream to this URL
      timeout - milliseconds for timeout
      retry - number of retry attemps
      Returns:
      InputStream to URL service
      Throws:
      TException
    • dumpHttpResponse

      public static void dumpHttpResponse(HttpResponse<InputStream> response, int goodStatus)
      Used to trace IT calls
      Parameters:
      response - http response
      goodStatus - expected status to skip dump
    • getObjectProperties

      public Properties getObjectProperties(String requestURL, int retry) throws TException
      Get structured properties from a Get request
      Parameters:
      requestURL - build inputStream to this URL
      retry - number of retry attemps
      timeout - milliseconds for timeout
      Returns:
      Properties generated from HTTPResponse
      Throws:
      TException - process Exception
    • getObjectResponse

      public HttpResponse<InputStream> getObjectResponse(String requestURL, int retry) throws TException
      Get structured properties from a Get request
      Parameters:
      requestURL - build inputStream to this URL
      retry - number of retry attemps
      timeout - milliseconds for timeout
      Returns:
      Properties generated from HTTPResponse
      Throws:
      TException - process Exception
    • response2Property

      public static Properties response2Property(HttpResponse<InputStream> response) throws TException
      Throws:
      TException
    • getBasicAuthenticationHeader

      public static final String getBasicAuthenticationHeader(String username, String password)
    • addBasidAuthenticationHeader

      public void addBasidAuthenticationHeader(String username, String password)
    • addBasidAuthenticationToLocalHeader

      public static void addBasidAuthenticationToLocalHeader(String username, String password, HashMap<String,String> localHeaders)
    • getContentLength

      public Long getContentLength(String requestURL) throws TException
      returns content length using head if present
      Parameters:
      requestURL - tested url for length
      Returns:
      >= 0 content length -1 no content-length header found invalid input: '<' -399 negative status code
      Throws:
      TException
    • getHttpClient

      public HttpClient getHttpClient()