Package org.cdlib.mrt.utility
Class HTTPGetUtil
java.lang.Object
org.cdlib.mrt.utility.HTTPGetUtil
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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHTTPGetUtil(int timeout, String proxyHost, Integer proxyPort, HashMap headers) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBasidAuthenticationHeader(String username, String password) static voidaddBasidAuthenticationToLocalHeader(String username, String password, HashMap<String, String> localHeaders) addHeaders(HttpRequest.Builder requestBuilder) static HTTPGetUtilBuild HTTPGetUtilstatic HTTPGetUtilBuild HTTPGetUtilstatic voiddumpHttpResponse(HttpResponse<InputStream> response, int goodStatus) Used to trace IT callsstatic final StringgetBasicAuthenticationHeader(String username, String password) getContentLength(String requestURL) returns content length using head if presentSend this manifestFile to mrt storegetObject with timeout and retrygetObjectProperties(String requestURL, int retry) Get structured properties from a Get requestgetObjectResponse(String requestURL, int retry) Get structured properties from a Get requestgetObjectStream(String requestURLS, long startByte, long endByte) Send this manifestFile to mrt storegetStreamResponse(String requestURLS) Get java HttpResponse for GetgetStreamResponse(String requestURLS, long startByte, long endByte) Send this manifestFile to mrt storestatic booleanisChunked(HttpResponse response) static Propertiesresponse2Property(HttpResponse<InputStream> response)
-
Field Details
-
DEFAULT_TIMEOUT
protected static final int DEFAULT_TIMEOUT- See Also:
-
httpClient
-
headers
-
timeout
protected int timeout
-
-
Constructor Details
-
HTTPGetUtil
protected HTTPGetUtil(int timeout, String proxyHost, Integer proxyPort, HashMap headers) throws TException - Throws:
TException
-
-
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 proxyproxyPort- service port of forward prosy - if proxy requiredheaders- 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 timeoutproxyHost- service name (not url) of forward proxy - null=no proxyproxyPort- service port of forward prosy - if proxy requiredheaders- map of headers to be used for each GET request- Returns:
- HTTPGETUtil
- Throws:
TException
-
getStreamResponse
Get java HttpResponse for Get- Parameters:
requestURLS- Url for content- Returns:
- java HttpResponse
- Throws:
TException
-
getObject
Send this manifestFile to mrt store- Parameters:
requestURLS- url for content- Returns:
- InputStream content
-
addHeaders
-
getStreamResponse
public HttpResponse<InputStream> getStreamResponse(String requestURLS, long startByte, long endByte) throws TException Send this manifestFile to mrt store- Parameters:
requestURLS- stream source of contentstartByte- starting byte (from 0) for extractionendByte- 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
-
getObject
getObject with timeout and retry- Parameters:
requestURL- build inputStream to this URLtimeout- milliseconds for timeoutretry- number of retry attemps- Returns:
- InputStream to URL service
- Throws:
TException
-
dumpHttpResponse
Used to trace IT calls- Parameters:
response- http responsegoodStatus- expected status to skip dump
-
getObjectProperties
Get structured properties from a Get request- Parameters:
requestURL- build inputStream to this URLretry- number of retry attempstimeout- milliseconds for timeout- Returns:
- Properties generated from HTTPResponse
- Throws:
TException- process Exception
-
getObjectResponse
Get structured properties from a Get request- Parameters:
requestURL- build inputStream to this URLretry- number of retry attempstimeout- milliseconds for timeout- Returns:
- Properties generated from HTTPResponse
- Throws:
TException- process Exception
-
response2Property
- Throws:
TException
-
getBasicAuthenticationHeader
-
addBasidAuthenticationHeader
-
addBasidAuthenticationToLocalHeader
-
getContentLength
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
-