use of com.helger.phase4.dump.AS4DumpManager in project phase4 by phax.
the class AbstractAS4Client method sendMessageWithRetries.
/**
* Send the AS4 client message created by
* {@link #buildMessage(String, IAS4ClientBuildMessageCallback)} to the
* provided URL. This methods does take retries into account. It synchronously
* handles the retries and only returns after the last retry.
*
* @param <T>
* The response data type
* @param sURL
* The URL to send the HTTP POST to
* @param aResponseHandler
* The response handler that converts the HTTP response to a domain
* object. May not be <code>null</code>.
* @param aCallback
* An optional callback for the different stages of building the
* document. May be <code>null</code>.
* @param aOutgoingDumper
* An outgoing dumper to be used. Maybe <code>null</code>. If
* <code>null</code> the global outgoing dumper from
* {@link AS4DumpManager} is used.
* @param aRetryCallback
* An optional callback to be invoked if a retry happens on HTTP level.
* May be <code>null</code>.
* @return The sent message that contains
* @throws IOException
* in case of error when building or sending the message
* @throws WSSecurityException
* In case there is an issue with signing/encryption
* @throws MessagingException
* in case something happens in MIME wrapping
* @since 0.9.14
*/
@Nonnull
public final <T> AS4ClientSentMessage<T> sendMessageWithRetries(@Nonnull final String sURL, @Nonnull final ResponseHandler<? extends T> aResponseHandler, @Nullable final IAS4ClientBuildMessageCallback aCallback, @Nullable final IAS4OutgoingDumper aOutgoingDumper, @Nullable final IAS4RetryCallback aRetryCallback) throws IOException, WSSecurityException, MessagingException {
// Create a new message ID for each build!
final String sMessageID = createMessageID();
final AS4ClientBuiltMessage aBuiltMsg = buildMessage(sMessageID, aCallback);
HttpEntity aBuiltEntity = aBuiltMsg.getHttpEntity();
final HttpHeaderMap aBuiltHttpHeaders = aBuiltMsg.getCustomHeaders();
if (m_aHttpRetrySettings.isRetryEnabled() || aOutgoingDumper != null || AS4DumpManager.getOutgoingDumper() != null) {
// Ensure a repeatable entity is provided
aBuiltEntity = m_aResHelper.createRepeatableHttpEntity(aBuiltEntity);
}
// Keep the HTTP response status line for external evaluation
final Wrapper<StatusLine> aStatusLineKeeper = new Wrapper<>();
// Keep the HTTP response headers for external evaluation
final HttpHeaderMap aResponseHeaders = new HttpHeaderMap();
final ResponseHandler<T> aRealResponseHandler = x -> {
// Remember the HTTP response data
aStatusLineKeeper.set(x.getStatusLine());
final Header[] aHeaders = x.getAllHeaders();
if (aHeaders != null)
for (final Header aHeader : aHeaders) aResponseHeaders.addHeader(aHeader.getName(), aHeader.getValue());
// Call the original handler
return aResponseHandler.handleResponse(x);
};
final T aResponseContent = m_aHttpPoster.sendGenericMessageWithRetries(sURL, aBuiltHttpHeaders, aBuiltEntity, sMessageID, m_aHttpRetrySettings, aRealResponseHandler, aOutgoingDumper, aRetryCallback);
return new AS4ClientSentMessage<>(aBuiltMsg, aStatusLineKeeper.get(), aResponseHeaders, aResponseContent);
}
Aggregations