Search in sources :

Example 1 with AS2ServletMDNReceiverModule

use of com.helger.as2servlet.util.AS2ServletMDNReceiverModule in project as2-lib by phax.

the class AS2ReceiveXServletHandlerCodeConfig method createAS2Session.

@Override
@Nonnull
protected AS2Session createAS2Session(@Nonnull final ICommonsMap<String, String> aInitParams) throws AS2Exception, ServletException {
    final AS2Session aSession = new AS2Session();
    {
        // Create CertificateFactory
        final CertificateFactory aCertFactory = new CertificateFactory();
        aCertFactory.setKeyStoreType(EKeyStoreType.PKCS12);
        aCertFactory.setFilename("clientCertificate.jks");
        aCertFactory.setPassword("test1234");
        aCertFactory.setSaveChangesToFile(false);
        aCertFactory.initDynamicComponent(aSession, null);
        aSession.setCertificateFactory(aCertFactory);
    }
    {
        // Create PartnershipFactory
        final SelfFillingPartnershipFactory aPartnershipFactory = new SelfFillingPartnershipFactory();
        aPartnershipFactory.initDynamicComponent(aSession, null);
        aSession.setPartnershipFactory(aPartnershipFactory);
    }
    {
        // Create MessageProcessor
        final DefaultMessageProcessor aMessageProcessor = new DefaultMessageProcessor();
        aMessageProcessor.setPendingMDNFolder("data/pendingMDN");
        aMessageProcessor.setPendingMDNInfoFolder("data/pendinginfoMDN");
        aMessageProcessor.initDynamicComponent(aSession, null);
        aSession.setMessageProcessor(aMessageProcessor);
        /**
         * Required to receive messages port is required internally - simply
         * ignore it for servlets
         */
        {
            final AS2ServletReceiverModule aModule = new AS2ServletReceiverModule();
            aModule.setErrorDirectory("data/inbox/error");
            aModule.setErrorFormat("$msg.sender.as2_id$, $msg.receiver.as2_id$, $msg.headers.message-id$");
            aModule.initDynamicComponent(aSession, null);
            aMessageProcessor.addModule(aModule);
        }
        /**
         * Only needed to receive asynchronous MDNs
         */
        {
            final AS2ServletMDNReceiverModule aModule = new AS2ServletMDNReceiverModule();
            aModule.initDynamicComponent(aSession, null);
            aMessageProcessor.addModule(aModule);
        }
        /**
         * Below module is used to send async mdn
         */
        {
            final AsynchMDNSenderModule aModule = new AsynchMDNSenderModule();
            aModule.initDynamicComponent(aSession, null);
            aMessageProcessor.addModule(aModule);
        }
        /**
         * A module storing the message.
         */
        {
            final MyHandlerModule aModule = new MyHandlerModule();
            aModule.initDynamicComponent(aSession, null);
            aMessageProcessor.addModule(aModule);
        }
    // Add further modules if you need them
    }
    return aSession;
}
Also used : AS2ServletMDNReceiverModule(com.helger.as2servlet.util.AS2ServletMDNReceiverModule) AS2ServletReceiverModule(com.helger.as2servlet.util.AS2ServletReceiverModule) CertificateFactory(com.helger.as2lib.cert.CertificateFactory) SelfFillingPartnershipFactory(com.helger.as2lib.partner.SelfFillingPartnershipFactory) DefaultMessageProcessor(com.helger.as2lib.processor.DefaultMessageProcessor) AS2Session(com.helger.as2lib.session.AS2Session) AsynchMDNSenderModule(com.helger.as2lib.processor.sender.AsynchMDNSenderModule) Nonnull(javax.annotation.Nonnull)

Example 2 with AS2ServletMDNReceiverModule

use of com.helger.as2servlet.util.AS2ServletMDNReceiverModule in project as2-lib by phax.

the class AbstractAS2MDNReceiveXServletHandler method onServletInit.

@Override
public void onServletInit(@Nonnull final ICommonsMap<String, String> aInitParams) throws ServletException {
    super.onServletInit(aInitParams);
    try {
        m_aReceiver = getSession().getMessageProcessor().getModuleOfClass(AS2ServletMDNReceiverModule.class);
        if (m_aReceiver == null)
            throw new ServletException("Failed to retrieve 'AS2ServletMDNReceiverModule' which is a mandatory module! Please ensure your configuration file contains at least the module '" + AS2ServletMDNReceiverModule.class.getName() + "'");
    } catch (final AS2Exception ex) {
        throw new ServletException("Failed to init AS2 configuration", ex);
    }
    LOGGER.info("Successfully initialized AS2 configuration");
}
Also used : ServletException(javax.servlet.ServletException) AS2Exception(com.helger.as2lib.exception.AS2Exception) AS2ServletMDNReceiverModule(com.helger.as2servlet.util.AS2ServletMDNReceiverModule)

Aggregations

AS2ServletMDNReceiverModule (com.helger.as2servlet.util.AS2ServletMDNReceiverModule)2 CertificateFactory (com.helger.as2lib.cert.CertificateFactory)1 AS2Exception (com.helger.as2lib.exception.AS2Exception)1 SelfFillingPartnershipFactory (com.helger.as2lib.partner.SelfFillingPartnershipFactory)1 DefaultMessageProcessor (com.helger.as2lib.processor.DefaultMessageProcessor)1 AsynchMDNSenderModule (com.helger.as2lib.processor.sender.AsynchMDNSenderModule)1 AS2Session (com.helger.as2lib.session.AS2Session)1 AS2ServletReceiverModule (com.helger.as2servlet.util.AS2ServletReceiverModule)1 Nonnull (javax.annotation.Nonnull)1 ServletException (javax.servlet.ServletException)1