Package com.helger.as2lib.util.http
Class AS2HttpClient
java.lang.Object
com.helger.as2lib.util.http.AS2HttpClient
Http connection, Implemented as HttpClient.
- Author:
- Ziv Harpaz, Philip Helger
-
Constructor Summary
ConstructorDescriptionAS2HttpClient
(String sUrl, org.apache.hc.core5.util.Timeout aConnectTimeout, org.apache.hc.core5.util.Timeout aResponseTimeout, com.helger.commons.http.EHttpMethod eRequestMethod, Proxy aProxy, SSLContext aSSLContext, HostnameVerifier aHV) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Close the connectionGet InputStreamint
com.helger.commons.http.HttpHeaderMap
getURL()
static boolean
isErrorResponseCode
(int nResponseCode) This method determines if something is an HTTP error or not.long
send
(InputStream aISToSend, com.helger.mail.cte.EContentTransferEncoding eCTE, IHTTPOutgoingDumper aOutgoingDumper, AS2ResourceHelper aResHelper) void
setHttpHeader
(String sName, String sValue) Set an HTTP header (replacing existing value).
-
Constructor Details
-
AS2HttpClient
public AS2HttpClient(@Nonnull @Nonempty String sUrl, @Nonnull org.apache.hc.core5.util.Timeout aConnectTimeout, @Nonnull org.apache.hc.core5.util.Timeout aResponseTimeout, @Nonnull com.helger.commons.http.EHttpMethod eRequestMethod, @Nullable Proxy aProxy, @Nullable SSLContext aSSLContext, @Nullable HostnameVerifier aHV)
-
-
Method Details
-
setHttpHeader
Set an HTTP header (replacing existing value). No modification or check on name or value happens.- Parameters:
sName
- Header name. May not benull
.sValue
- Header value. May not benull
.
-
getURL
- Returns:
- The URL to send to. Should be the same as the one passed in the
constructor. Never
null
. - Throws:
AS2Exception
- in case of error (e.g. if the URI could not be converted to a URL).
-
send
@Nonnegative public long send(@Nonnull @WillClose InputStream aISToSend, @Nullable com.helger.mail.cte.EContentTransferEncoding eCTE, @Nullable IHTTPOutgoingDumper aOutgoingDumper, @Nonnull AS2ResourceHelper aResHelper) throws IOException - Parameters:
aISToSend
- InputStream to send. May not benull
.eCTE
- Content-Transfer-Encoding to be used. May not benull
.aOutgoingDumper
- Optional outgoing dumperaResHelper
- Resource helper- Returns:
- bytes sent. Must be ≥ 0.
- Throws:
IOException
- In case of error
-
getInputStream
Get InputStream- Returns:
- InputStream to read response body from
- Throws:
AS2Exception
- in case of errorIOException
- in case of IO error
-
getResponseCode
- Returns:
- response HTTP Status as int
- Throws:
AS2Exception
- in case of error
-
getResponseMessage
- Returns:
- the response message
- Throws:
AS2Exception
- in case of error
-
getResponseHeaderFields
@Nonnull @ReturnsMutableCopy public com.helger.commons.http.HttpHeaderMap getResponseHeaderFields() throws AS2Exception- Throws:
AS2Exception
-
disconnect
public void disconnect()Close the connection -
isErrorResponseCode
public static boolean isErrorResponseCode(int nResponseCode) This method determines if something is an HTTP error or not. The following HTTP status codes are interpreted as success: 200, 201, 202, 204 and 206.- Parameters:
nResponseCode
- The HTTP status code to check.- Returns:
true
if it is an error,false
on success.
-