Class BasicHttpPoster

java.lang.Object
com.helger.phase4.messaging.http.BasicHttpPoster
All Implemented Interfaces:
IHttpPoster

public class BasicHttpPoster extends Object implements IHttpPoster
A generic HTTP POST wrapper based on IHttpClientProvider and HttpPost. Since 0.13.0 this is a standalone class which is injected as a member into the respective AS4 clients.
Author:
Philip Helger
  • Field Details

    • DEFAULT_QUOTE_HTTP_HEADERS

      public static final boolean DEFAULT_QUOTE_HTTP_HEADERS
      See Also:
  • Constructor Details

    • BasicHttpPoster

      public BasicHttpPoster()
  • Method Details

    • createDefaultHttpClientFactory

      @Nonnull public static com.helger.httpclient.HttpClientFactory createDefaultHttpClientFactory()
      Returns:
      The default HttpClientFactory to be used. Never null.
      Since:
      0.8.3
    • getHttpClientFactory

      @Nonnull public final com.helger.httpclient.HttpClientFactory getHttpClientFactory()
      Specified by:
      getHttpClientFactory in interface IHttpPoster
      Returns:
      The internal http client factory used for http sending. May not be null.
    • setHttpClientFactory

      @Nonnull public final BasicHttpPoster setHttpClientFactory(@Nonnull com.helger.httpclient.HttpClientFactory aHttpClientFactory)
      Description copied from interface: IHttpPoster
      Set the HTTP client provider to be used. This is e.g. necessary when a custom SSL context or a proxy server is to be used. See createDefaultHttpClientFactory() as the default implementation of IHttpClientProvider. This factory is used for http sending.
      Specified by:
      setHttpClientFactory in interface IHttpPoster
      Parameters:
      aHttpClientFactory - The HTTP client factory to be used. May not be null.
      Returns:
      this for chaining
    • getHttpCustomizer

      @Nullable public final Consumer<? super org.apache.hc.client5.http.classic.methods.HttpPost> getHttpCustomizer()
      Specified by:
      getHttpCustomizer in interface IHttpPoster
      Returns:
      The HTTP Post customizer to be used. May be null.
    • setHttpCustomizer

      @Nonnull public final BasicHttpPoster setHttpCustomizer(@Nullable Consumer<? super org.apache.hc.client5.http.classic.methods.HttpPost> aHttpCustomizer)
      Description copied from interface: IHttpPoster
      Set the HTTP Post Customizer to be used.
      Specified by:
      setHttpCustomizer in interface IHttpPoster
      Parameters:
      aHttpCustomizer - The new customizer. May be null.
      Returns:
      this for chaining
    • isQuoteHttpHeaders

      public final boolean isQuoteHttpHeaders()
      Specified by:
      isQuoteHttpHeaders in interface IHttpPoster
      Returns:
      true if HTTP header values should be quoted if they contain forbidden characters, false if not.
    • setQuoteHttpHeaders

      @Nonnull public final BasicHttpPoster setQuoteHttpHeaders(boolean bQuoteHttpHeaders)
      Description copied from interface: IHttpPoster
      Enable or disable, if HTTP header values should be quoted or not. For compatibility it is recommended, to not quote the values.
      Specified by:
      setQuoteHttpHeaders in interface IHttpPoster
      Parameters:
      bQuoteHttpHeaders - true to quote them, false to not quote them.
      Returns:
      this for chaining
    • sendGenericMessage

      @Nullable public <T> T sendGenericMessage(@Nonnull @Nonempty String sURL, @Nullable com.helger.commons.http.HttpHeaderMap aCustomHttpHeaders, @Nonnull org.apache.hc.core5.http.HttpEntity aHttpEntity, @Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) throws IOException
      Send an arbitrary HTTP POST message to the provided URL, using the contained HttpClientFactory as well as the customizer. Additionally the AS4 HTTP debugging is invoked in here.
      This method does NOT retry
      Specified by:
      sendGenericMessage in interface IHttpPoster
      Type Parameters:
      T - Response data type
      Parameters:
      sURL - The URL to send to. May neither be null nor empty.
      aCustomHttpHeaders - An optional http header map that should be applied. May be null.
      aHttpEntity - The HTTP entity to be send. May not be null.
      aResponseHandler - The Http response handler that should be used to convert the HTTP response to a domain object.
      Returns:
      The HTTP response. May be null.
      Throws:
      IOException - In case of IO error
    • createDumpingHttpEntity

      @Nonnull protected static org.apache.hc.core5.http.HttpEntity createDumpingHttpEntity(@Nullable IAS4OutgoingDumper aOutgoingDumper, @Nonnull org.apache.hc.core5.http.HttpEntity aSrcEntity, @Nonnull @Nonempty String sMessageID, @Nullable com.helger.commons.http.HttpHeaderMap aCustomHttpHeaders, @Nonnegative int nTry, @Nonnull com.helger.commons.wrapper.Wrapper<OutputStream> aDumpOSHolder) throws IOException
      Throws:
      IOException
    • sendGenericMessageWithRetries

      @Nullable public <T> T sendGenericMessageWithRetries(@Nonnull String sURL, @Nullable com.helger.commons.http.HttpHeaderMap aCustomHttpHeaders, @Nonnull org.apache.hc.core5.http.HttpEntity aHttpEntity, @Nonnull String sMessageID, @Nonnull HttpRetrySettings aRetrySettings, @Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler, @Nullable IAS4OutgoingDumper aOutgoingDumper, @Nullable IAS4RetryCallback aRetryCallback) throws IOException
      Description copied from interface: IHttpPoster
      Send an arbitrary HTTP POST message to the provided URL, using the contained HttpClientFactory as well as the customizer. Additionally the AS4 HTTP debugging is invoked in here.
      Specified by:
      sendGenericMessageWithRetries in interface IHttpPoster
      Type Parameters:
      T - Response data type
      Parameters:
      sURL - The URL to send to. May neither be null nor empty.
      aCustomHttpHeaders - An optional http header map that should be applied. May be null.
      aHttpEntity - The HTTP entity to be send. May not be null.
      sMessageID - the AS4 message ID. May not be null.
      aRetrySettings - The retry settings to use. May not be null.
      aResponseHandler - The HTTP response handler that should be used to convert the HTTP response to a domain object.
      aOutgoingDumper - An optional outgoing dumper for this message. May be null to use the global one.
      aRetryCallback - An optional retry callback that is invoked, before a retry happens.
      Returns:
      The HTTP response data as indicated by the ResponseHandler. Should not be null but basically depends on the response handler.
      Throws:
      IOException - In case of IO error
    • toString

      public String toString()
      Overrides:
      toString in class Object