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 Details

    • MA_HTTP_REQ_TYPE

      public static final String MA_HTTP_REQ_TYPE
      The request method used (POST or GET)
      See Also:
    • MA_HTTP_REQ_URL

      public static final String MA_HTTP_REQ_URL
      The request URL used - defaults to "/"
      See Also:
    • MA_HTTP_REQ_VERSION

      public static final String MA_HTTP_REQ_VERSION
      The HTTP version used. E.g. "HTTP/1.1"
      See Also:
    • 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:
    • 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:
  • Method Details

    • 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 null if 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 be null.
      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, return DataSource. If is on, data is not read.
      Parameters:
      aRDP - The abstract input stream provider to use. May not be null.
      aResponseHandler - The HTTP response handler to be used. May not be null.
      aMsg - The Message to be filled. May not be null.
      aIncomingDumper - Optional incoming HTTP dumper. May be null.
      Returns:
      A IExtendedDataSource that holds/refers to the body.
      Throws:
      IOException - In case of error reading from the InputStream
      jakarta.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. Use readTillNextLine(InputStream) instead
      Read up to (and including) CRLF.
      Parameters:
      aIS - input stream to read from
      Throws:
      IOException - if stream ends during chunk length read
    • readTillNextLine

      public static void readTillNextLine(@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