Search in sources :

Example 1 with AS2HttpRequestDataProviderInputStream

use of com.helger.as2lib.util.http.AS2HttpRequestDataProviderInputStream in project as2-lib by phax.

the class AS2MDNReceiverHandler method handle.

public void handle(@Nonnull final AbstractActiveNetModule aOwner, @Nonnull final Socket aSocket) {
    final String sClientInfo = getClientInfo(aSocket);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("incoming connection for receiving AsyncMDN [" + sClientInfo + "]");
    final AS2Message aMsg = new AS2Message();
    final boolean bQuoteHeaderValues = m_aReceiverModule.isQuoteHeaderValues();
    final IAS2HttpResponseHandler aResponseHandler = new AS2HttpResponseHandlerSocket(aSocket, bQuoteHeaderValues);
    // Time the transmission
    final StopWatch aSW = StopWatch.createdStarted();
    DataSource aMdnDataSource = null;
    try {
        // Read in the message request, headers, and data
        final IHTTPIncomingDumper aIncomingDumper = getEffectiveHttpIncomingDumper();
        aMdnDataSource = HTTPHelper.readAndDecodeHttpRequest(new AS2HttpRequestDataProviderInputStream(aSocket.getInputStream()), aResponseHandler, aMsg, aIncomingDumper);
    } catch (final Exception ex) {
        new AS2NetException(aSocket.getInetAddress(), aSocket.getPort(), ex).terminate();
    }
    aSW.stop();
    if (aMdnDataSource == null) {
        LOGGER.error("Not having a data source to operate on");
    } else {
        if (aMdnDataSource instanceof ByteArrayDataSource) {
            if (LOGGER.isInfoEnabled())
                LOGGER.info("received " + AS2IOHelper.getTransferRate(((ByteArrayDataSource) aMdnDataSource).directGetBytes().length, aSW) + " from " + sClientInfo + aMsg.getLoggingText());
        } else {
            LOGGER.info("received message from " + sClientInfo + aMsg.getLoggingText() + " in " + aSW.getMillis() + " ms");
        }
        handleIncomingMessage(sClientInfo, aMdnDataSource, aMsg, aResponseHandler);
    }
}
Also used : AS2HttpResponseHandlerSocket(com.helger.as2lib.util.http.AS2HttpResponseHandlerSocket) AS2Message(com.helger.as2lib.message.AS2Message) IAS2HttpResponseHandler(com.helger.as2lib.util.http.IAS2HttpResponseHandler) AS2HttpRequestDataProviderInputStream(com.helger.as2lib.util.http.AS2HttpRequestDataProviderInputStream) ByteArrayDataSource(com.helger.mail.datasource.ByteArrayDataSource) MessagingException(javax.mail.MessagingException) AS2NoModuleException(com.helger.as2lib.processor.AS2NoModuleException) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) IOException(java.io.IOException) AS2ComponentNotFoundException(com.helger.as2lib.session.AS2ComponentNotFoundException) StopWatch(com.helger.commons.timing.StopWatch) ByteArrayDataSource(com.helger.mail.datasource.ByteArrayDataSource) DataSource(javax.activation.DataSource) IHTTPIncomingDumper(com.helger.as2lib.util.dump.IHTTPIncomingDumper)

Example 2 with AS2HttpRequestDataProviderInputStream

use of com.helger.as2lib.util.http.AS2HttpRequestDataProviderInputStream in project as2-lib by phax.

the class AS2ReceiverHandler method handle.

