Package com.helger.phase4.messaging.http
Class BasicHttpPoster
java.lang.Object
com.helger.phase4.messaging.http.BasicHttpPoster
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull com.helger.httpclient.HttpClientFactoryprotected static @NonNull org.apache.hc.core5.http.HttpEntitycreateDumpingHttpEntity(@Nullable IAS4OutgoingDumper aOutgoingDumper, @NonNull org.apache.hc.core5.http.HttpEntity aSrcEntity, @NonNull @Nonempty String sMessageID, @Nullable com.helger.http.header.HttpHeaderMap aCustomHttpHeaders, int nTry, @NonNull com.helger.base.wrapper.Wrapper<OutputStream> aDumpOSHolder) final @NonNull com.helger.httpclient.HttpClientFactoryfinal @Nullable Consumer<? super org.apache.hc.client5.http.classic.methods.HttpPost> final boolean<T> @Nullable TsendGenericMessage(@NonNull @Nonempty String sURL, @Nullable com.helger.http.header.HttpHeaderMap aCustomHttpHeaders, @NonNull org.apache.hc.core5.http.HttpEntity aHttpEntity, @NonNull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) Deprecated, for removal: This API element is subject to removal in a future version.<T> @Nullable TsendGenericMessage(@NonNull @Nonempty String sURL, @Nullable com.helger.http.header.HttpHeaderMap aCustomHttpHeaders, @NonNull org.apache.hc.core5.http.HttpEntity aHttpEntity, @NonNull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler, @Nullable Consumer<? super com.helger.collection.commons.ICommonsList<X509Certificate>> aRemoteTlsPeerCertConsumer) Send an arbitrary HTTP POST message to the provided URL, using the contained HttpClientFactory as well as the customizer.<T> @Nullable TsendGenericMessageWithRetries(@NonNull String sURL, @Nullable com.helger.http.header.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) Deprecated, for removal: This API element is subject to removal in a future version.<T> @Nullable TsendGenericMessageWithRetries(@NonNull String sURL, @Nullable com.helger.http.header.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, @Nullable Consumer<? super com.helger.collection.commons.ICommonsList<X509Certificate>> aRemoteTlsPeerCertConsumer) Same assendGenericMessageWithRetries(String, HttpHeaderMap, HttpEntity, String, HttpRetrySettings, HttpClientResponseHandler, IAS4OutgoingDumper, IAS4RetryCallback)but additionally surfaces the remote TLS server certificates of the (last) successful HTTPS exchange to the provided consumer.final @NonNull BasicHttpPostersetHttpClientFactory(@NonNull com.helger.httpclient.HttpClientFactory aHttpClientFactory) Set the HTTP client provider to be used.final @NonNull BasicHttpPostersetHttpCustomizer(@Nullable Consumer<? super org.apache.hc.client5.http.classic.methods.HttpPost> aHttpCustomizer) Set the HTTP Post Customizer to be used.final @NonNull BasicHttpPostersetQuoteHttpHeaders(boolean bQuoteHttpHeaders) Enable or disable, if HTTP header values should be quoted or not.toString()
-
Field Details
-
DEFAULT_QUOTE_HTTP_HEADERS
public static final boolean DEFAULT_QUOTE_HTTP_HEADERS- See Also:
-
-
Constructor Details
-
BasicHttpPoster
public BasicHttpPoster()
-
-
Method Details
-
createDefaultHttpClientFactory
public static @NonNull com.helger.httpclient.HttpClientFactory createDefaultHttpClientFactory()- Returns:
- The default
HttpClientFactoryto be used. Nevernull. - Since:
- 0.8.3
-
getHttpClientFactory
public final @NonNull com.helger.httpclient.HttpClientFactory getHttpClientFactory()- Specified by:
getHttpClientFactoryin interfaceIHttpPoster- Returns:
- The internal http client factory used for http sending. May not be
null.
-
setHttpClientFactory
public final @NonNull BasicHttpPoster setHttpClientFactory(@NonNull com.helger.httpclient.HttpClientFactory aHttpClientFactory) Description copied from interface:IHttpPosterSet 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. SeecreateDefaultHttpClientFactory()as the default implementation ofIHttpClientProvider. This factory is used for http sending.- Specified by:
setHttpClientFactoryin interfaceIHttpPoster- Parameters:
aHttpClientFactory- The HTTP client factory to be used. May not benull.- Returns:
- this for chaining
-
getHttpCustomizer
public final @Nullable Consumer<? super org.apache.hc.client5.http.classic.methods.HttpPost> getHttpCustomizer()- Specified by:
getHttpCustomizerin interfaceIHttpPoster- Returns:
- The HTTP Post customizer to be used. May be
null.
-
setHttpCustomizer
public final @NonNull BasicHttpPoster setHttpCustomizer(@Nullable Consumer<? super org.apache.hc.client5.http.classic.methods.HttpPost> aHttpCustomizer) Description copied from interface:IHttpPosterSet the HTTP Post Customizer to be used.- Specified by:
setHttpCustomizerin interfaceIHttpPoster- Parameters:
aHttpCustomizer- The new customizer. May benull.- Returns:
- this for chaining
-
isQuoteHttpHeaders
public final boolean isQuoteHttpHeaders()- Specified by:
isQuoteHttpHeadersin interfaceIHttpPoster- Returns:
trueif HTTP header values should be quoted if they contain forbidden characters,falseif not.
-
setQuoteHttpHeaders
Description copied from interface:IHttpPosterEnable or disable, if HTTP header values should be quoted or not. For compatibility it is recommended, to not quote the values.- Specified by:
setQuoteHttpHeadersin interfaceIHttpPoster- Parameters:
bQuoteHttpHeaders-trueto quote them,falseto not quote them.- Returns:
- this for chaining
-
sendGenericMessage
@Deprecated(forRemoval=true, since="4.5.1") public <T> @Nullable T sendGenericMessage(@Nonempty @NonNull @Nonempty String sURL, @Nullable com.helger.http.header.HttpHeaderMap aCustomHttpHeaders, @NonNull org.apache.hc.core5.http.HttpEntity aHttpEntity, @NonNull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.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:
sendGenericMessagein interfaceIHttpPoster- Type Parameters:
T- Response data type- Parameters:
sURL- The URL to send to. May neither benullnor empty.aCustomHttpHeaders- An optional http header map that should be applied. May benull.aHttpEntity- The HTTP entity to be send. May not benull.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
-
sendGenericMessage
public <T> @Nullable T sendGenericMessage(@Nonempty @NonNull @Nonempty String sURL, @Nullable com.helger.http.header.HttpHeaderMap aCustomHttpHeaders, @NonNull org.apache.hc.core5.http.HttpEntity aHttpEntity, @NonNull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler, @Nullable Consumer<? super com.helger.collection.commons.ICommonsList<X509Certificate>> aRemoteTlsPeerCertConsumer) 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:
sendGenericMessagein interfaceIHttpPoster- Type Parameters:
T- Response data type- Parameters:
sURL- The URL to send to. May neither benullnor empty.aCustomHttpHeaders- An optional http header map that should be applied. May benull.aHttpEntity- The HTTP entity to be send. May not benull.aResponseHandler- The Http response handler that should be used to convert the HTTP response to a domain object.aRemoteTlsPeerCertConsumer- An optional consumer that is invoked with the remote TLS server certificates after a successful HTTPS request. May benull. The list passed in may benullif no certificates were captured (e.g. plain HTTP).- Returns:
- The HTTP response. May be
null. - Throws:
IOException- In case of IO error- Since:
- 4.5.1
-
createDumpingHttpEntity
protected static @NonNull org.apache.hc.core5.http.HttpEntity createDumpingHttpEntity(@Nullable IAS4OutgoingDumper aOutgoingDumper, @NonNull org.apache.hc.core5.http.HttpEntity aSrcEntity, @Nonempty @NonNull @Nonempty String sMessageID, @Nullable com.helger.http.header.HttpHeaderMap aCustomHttpHeaders, @Nonnegative int nTry, @NonNull com.helger.base.wrapper.Wrapper<OutputStream> aDumpOSHolder) throws IOException - Throws:
IOException
-
sendGenericMessageWithRetries
@Deprecated(forRemoval=true, since="4.5.1") public <T> @Nullable T sendGenericMessageWithRetries(@NonNull String sURL, @Nullable com.helger.http.header.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 Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:IHttpPosterSend 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:
sendGenericMessageWithRetriesin interfaceIHttpPoster- Type Parameters:
T- Response data type- Parameters:
sURL- The URL to send to. May neither benullnor empty.aCustomHttpHeaders- An optional http header map that should be applied. May benull.aHttpEntity- The HTTP entity to be send. May not benull.sMessageID- the AS4 message ID. May not benull.aRetrySettings- The retry settings to use. May not benull.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 benullto 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
nullbut basically depends on the response handler. - Throws:
IOException- In case of IO error
-
sendGenericMessageWithRetries
public <T> @Nullable T sendGenericMessageWithRetries(@NonNull String sURL, @Nullable com.helger.http.header.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, @Nullable Consumer<? super com.helger.collection.commons.ICommonsList<X509Certificate>> aRemoteTlsPeerCertConsumer) throws IOException Same assendGenericMessageWithRetries(String, HttpHeaderMap, HttpEntity, String, HttpRetrySettings, HttpClientResponseHandler, IAS4OutgoingDumper, IAS4RetryCallback)but additionally surfaces the remote TLS server certificates of the (last) successful HTTPS exchange to the provided consumer.- Specified by:
sendGenericMessageWithRetriesin interfaceIHttpPoster- Type Parameters:
T- Response data type- Parameters:
sURL- The URL to send to. May neither benullnor empty.aCustomHttpHeaders- An optional http header map that should be applied. May benull.aHttpEntity- The HTTP entity to be send. May not benull.sMessageID- the AS4 message ID. May not benull.aRetrySettings- The retry settings to use. May not benull.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 benullto use the global one.aRetryCallback- An optional retry callback that is invoked, before a retry happens. May benull.aRemoteTlsPeerCertConsumer- An optional consumer that is invoked with the remote TLS server certificates after each successful HTTPS attempt. May benull. The list passed in may benullif no certificates were captured (e.g. plain HTTP).- Returns:
- The HTTP response data as indicated by the ResponseHandler. Should not be
nullbut basically depends on the response handler. - Throws:
IOException- In case of IO error- Since:
- 4.5.1
-
toString
-