Package com.hybris.ymkt.common.http
Class HttpURLConnectionService
java.lang.Object
com.hybris.ymkt.common.http.HttpURLConnectionService
This bean shall be instantiated only once for the entire server/tenant.
All methods could have been public static but are defined this way to allow overriding.
This service only works with byte[] instead of
All methods could have been public static but are defined this way to allow overriding.
This service only works with byte[] instead of
InputStream & OutputStream. It is important that all
intended input and output payloads fit into memory.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]bufferStream(InputStream stream) Utility method to extract all bytes of theInputStreamand return them as a byte array.protected voiddisableHttpsCertificate(HttpsURLConnection connection) execute(HttpURLConnectionRequest request) This method execute a request and return a response.
No exception will be thrown as the caller is responsible to check theHttpURLConnectionResponse.getIOException().protected voidlogExecution(HttpURLConnectionRequest request, HttpURLConnectionResponse response) voidsetConnectTimeout(int connectTimeout) voidsetReadTimeout(int readTimeout) protected void
-
Field Details
-
connectTimeout
protected int connectTimeout -
readTimeout
protected int readTimeout
-
-
Constructor Details
-
HttpURLConnectionService
public HttpURLConnectionService()
-
-
Method Details
-
bufferStream
Utility method to extract all bytes of theInputStreamand return them as a byte array.- Parameters:
stream-InputStreamto be converted into byte[].- Returns:
- byte array containing all bytes of the
InputStream. The length of the array equals to total number of bytes read. - Throws:
IOException- May be thrown by the following 2 methods :InputStream.read()andInputStream.close()
-
disableHttpsCertificate
-
execute
This method execute a request and return a response.
No exception will be thrown as the caller is responsible to check theHttpURLConnectionResponse.getIOException().- Parameters:
request-HttpURLConnectionRequest- Returns:
HttpURLConnectionResponse
-
logExecution
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout) - Parameters:
connectTimeout- an int that specifies the connect timeout value in milliseconds- See Also:
-
setReadTimeout
public void setReadTimeout(int readTimeout) - Parameters:
readTimeout- an int that specifies the timeout value to be used in milliseconds- See Also:
-
trace
-