public void handle(@Nonnull final AbstractActiveNetModule aOwner, @Nonnull final Socket aSocket) {
    final String sClientInfo = getClientInfo(aSocket);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Incoming connection " + sClientInfo);
    final AS2Message aMsg = createMessage(aSocket);
    final boolean bQuoteHeaderValues = m_aReceiverModule.isQuoteHeaderValues();
    final IAS2HttpResponseHandler aResponseHandler = new AS2HttpResponseHandlerSocket(aSocket, bQuoteHeaderValues);
    // Time the transmission
    final StopWatch aSW = StopWatch.createdStarted();
    DataSource aMsgDataSource = null;
    try {
        // Read in the message request, headers, and data
        final IHTTPIncomingDumper aIncomingDumper = getEffectiveHttpIncomingDumper();
        aMsgDataSource = HTTPHelper.readAndDecodeHttpRequest(new AS2HttpRequestDataProviderInputStream(aSocket.getInputStream()), aResponseHandler, aMsg, aIncomingDumper);
    } catch (final Exception ex) {
        new AS2NetException(aSocket.getInetAddress(), aSocket.getPort(), ex).terminate();
    }
    aSW.stop();
    if (aMsgDataSource == null) {
        LOGGER.error("Not having a data source to operate on");
    } else {
        if (aMsgDataSource instanceof ByteArrayDataSource) {
            if (LOGGER.isInfoEnabled())
                LOGGER.info("received " + AS2IOHelper.getTransferRate(((ByteArrayDataSource) aMsgDataSource).directGetBytes().length, aSW) + " from " + sClientInfo + aMsg.getLoggingText());
        } else {
            LOGGER.info("received message from " + sClientInfo + aMsg.getLoggingText() + " in " + aSW.getMillis() + " ms");
        }
        handleIncomingMessage(sClientInfo, aMsgDataSource, aMsg, aResponseHandler);
    }
}
Also used : AS2HttpResponseHandlerSocket(com.helger.as2lib.util.http.AS2HttpResponseHandlerSocket) AS2Message(com.helger.as2lib.message.AS2Message) IAS2HttpResponseHandler(com.helger.as2lib.util.http.IAS2HttpResponseHandler) AS2HttpRequestDataProviderInputStream(com.helger.as2lib.util.http.AS2HttpRequestDataProviderInputStream) ByteArrayDataSource(com.helger.mail.datasource.ByteArrayDataSource) MessagingException(javax.mail.MessagingException) AS2NoModuleException(com.helger.as2lib.processor.AS2NoModuleException) AS2DispositionException(com.helger.as2lib.disposition.AS2DispositionException) AS2ProcessorException(com.helger.as2lib.processor.AS2ProcessorException) CMSException(org.bouncycastle.cms.CMSException) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) IOException(java.io.IOException) SMIMEException(org.bouncycastle.mail.smime.SMIMEException) AS2ComponentNotFoundException(com.helger.as2lib.session.AS2ComponentNotFoundException) StopWatch(com.helger.commons.timing.StopWatch) ByteArrayDataSource(com.helger.mail.datasource.ByteArrayDataSource) DataSource(javax.activation.DataSource) IHTTPIncomingDumper(com.helger.as2lib.util.dump.IHTTPIncomingDumper)

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 IHTTPIncomingDumper (com.helger.as2lib.util.dump.IHTTPIncomingDumper)2 AS2HttpRequestDataProviderInputStream (com.helger.as2lib.util.http.AS2HttpRequestDataProviderInputStream)2 AS2HttpResponseHandlerSocket (com.helger.as2lib.util.http.AS2HttpResponseHandlerSocket)2 IAS2HttpResponseHandler (com.helger.as2lib.util.http.IAS2HttpResponseHandler)2 StopWatch (com.helger.commons.timing.StopWatch)2 ByteArrayDataSource (com.helger.mail.datasource.ByteArrayDataSource)2 IOException (java.io.IOException)2 DataSource (javax.activation.DataSource)2 MessagingException (javax.mail.MessagingException)2 AS2DispositionException (com.helger.as2lib.disposition.AS2DispositionException)1 AS2ProcessorException (com.helger.as2lib.processor.AS2ProcessorException)1 CMSException (org.bouncycastle.cms.CMSException)1 SMIMEException (org.bouncycastle.mail.smime.SMIMEException)1