Search in sources :

Example 1 with AS2ServerXMLSession

use of com.helger.as2.app.session.AS2ServerXMLSession in project as2-server by phax.

the class MainOpenAS2Server method start.

public void start(@Nullable final String sConfigFilePath) {
    AS2ServerXMLSession aXMLSession = null;
    try {
        s_aLogger.info(CAS2Info.NAME_VERSION + " - starting Server...");
        // create the OpenAS2 Session object
        // this is used by all other objects to access global configs and
        // functionality
        s_aLogger.info("Loading configuration...");
        if (StringHelper.hasText(sConfigFilePath)) {
            // Load config file
            aXMLSession = new AS2ServerXMLSession(sConfigFilePath);
        } else {
            s_aLogger.info("Usage:");
            s_aLogger.info("java " + getClass().getName() + " <configuration file>");
            throw new Exception("Missing configuration file name on the commandline. You may specify src/main/resources/config/config.xml");
        }
        // start the active processor modules
        s_aLogger.info("Starting Active Modules...");
        aXMLSession.getMessageProcessor().startActiveModules();
        final ICommandRegistry aCommandRegistry = aXMLSession.getCommandRegistry();
        final CommandManager aCommandMgr = aXMLSession.getCommandManager();
        final List<AbstractCommandProcessor> aCommandProcessors = aCommandMgr.getProcessors();
        for (final AbstractCommandProcessor cmd : aCommandProcessors) {
            s_aLogger.info("Loading Command Processor " + cmd.getClass().getName() + "");
            cmd.init();
            cmd.addCommands(aCommandRegistry);
            new Thread(cmd, ClassHelper.getClassLocalName(cmd)).start();
        }
        // enter the command processing loop
        s_aLogger.info("OpenAS2 Started");
        // Start waiting for termination
        breakOut: while (true) {
            for (final AbstractCommandProcessor cmd : aCommandProcessors) {
                if (cmd.isTerminated())
                    break breakOut;
            }
            // Wait outside loop in case no command processor is present
            Thread.sleep(100);
        }
        s_aLogger.info("- OpenAS2 Stopped -");
    } catch (final Throwable t) {
        t.printStackTrace();
    } finally {
        if (aXMLSession != null) {
            try {
                aXMLSession.getMessageProcessor().stopActiveModules();
            } catch (final OpenAS2Exception same) {
                same.terminate();
            }
        }
        s_aLogger.info("OpenAS2 has shut down");
    }
}
Also used : CommandManager(com.helger.as2.cmd.CommandManager) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) AS2ServerXMLSession(com.helger.as2.app.session.AS2ServerXMLSession) ICommandRegistry(com.helger.as2.cmd.ICommandRegistry) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) AbstractCommandProcessor(com.helger.as2.cmdprocessor.AbstractCommandProcessor)

Example 2 with AS2ServerXMLSession

use of com.helger.as2.app.session.AS2ServerXMLSession in project as2-server by phax.

the class XMLCommandRegistry method loadCommand.

protected void loadCommand(final IMicroElement eCommand, @Nullable final MultiCommand aParent) throws OpenAS2Exception {
    final IAS2Session aSession = getSession();
    final String sBaseDirectory = aSession instanceof AS2ServerXMLSession ? ((AS2ServerXMLSession) aSession).getBaseDirectory() : null;
    final ICommand aCommand = AS2XMLHelper.createComponent(eCommand, ICommand.class, aSession, sBaseDirectory);
    if (aParent != null)
        aParent.getCommands().add(aCommand);
    else
        addCommand(aCommand);
}
Also used : AS2ServerXMLSession(com.helger.as2.app.session.AS2ServerXMLSession) IAS2Session(com.helger.as2lib.session.IAS2Session)

Aggregations

AS2ServerXMLSession (com.helger.as2.app.session.AS2ServerXMLSession)2 CommandManager (com.helger.as2.cmd.CommandManager)1 ICommandRegistry (com.helger.as2.cmd.ICommandRegistry)1 AbstractCommandProcessor (com.helger.as2.cmdprocessor.AbstractCommandProcessor)1 OpenAS2Exception (com.helger.as2lib.exception.OpenAS2Exception)1 IAS2Session (com.helger.as2lib.session.IAS2Session)1