Search in sources :

Example 1 with IHTTPOutgoingDumper

use of com.helger.as2lib.util.dump.IHTTPOutgoingDumper in project as2-lib by phax.

the class AS2SenderModule method handle.

public void handle(@Nonnull final String sAction, @Nonnull final IMessage aBaseMsg, @Nullable final Map<String, Object> aOptions) throws AS2Exception {
    final AS2Message aMsg = (AS2Message) aBaseMsg;
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Submitting message" + aMsg.getLoggingText());
    // verify all required information is present for sending
    checkRequired(aMsg);
    final int nRetries = getRetryCount(aMsg.partnership(), aOptions);
    try (final AS2ResourceHelper aResHelper = new AS2ResourceHelper()) {
        // Get Content-Transfer-Encoding to use
        final String sContentTransferEncoding = aMsg.partnership().getContentTransferEncodingSend(EContentTransferEncoding.AS2_DEFAULT.getID());
        final EContentTransferEncoding eCTE = EContentTransferEncoding.getFromIDCaseInsensitiveOrDefault(sContentTransferEncoding, EContentTransferEncoding.AS2_DEFAULT);
        // compress and/or sign and/or encrypt the message if needed
        final MimeBodyPart aSecuredData = secure(aMsg, eCTE);
        // Calculate MIC after compress/sign/crypt was handled, because the
        // message data might change if compression before signing is active.
        final MIC aMIC;
        if (aMsg.isRequestingMDN())
            aMIC = calculateAndStoreMIC(aMsg);
        else
            aMIC = null;
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Setting message content type to '" + aSecuredData.getContentType() + "'");
        aMsg.setContentType(aSecuredData.getContentType());
        try (final IHTTPOutgoingDumper aOutgoingDumper = getHttpOutgoingDumper(aMsg)) {
            final IHTTPIncomingDumper aIncomingDumper = getEffectiveHttpIncomingDumper();
            // Use no CTE, because it was set on all MIME parts
            _sendViaHTTP(aMsg, aSecuredData, aMIC, true ? null : eCTE, aOutgoingDumper, aIncomingDumper, aResHelper);
        }
    } catch (final AS2HttpResponseException ex) {
        if (LOGGER.isErrorEnabled())
            LOGGER.error("Http Response Error " + ex.getMessage());
        ex.terminate(aMsg);
        if (!doResend(IProcessorSenderModule.DO_SEND, aMsg, ex, nRetries))
            throw ex;
    } catch (final IOException ex) {
        // Re-send if a network error occurs during transmission
        final AS2Exception wioe = WrappedAS2Exception.wrap(ex).setSourceMsg(aMsg).terminate();
        if (!doResend(IProcessorSenderModule.DO_SEND, aMsg, wioe, nRetries))
            throw wioe;
    } catch (final Exception ex) {
        // Propagate error if it can't be handled by a re-send
        throw WrappedAS2Exception.wrap(ex);
    }
}
Also used : EContentTransferEncoding(com.helger.mail.cte.EContentTransferEncoding) MIC(com.helger.as2lib.crypto.MIC) IHTTPOutgoingDumper(com.helger.as2lib.util.dump.IHTTPOutgoingDumper) IOException(java.io.IOException) MessagingException(javax.mail.MessagingException) AS2NoModuleException(com.helger.as2lib.processor.AS2NoModuleException) AS2DispositionException(com.helger.as2lib.disposition.AS2DispositionException) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) IOException(java.io.IOException) AS2InvalidParameterException(com.helger.as2lib.params.AS2InvalidParameterException) SMIMEException(org.bouncycastle.mail.smime.SMIMEException) AS2ComponentNotFoundException(com.helger.as2lib.session.AS2ComponentNotFoundException) IHTTPIncomingDumper(com.helger.as2lib.util.dump.IHTTPIncomingDumper) AS2ResourceHelper(com.helger.as2lib.util.AS2ResourceHelper) AS2Message(com.helger.as2lib.message.AS2Message) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 2 with IHTTPOutgoingDumper

