Package com.helger.as2lib.util.http
Class HTTPHelper
- java.lang.Object
-
- com.helger.as2lib.util.http.HTTPHelper
-
@ThreadSafe public final class HTTPHelper extends Object
HTTP utility methods.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static StringMA_HTTP_ORIGINAL_CONTENT_LENGTHThe original content length before any eventual decoding (only if Content-Transfer-Encoding is provided)static StringMA_HTTP_ORIGINAL_CONTENT_TRANSFER_ENCODINGThe value of the Content-Transfer-Encoding header (if provided)static StringMA_HTTP_REQ_TYPEThe request method used (POST or GET)static StringMA_HTTP_REQ_URLThe request URL used - defaults to "/"static StringMA_HTTP_REQ_VERSIONThe HTTP version used.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.helger.commons.collection.impl.ICommonsList<String>getAllHTTPHeaderLines(com.helger.commons.http.HttpHeaderMap aHeaders)static IHTTPIncomingDumpergetHTTPIncomingDumper()static Supplier<? extends IHTTPIncomingDumper>getHTTPIncomingDumperFactory()static jakarta.activation.DataSourcereadAndDecodeHttpRequest(IAS2HttpRequestDataProvider aRDP, IAS2HttpResponseHandler aResponseHandler, IMessage aMsg, IHTTPIncomingDumper aIncomingDumper)static intreadChunkLen(InputStream aIS)Read chunk size (including the newline ending it).static com.helger.mail.datasource.IExtendedDataSourcereadHttpRequest(IAS2HttpRequestDataProvider aRDP, IAS2HttpResponseHandler aResponseHandler, IMessage aMsg, IHTTPIncomingDumper aIncomingDumper)Read headers and payload from the passed input stream provider.static voidreadTillNexLine(InputStream aIS)Read up to (and including )CRLF.static voidsendSimpleHTTPResponse(IAS2HttpResponseHandler aResponseHandler, int nResponseCode)Send a simple HTTP response that only contains the HTTP status code and the respective descriptive text.static voidsetHTTPIncomingDumperFactory(Supplier<? extends IHTTPIncomingDumper> aHttpDumperFactory)Set the global factory for creating dumper for incoming HTTP requests.
-
-
-
Field Detail
-
MA_HTTP_REQ_TYPE
public static final String MA_HTTP_REQ_TYPE
The request method used (POST or GET)- See Also:
- Constant Field Values
-
MA_HTTP_REQ_URL
public static final String MA_HTTP_REQ_URL
The request URL used - defaults to "/"- See Also:
- Constant Field Values
-
MA_HTTP_REQ_VERSION
public static final String MA_HTTP_REQ_VERSION
The HTTP version used. E.g. "HTTP/1.1"- See Also:
- Constant Field Values
-
MA_HTTP_ORIGINAL_CONTENT_TRANSFER_ENCODING
public static final String MA_HTTP_ORIGINAL_CONTENT_TRANSFER_ENCODING
The value of the Content-Transfer-Encoding header (if provided)- See Also:
- Constant Field Values
-
MA_HTTP_ORIGINAL_CONTENT_LENGTH
public static final String MA_HTTP_ORIGINAL_CONTENT_LENGTH
The original content length before any eventual decoding (only if Content-Transfer-Encoding is provided)- See Also:
- Constant Field Values
-
-
Method Detail
-
getAllHTTPHeaderLines
@Nonnull @ReturnsMutableCopy public static com.helger.commons.collection.impl.ICommonsList<String> getAllHTTPHeaderLines(@Nonnull com.helger.commons.http.HttpHeaderMap aHeaders)
-
getHTTPIncomingDumper
@Nullable public static IHTTPIncomingDumper getHTTPIncomingDumper()
- Returns:
- the global dumper for incoming HTTP requests or
nullif none is present - Since:
- 3.0.1
-
getHTTPIncomingDumperFactory
@Nonnull public static Supplier<? extends IHTTPIncomingDumper> 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
IExtendedDataSourcethat 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:
IOExceptionjakarta.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
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
- Throws:
IOException- if stream ends during chunk length read
-
readTillNexLine
public static void readTillNexLine(@Nonnull @WillNotClose InputStream aIS) throws IOException
Read up to (and including )CRLF.- Parameters:
aIS- - input stream to read from- Throws:
IOException- if stream ends during chunk length read
-
-