Search in sources :

Example 1 with AS4DumpManager

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);
}
Also used : StatusLine(org.apache.http.StatusLine) BasicHttpPoster(com.helger.phase4.http.BasicHttpPoster) IGenericImplTrait(com.helger.commons.traits.IGenericImplTrait) MessageHelperMethods(com.helger.phase4.messaging.domain.MessageHelperMethods) PModeReceptionAwareness(com.helger.phase4.model.pmode.PModeReceptionAwareness) ESoapVersion(com.helger.phase4.soap.ESoapVersion) HttpHeaderMap(com.helger.commons.http.HttpHeaderMap) AS4HttpDebug(com.helger.phase4.http.AS4HttpDebug) MessagingException(javax.mail.MessagingException) MetaAS4Manager(com.helger.phase4.mgr.MetaAS4Manager) IMicroDocument(com.helger.xml.microdom.IMicroDocument) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) Supplier(java.util.function.Supplier) Header(org.apache.http.Header) StatusLine(org.apache.http.StatusLine) AS4CryptParams(com.helger.phase4.crypto.AS4CryptParams) EAS4MessageType(com.helger.phase4.messaging.domain.EAS4MessageType) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Nonempty(com.helger.commons.annotation.Nonempty) IHttpPoster(com.helger.phase4.http.IHttpPoster) Duration(java.time.Duration) AS4ResourceHelper(com.helger.phase4.util.AS4ResourceHelper) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IAS4OutgoingDumper(com.helger.phase4.dump.IAS4OutgoingDumper) WillNotClose(javax.annotation.WillNotClose) AS4SigningParams(com.helger.phase4.crypto.AS4SigningParams) IPMode(com.helger.phase4.model.pmode.IPMode) StringHelper(com.helger.commons.string.StringHelper) HttpEntity(org.apache.http.HttpEntity) IOException(java.io.IOException) ResponseHandlerMicroDom(com.helger.httpclient.response.ResponseHandlerMicroDom) ValueEnforcer(com.helger.commons.ValueEnforcer) AS4DumpManager(com.helger.phase4.dump.AS4DumpManager) HttpRetrySettings(com.helger.phase4.http.HttpRetrySettings) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) OffsetDateTime(java.time.OffsetDateTime) Wrapper(com.helger.commons.wrapper.Wrapper) ReturnsMutableObject(com.helger.commons.annotation.ReturnsMutableObject) ResponseHandler(org.apache.http.client.ResponseHandler) HttpHeaderMap(com.helger.commons.http.HttpHeaderMap) Wrapper(com.helger.commons.wrapper.Wrapper) HttpEntity(org.apache.http.HttpEntity) Header(org.apache.http.Header) Nonnull(javax.annotation.Nonnull)

Aggregations

ValueEnforcer (com.helger.commons.ValueEnforcer)1 Nonempty (com.helger.commons.annotation.Nonempty)1 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)1 HttpHeaderMap (com.helger.commons.http.HttpHeaderMap)1 StringHelper (com.helger.commons.string.StringHelper)1 IGenericImplTrait (com.helger.commons.traits.IGenericImplTrait)1 Wrapper (com.helger.commons.wrapper.Wrapper)1 ResponseHandlerMicroDom (com.helger.httpclient.response.ResponseHandlerMicroDom)1 AS4CryptParams (com.helger.phase4.crypto.AS4CryptParams)1 AS4SigningParams (com.helger.phase4.crypto.AS4SigningParams)1 IAS4CryptoFactory (com.helger.phase4.crypto.IAS4CryptoFactory)1 AS4DumpManager (com.helger.phase4.dump.AS4DumpManager)1 IAS4OutgoingDumper (com.helger.phase4.dump.IAS4OutgoingDumper)1 AS4HttpDebug (com.helger.phase4.http.AS4HttpDebug)1 BasicHttpPoster (com.helger.phase4.http.BasicHttpPoster)1 HttpRetrySettings (com.helger.phase4.http.HttpRetrySettings)1 IHttpPoster (com.helger.phase4.http.IHttpPoster)1 EAS4MessageType (com.helger.phase4.messaging.domain.EAS4MessageType)1 MessageHelperMethods (com.helger.phase4.messaging.domain.MessageHelperMethods)1 MetaAS4Manager (com.helger.phase4.mgr.MetaAS4Manager)1