use of com.helger.as2lib.util.dump.IHTTPOutgoingDumper in project as2-lib by phax.

the class AsynchMDNSenderModule method handle.

public void handle(@Nonnull final String sAction, @Nonnull final IMessage aBaseMsg, @Nullable final Map<String, Object> aOptions) throws AS2Exception {
    try (final AS2ResourceHelper aResHelper = new AS2ResourceHelper()) {
        final AS2Message aMsg = (AS2Message) aBaseMsg;
        if (LOGGER.isInfoEnabled())
            LOGGER.info("Async MDN submitted" + aMsg.getLoggingText());
        final DispositionType aDisposition = DispositionType.createSuccess();
        final int nRetries = getRetryCount(aMsg.partnership(), aOptions);
        try (final IHTTPOutgoingDumper aOutgoingDumper = getHttpOutgoingDumper(aMsg)) {
            _sendViaHTTP(aMsg, aDisposition, aOutgoingDumper, aResHelper);
        } catch (final AS2HttpResponseException ex) {
            if (LOGGER.isErrorEnabled())
                LOGGER.error("Http Response Error " + ex.getMessage());
            // Resend if the HTTP Response has an error code
            ex.terminate();
            if (!doResend(IProcessorSenderModule.DO_SEND_ASYNC_MDN, aMsg, ex, nRetries))
                throw ex;
        } catch (final IOException ex) {
            // Resend if a network error occurs during transmission
            final AS2Exception wioe = WrappedAS2Exception.wrap(ex).setSourceMsg(aMsg).terminate();
            if (!doResend(IProcessorSenderModule.DO_SEND_ASYNC_MDN, aMsg, wioe, nRetries))
                throw wioe;
        } catch (final Exception ex) {
            // Propagate error if it can't be handled by a resend
            throw WrappedAS2Exception.wrap(ex);
        }
    } finally {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Async MDN message sent");
    }
}
Also used : AS2ResourceHelper(com.helger.as2lib.util.AS2ResourceHelper) DispositionType(com.helger.as2lib.disposition.DispositionType) AS2Message(com.helger.as2lib.message.AS2Message) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) IHTTPOutgoingDumper(com.helger.as2lib.util.dump.IHTTPOutgoingDumper) IOException(java.io.IOException) MessagingException(javax.mail.MessagingException) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) AS2NoModuleException(com.helger.as2lib.processor.AS2NoModuleException) IOException(java.io.IOException) AS2ComponentNotFoundException(com.helger.as2lib.session.AS2ComponentNotFoundException)

Aggregations

AS2Exception (com.helger.as2lib.exception.AS2Exception)2 WrappedAS2Exception (com.helger.as2lib.exception.WrappedAS2Exception)2 AS2Message (com.helger.as2lib.message.AS2Message)2 AS2NoModuleException (com.helger.as2lib.processor.AS2NoModuleException)2 AS2ComponentNotFoundException (com.helger.as2lib.session.AS2ComponentNotFoundException)2 AS2ResourceHelper (com.helger.as2lib.util.AS2ResourceHelper)2 IHTTPOutgoingDumper (com.helger.as2lib.util.dump.IHTTPOutgoingDumper)2 IOException (java.io.IOException)2 MessagingException (javax.mail.MessagingException)2 MIC (com.helger.as2lib.crypto.MIC)1 AS2DispositionException (com.helger.as2lib.disposition.AS2DispositionException)1 DispositionType (com.helger.as2lib.disposition.DispositionType)1 AS2InvalidParameterException (com.helger.as2lib.params.AS2InvalidParameterException)1 IHTTPIncomingDumper (com.helger.as2lib.util.dump.IHTTPIncomingDumper)1 EContentTransferEncoding (com.helger.mail.cte.EContentTransferEncoding)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 SMIMEException (org.bouncycastle.mail.smime.SMIMEException)1