Package com.hybris.ymkt.common.http
Class HttpURLConnectionService
- java.lang.Object
-
- com.hybris.ymkt.common.http.HttpURLConnectionService
-
public class HttpURLConnectionService extends java.lang.ObjectThis 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 ofInputStream&OutputStream. It is important that all intended input and output payloads fit into memory.
-
-
Field Summary
Fields Modifier and Type Field Description protected intconnectTimeoutprotected intreadTimeout
-
Constructor Summary
Constructors Constructor Description HttpURLConnectionService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]bufferStream(java.io.InputStream stream)Utility method to extract all bytes of theInputStreamand return them as a byte array.protected voiddisableHttpsCertificate(javax.net.ssl.HttpsURLConnection connection)HttpURLConnectionResponseexecute(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 voidtrace(java.util.Map<java.lang.String,java.util.List<java.lang.String>> fields)
-
-
-
Method Detail
-
bufferStream
@Nonnull public byte[] bufferStream(java.io.InputStream stream) throws java.io.IOExceptionUtility 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:
java.io.IOException- May be thrown by the following 2 methods :InputStream.read()andInputStream.close()
-
disableHttpsCertificate
protected void disableHttpsCertificate(javax.net.ssl.HttpsURLConnection connection)
-
execute
@Nonnull public HttpURLConnectionResponse 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().- Parameters:
request-HttpURLConnectionRequest- Returns:
HttpURLConnectionResponse
-
logExecution
protected void logExecution(HttpURLConnectionRequest request, HttpURLConnectionResponse response)
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
- Parameters:
connectTimeout- an int that specifies the connect timeout value in milliseconds- See Also:
URLConnection.setConnectTimeout(int)
-
setReadTimeout
public void setReadTimeout(int readTimeout)
- Parameters:
readTimeout- an int that specifies the timeout value to be used in milliseconds- See Also:
URLConnection.setReadTimeout(int)
-
trace
protected void trace(java.util.Map<java.lang.String,java.util.List<java.lang.String>> fields)
-
-