Package com.helger.as2lib.util.http
Class HTTPHelper
java.lang.Object
com.helger.as2lib.util.http.HTTPHelper
HTTP utility methods.
- Author:
- Philip Helger
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The original content length before any eventual decoding (only if Content-Transfer-Encoding is provided)static final String
The value of the Content-Transfer-Encoding header (if provided)static final String
The request method used (POST or GET)static final String
The request URL used - defaults to "/"static final String
The HTTP version used. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.helger.commons.collection.impl.ICommonsList<String>
getAllHTTPHeaderLines
(com.helger.commons.http.HttpHeaderMap aHeaders) static IHTTPIncomingDumper
static Supplier<? extends IHTTPIncomingDumper>
static jakarta.activation.DataSource
readAndDecodeHttpRequest
(IAS2HttpRequestDataProvider aRDP, IAS2HttpResponseHandler aResponseHandler, IMessage aMsg, IHTTPIncomingDumper aIncomingDumper) static int
readChunkLen
(InputStream aIS) Read chunk size (including the newline ending it).static com.helger.mail.datasource.IExtendedDataSource
readHttpRequest
(IAS2HttpRequestDataProvider aRDP, IAS2HttpResponseHandler aResponseHandler, IMessage aMsg, IHTTPIncomingDumper aIncomingDumper) Read headers and payload from the passed input stream provider.static void
Deprecated.Since 5.1.1.static void
Read up to (and including) CRLF.static void
sendSimpleHTTPResponse
(IAS2HttpResponseHandler aResponseHandler, int nResponseCode) Send a simple HTTP response that only contains the HTTP status code and the respective descriptive text.static void
setHTTPIncomingDumperFactory
(Supplier<? extends IHTTPIncomingDumper> aHttpDumperFactory) Set the global factory for creating dumper for incoming HTTP requests.
-
Field Details
-
MA_HTTP_REQ_TYPE
The request method used (POST or GET)- See Also:
-
MA_HTTP_REQ_URL
The request URL used - defaults to "/"- See Also:
-
MA_HTTP_REQ_VERSION
The HTTP version used. E.g. "HTTP/1.1"- See Also:
-
MA_HTTP_ORIGINAL_CONTENT_TRANSFER_ENCODING
The value of the Content-Transfer-Encoding header (if provided)- See Also:
-
MA_HTTP_ORIGINAL_CONTENT_LENGTH
The original content length before any eventual decoding (only if Content-Transfer-Encoding is provided)- See Also:
-
-
Method Details
-
getAllHTTPHeaderLines
-
getHTTPIncomingDumper
- Returns:
- the global dumper for incoming HTTP requests or
null
if none is present - Since:
- 3.0.1
-
getHTTPIncomingDumperFactory
- Returns:
- the global dumper factory for incoming HTTP requests. Never
null
. - Since:
- 4.4.0
-
setHTTPIncomingDumperFactory
public static void setHTTPIncomingDumperFactory(@Nonnull Supplier<? extends IHTTPIncomingDumper> aHttpDumperFactory) Set the global factory for creating dumper for incoming HTTP requests.- Parameters:
aHttpDumperFactory
- The dumper factory to be used. May not benull
.- Since:
- 3.1.0
-
readHttpRequest
@Nonnull public static com.helger.mail.datasource.IExtendedDataSource readHttpRequest(@Nonnull IAS2HttpRequestDataProvider aRDP, @Nonnull IAS2HttpResponseHandler aResponseHandler, @Nonnull IMessage aMsg, @Nullable IHTTPIncomingDumper aIncomingDumper) throws IOException, jakarta.mail.MessagingException Read headers and payload from the passed input stream provider. For large file support, returnDataSource
. If is on, data is not read.- Parameters:
aRDP
- The abstract input stream provider to use. May not benull
.aResponseHandler
- The HTTP response handler to be used. May not benull
.aMsg
- The Message to be filled. May not benull
.aIncomingDumper
- Optional incoming HTTP dumper. May benull
.- Returns:
- A
IExtendedDataSource
that holds/refers to the body. - Throws:
IOException
- In case of error reading from the InputStreamjakarta.mail.MessagingException
- In case header line parsing fails
-
readAndDecodeHttpRequest
@Nonnull public static jakarta.activation.DataSource readAndDecodeHttpRequest(@Nonnull IAS2HttpRequestDataProvider aRDP, @Nonnull IAS2HttpResponseHandler aResponseHandler, @Nonnull IMessage aMsg, @Nullable IHTTPIncomingDumper aIncomingDumper) throws IOException, jakarta.mail.MessagingException - Throws:
IOException
jakarta.mail.MessagingException
-
sendSimpleHTTPResponse
public static void sendSimpleHTTPResponse(@Nonnull IAS2HttpResponseHandler aResponseHandler, @Nonnegative int nResponseCode) throws IOException Send a simple HTTP response that only contains the HTTP status code and the respective descriptive text. An empty header map us used.- Parameters:
aResponseHandler
- The response handler to be used.nResponseCode
- The HTTP response code to use.- Throws:
IOException
- In case sending fails for whatever reason
-
readChunkLen
@Nonnegative public static int readChunkLen(@Nonnull @WillNotClose InputStream aIS) throws IOException Read chunk size (including the newline ending it). Discard any other data, e.g. headers that my be there.- Parameters:
aIS
- - input stream to read from- Returns:
- Chunk length. Should always be ≥ 0.
- Throws:
IOException
- if stream ends during chunk length read
-
readTillNexLine
@Deprecated public static void readTillNexLine(@Nonnull @WillNotClose InputStream aIS) throws IOException Deprecated.Since 5.1.1. UsereadTillNextLine(InputStream)
insteadRead up to (and including) CRLF.- Parameters:
aIS
- input stream to read from- Throws:
IOException
- if stream ends during chunk length read
-
readTillNextLine
Read up to (and including) CRLF.- Parameters:
aIS
- input stream to read from- Throws:
IOException
- if stream ends during chunk length read
-