Search in sources :

Example 6 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext in project iaf by ibissource.

the class StartIbis method main.

public static void main(String[] args) {
    IbisContext ibisContext = new IbisContext();
    ibisContext.init();
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext)

Example 7 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext in project iaf by ibissource.

the class ReloadSender method sendMessage.

@Override
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws TimeOutException, SenderException {
    String configName = null;
    String activeVersion = null;
    ParameterValueList pvl = null;
    try {
        if (prc != null && paramList != null) {
            pvl = prc.getValues(paramList);
            if (pvl.getParameterValue("name") != null)
                configName = (String) pvl.getParameterValue("name").getValue();
            if (pvl.getParameterValue("forceReload") != null)
                setForceReload((Boolean) pvl.getParameterValue("forceReload").getValue());
        }
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
    }
    try {
        if (configName == null)
            configName = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='NAME']");
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "error evaluating Xpath expression configName", e);
    }
    try {
        if (!getForceReload())
            activeVersion = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='VERSION']");
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "error evaluating Xpath expression activeVersion", e);
    }
    Configuration configuration = getPipe().getAdapter().getConfiguration().getIbisManager().getConfiguration(configName);
    if (configuration != null) {
        String latestVersion = configuration.getVersion();
        if (getForceReload() || (latestVersion != null && !activeVersion.equals(latestVersion))) {
            IbisContext ibisContext = configuration.getIbisManager().getIbisContext();
            ibisContext.reload(configName);
            return "Reload " + configName + " succeeded";
        } else {
            return "Reload " + configName + " skipped";
        }
    } else {
        log.warn("Configuration [" + configName + "] not loaded yet");
        return "Reload " + configName + " skipped";
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Configuration(nl.nn.adapterframework.configuration.Configuration) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 8 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext in project iaf by ibissource.

the class TestTool method runScenarios.

public static void runScenarios(ServletContext application, HttpServletRequest request, Writer out, boolean silent) {
    String logLevel = "wrong pipeline messages";
    String autoScroll = "true";
    String paramLogLevel = request.getParameter("loglevel");
    if (paramLogLevel != null && LOG_LEVEL_ORDER.indexOf("[" + paramLogLevel + "]") > -1) {
        logLevel = paramLogLevel;
    }
    String paramAutoScroll = request.getParameter("autoscroll");
    if (paramAutoScroll == null && paramLogLevel != null) {
        autoScroll = "false";
    }
    Map writers = null;
    if (!silent) {
        writers = new HashMap();
        writers.put("out", out);
        writers.put("htmlbuffer", new StringWriter());
        writers.put("logbuffer", new StringWriter());
        writers.put("loglevel", logLevel);
        writers.put("autoscroll", autoScroll);
        writers.put("usehtmlbuffer", "false");
        writers.put("uselogbuffer", "true");
        writers.put("messagecounter", new Integer(0));
        writers.put("scenariocounter", new Integer(1));
    } else {
        silentOut = out;
    }
    TestTool.debugMessage("Start logging to logbuffer until form is written", writers);
    debugMessage("Get ibis context", writers);
    AppConstants appConstants = AppConstants.getInstance();
    String ibisContextKey = appConstants.getResolvedProperty(ConfigurationServlet.KEY_CONTEXT);
    IbisContext ibisContext = (IbisContext) application.getAttribute(ibisContextKey);
    String asd = appConstants.getResolvedProperty("larva.diffs.autosave");
    if (asd != null) {
        autoSaveDiffs = Boolean.parseBoolean(asd);
    }
    debugMessage("Initialize scenarios root directories", writers);
    List scenariosRootDirectories = new ArrayList();
    List scenariosRootDescriptions = new ArrayList();
    String currentScenariosRootDirectory = initScenariosRootDirectories(appConstants, application, request, scenariosRootDirectories, scenariosRootDescriptions, writers);
    if (scenariosRootDirectories.size() == 0) {
        debugMessage("Stop logging to logbuffer", writers);
        writers.put("uselogbuffer", "stop");
        errorMessage("No scenarios root directories found", writers);
    } else {
        String appConstantsDirectory = appConstants.getResolvedProperty("larva.appconstants.directory");
        if (appConstantsDirectory != null) {
            appConstantsDirectory = getAbsolutePath(currentScenariosRootDirectory, appConstantsDirectory);
            if (new File(currentScenariosRootDirectory).exists()) {
                if (new File(appConstantsDirectory).exists()) {
                    debugMessage("Get AppConstants from directory: " + appConstantsDirectory, writers);
                    appConstants = AppConstants.getInstance(appConstantsDirectory);
                } else {
                    errorMessage("Directory for AppConstans not found", writers);
                }
            }
        }
        String windiffCmd = appConstants.getResolvedProperty("larva.windiff.command");
        if (windiffCmd != null) {
            windiffCommand = windiffCmd;
        } else {
            windiffCommand = currentScenariosRootDirectory + "..\\..\\IbisAlgemeenWasbak\\WinDiff\\WinDiff.Exe";
        }
        debugMessage("Read scenarios from directory '" + currentScenariosRootDirectory + "'", writers);
        List allScenarioFiles = readScenarioFiles(appConstants, currentScenariosRootDirectory, writers);
        debugMessage("Read execute parameter", writers);
        String paramExecute = request.getParameter("execute");
        debugMessage("Read waitbeforecleanup parameter", writers);
        String paramWaitBeforeCleanUp = request.getParameter("waitbeforecleanup");
        debugMessage("Initialize 'wait before cleanup' variable", writers);
        int waitBeforeCleanUp = 100;
        if (paramWaitBeforeCleanUp != null) {
            try {
                waitBeforeCleanUp = Integer.parseInt(paramWaitBeforeCleanUp);
            } catch (NumberFormatException e) {
            }
        }
        debugMessage("Write html form", writers);
        printHtmlForm(scenariosRootDirectories, scenariosRootDescriptions, currentScenariosRootDirectory, appConstants, allScenarioFiles, waitBeforeCleanUp, paramExecute, autoScroll, writers);
        debugMessage("Stop logging to logbuffer", writers);
        if (writers != null) {
            writers.put("uselogbuffer", "stop");
        }
        debugMessage("Start debugging to out", writers);
        debugMessage("Execute scenario(s) if execute parameter present and scenarios root directory did not change", writers);
        if (paramExecute != null) {
            String paramExecuteCanonicalPath;
            String scenariosRootDirectoryCanonicalPath;
            try {
                paramExecuteCanonicalPath = new File(paramExecute).getCanonicalPath();
                scenariosRootDirectoryCanonicalPath = new File(currentScenariosRootDirectory).getCanonicalPath();
            } catch (IOException e) {
                paramExecuteCanonicalPath = paramExecute;
                scenariosRootDirectoryCanonicalPath = currentScenariosRootDirectory;
                errorMessage("Could not get canonical path: " + e.getMessage(), e, writers);
            }
            if (paramExecuteCanonicalPath.startsWith(scenariosRootDirectoryCanonicalPath)) {
                debugMessage("Initialize XMLUnit", writers);
                XMLUnit.setIgnoreWhitespace(true);
                debugMessage("Initialize 'scenario files' variable", writers);
                debugMessage("Param execute: " + paramExecute, writers);
                List scenarioFiles;
                if (paramExecute.endsWith(".properties")) {
                    debugMessage("Read one scenario", writers);
                    scenarioFiles = new ArrayList();
                    scenarioFiles.add(new File(paramExecute));
                } else {
                    debugMessage("Read all scenarios from directory '" + paramExecute + "'", writers);
                    scenarioFiles = readScenarioFiles(appConstants, paramExecute, writers);
                }
                boolean evenStep = false;
                debugMessage("Initialize statistics variables", writers);
                int scenariosPassed = 0;
                int scenariosAutosaved = 0;
                int scenariosFailed = 0;
                long startTime = System.currentTimeMillis();
                debugMessage("Execute scenario('s)", writers);
                Iterator scenarioFilesIterator = scenarioFiles.iterator();
                while (scenarioFilesIterator.hasNext()) {
                    int scenarioPassed = RESULT_ERROR;
                    File scenarioFile = (File) scenarioFilesIterator.next();
                    String scenarioDirectory = scenarioFile.getParentFile().getAbsolutePath() + File.separator;
                    String longName = scenarioFile.getAbsolutePath();
                    String shortName = longName.substring(currentScenariosRootDirectory.length() - 1, longName.length() - ".properties".length());
                    if (writers != null) {
                        if (LOG_LEVEL_ORDER.indexOf("[" + (String) writers.get("loglevel") + "]") < LOG_LEVEL_ORDER.indexOf("[scenario passed/failed]")) {
                            writeHtml("<br/>", writers, false);
                            writeHtml("<br/>", writers, false);
                            writeHtml("<div class='scenario'>", writers, false);
                        }
                    }
                    debugMessage("Read property file " + scenarioFile.getName(), writers);
                    Properties properties = readProperties(appConstants, scenarioFile, writers);
                    List steps = null;
                    if (properties != null) {
                        debugMessage("Read steps from property file", writers);
                        steps = getSteps(properties, writers);
                        if (steps != null) {
                            synchronized (STEP_SYNCHRONIZER) {
                                debugMessage("Open queues", writers);
                                Map queues = openQueues(scenarioDirectory, steps, properties, ibisContext, writers);
                                if (queues != null) {
                                    debugMessage("Execute steps", writers);
                                    boolean allStepsPassed = true;
                                    boolean autoSaved = false;
                                    Iterator iterator = steps.iterator();
                                    while (allStepsPassed && iterator.hasNext()) {
                                        if (evenStep) {
                                            writeHtml("<div class='even'>", writers, false);
                                            evenStep = false;
                                        } else {
                                            writeHtml("<div class='odd'>", writers, false);
                                            evenStep = true;
                                        }
                                        String step = (String) iterator.next();
                                        String stepDisplayName = shortName + " - " + step + " - " + properties.get(step);
                                        debugMessage("Execute step '" + stepDisplayName + "'", writers);
                                        int stepPassed = executeStep(step, properties, stepDisplayName, queues, writers);
                                        if (stepPassed == RESULT_OK) {
                                            stepPassedMessage("Step '" + stepDisplayName + "' passed", writers);
                                        } else if (stepPassed == RESULT_AUTOSAVED) {
                                            stepAutosavedMessage("Step '" + stepDisplayName + "' passed after autosave", writers);
                                            autoSaved = true;
                                        } else {
                                            stepFailedMessage("Step '" + stepDisplayName + "' failed", writers);
                                            allStepsPassed = false;
                                        }
                                        writeHtml("</div>", writers, false);
                                    }
                                    if (allStepsPassed) {
                                        if (autoSaved) {
                                            scenarioPassed = RESULT_AUTOSAVED;
                                        } else {
                                            scenarioPassed = RESULT_OK;
                                        }
                                    }
                                    debugMessage("Wait " + waitBeforeCleanUp + " ms before clean up", writers);
                                    try {
                                        Thread.sleep(waitBeforeCleanUp);
                                    } catch (InterruptedException e) {
                                    }
                                    debugMessage("Close queues", writers);
                                    boolean remainingMessagesFound = closeQueues(queues, properties, writers);
                                    if (remainingMessagesFound) {
                                        stepFailedMessage("Found one or more messages on queues or in database after scenario executed", writers);
                                        scenarioPassed = RESULT_ERROR;
                                    }
                                }
                            }
                        }
                    }
                    if (scenarioPassed == RESULT_OK) {
                        scenarioPassedMessage("Scenario '" + shortName + " - " + properties.getProperty("scenario.description") + "' passed", writers);
                        if (silent) {
                            try {
                                out.write("[***PASSED***]");
                            } catch (IOException e) {
                            }
                        }
                        scenariosPassed++;
                    } else if (scenarioPassed == RESULT_AUTOSAVED) {
                        scenarioAutosavedMessage("Scenario '" + shortName + " - " + properties.getProperty("scenario.description") + "' passed after autosave", writers);
                        if (silent) {
                            try {
                                out.write("[***PASSED***]");
                            } catch (IOException e) {
                            }
                        }
                        scenariosAutosaved++;
                    } else {
                        scenarioFailedMessage("Scenario '" + shortName + " - " + properties.getProperty("scenario.description") + "' failed", writers);
                        scenariosFailed++;
                    }
                    writeHtml("</div>", writers, false);
                }
                long executeTime = System.currentTimeMillis() - startTime;
                debugMessage("Print statistics information", writers);
                int scenariosTotal = scenariosPassed + scenariosAutosaved + scenariosFailed;
                if (scenariosTotal == 0) {
                    scenariosTotalMessage("No scenarios found", writers);
                } else {
                    if (writers != null) {
                        if (LOG_LEVEL_ORDER.indexOf("[" + (String) writers.get("loglevel") + "]") <= LOG_LEVEL_ORDER.indexOf("[scenario passed/failed]")) {
                            writeHtml("<br/>", writers, false);
                            writeHtml("<br/>", writers, false);
                        }
                    }
                    debugMessage("Print statistics information", writers);
                    if (scenariosPassed == scenariosTotal) {
                        if (scenariosTotal == 1) {
                            scenariosPassedTotalMessage("All scenarios passed (1 scenario executed in " + executeTime + " ms)", writers);
                        } else {
                            scenariosPassedTotalMessage("All scenarios passed (" + scenariosTotal + " scenarios executed in " + executeTime + " ms)", writers);
                        }
                    } else if (scenariosFailed == scenariosTotal) {
                        if (scenariosTotal == 1) {
                            scenariosFailedTotalMessage("All scenarios failed (1 scenario executed in " + executeTime + " ms)", writers);
                        } else {
                            scenariosFailedTotalMessage("All scenarios failed (" + scenariosTotal + " scenarios executed in " + executeTime + " ms)", writers);
                        }
                    } else {
                        if (scenariosTotal == 1) {
                            scenariosTotalMessage("1 scenario executed in " + executeTime + " ms", writers);
                        } else {
                            scenariosTotalMessage(scenariosTotal + " scenarios executed in " + executeTime + " ms", writers);
                        }
                        if (scenariosPassed == 1) {
                            scenariosPassedTotalMessage("1 scenario passed", writers);
                        } else {
                            scenariosPassedTotalMessage(scenariosPassed + " scenarios passed", writers);
                        }
                        if (autoSaveDiffs) {
                            if (scenariosAutosaved == 1) {
                                scenariosAutosavedTotalMessage("1 scenario passed after autosave", writers);
                            } else {
                                scenariosAutosavedTotalMessage(scenariosAutosaved + " scenarios passed after autosave", writers);
                            }
                        }
                        if (scenariosFailed == 1) {
                            scenariosFailedTotalMessage("1 scenario failed", writers);
                        } else {
                            scenariosFailedTotalMessage(scenariosFailed + " scenarios failed", writers);
                        }
                    }
                }
                debugMessage("Start logging to htmlbuffer until form is written", writers);
                if (writers != null) {
                    writers.put("usehtmlbuffer", "start");
                }
                writeHtml("<br/>", writers, false);
                writeHtml("<br/>", writers, false);
                printHtmlForm(scenariosRootDirectories, scenariosRootDescriptions, currentScenariosRootDirectory, appConstants, allScenarioFiles, waitBeforeCleanUp, paramExecute, autoScroll, writers);
                debugMessage("Stop logging to htmlbuffer", writers);
                if (writers != null) {
                    writers.put("usehtmlbuffer", "stop");
                }
                writeHtml("", writers, true);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) IbisContext(nl.nn.adapterframework.configuration.IbisContext) StringWriter(java.io.StringWriter) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) File(java.io.File) AppConstants(nl.nn.adapterframework.util.AppConstants)

Example 9 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext in project iaf by ibissource.

the class DomainTransformerPipe method configure.

public void configure() throws ConfigurationException {
    super.configure();
    IbisContext ibisContext = getAdapter().getConfiguration().getIbisManager().getIbisContext();
    qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class);
    qs.setProxiedDataSources(proxiedDataSources);
    qs.setJmsRealm(jmsRealm);
    // dummy query required
    qs.setQuery("SELECT count(*) FROM ALL_TABLES");
    qs.configure();
    Connection conn = null;
    try {
        conn = qs.getConnection();
        if (!JdbcUtil.columnExists(conn, tableName, "*")) {
            throw new ConfigurationException("The table [" + tableName + "] doesn't exist");
        }
        if (!JdbcUtil.columnExists(conn, tableName, labelField)) {
            throw new ConfigurationException("The column [" + labelField + "] doesn't exist");
        }
        if (!JdbcUtil.columnExists(conn, tableName, valueInField)) {
            throw new ConfigurationException("The column [" + valueInField + "] doesn't exist");
        }
        if (!JdbcUtil.columnExists(conn, tableName, valueOutField)) {
            throw new ConfigurationException("The column [" + valueOutField + "] doesn't exist");
        }
        query = "SELECT " + valueOutField + " FROM " + tableName + " WHERE " + labelField + "=? AND " + valueInField + "=?";
    } catch (JdbcException e) {
        throw new ConfigurationException(e);
    } catch (SQLException e) {
        throw new ConfigurationException(e);
    } finally {
        JdbcUtil.close(conn);
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcException(nl.nn.adapterframework.jdbc.JdbcException)

Example 10 with IbisContext

use of nl.nn.adapterframework.configuration.IbisContext in project iaf by ibissource.

the class IbisTester method testStartAdapters.

public boolean testStartAdapters() {
    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.INFO);
    // remove AppConstants because it can be present from another JUnit test
    AppConstants.removeInstance();
    appConstants = AppConstants.getInstance();
    webAppPath = getWebContentDirectory();
    String projectBaseDir = Misc.getProjectBaseDir();
    appConstants.put("project.basedir", projectBaseDir);
    debug("***set property with name [project.basedir] and value [" + projectBaseDir + "]***");
    appConstants.put("create.dbscript.location", "create_database_h2.sql");
    // appConstants.put("validators.disabled", "true");
    // appConstants.put("xmlValidator.lazyInit", "true");
    // appConstants.put("xmlValidator.maxInitialised", "200");
    ibisContext = new IbisContext();
    long configLoadStartTime = System.currentTimeMillis();
    ibisContext.init();
    long configLoadEndTime = System.currentTimeMillis();
    debug("***configuration loaded in [" + (configLoadEndTime - configLoadStartTime) + "] msec***");
    int adaptersStarted = 0;
    int adaptersCount = 0;
    List<IAdapter> registeredAdapters = ibisContext.getIbisManager().getRegisteredAdapters();
    for (IAdapter adapter : registeredAdapters) {
        adaptersCount++;
        RunStateEnum runState = adapter.getRunState();
        if (!(RunStateEnum.STARTED).equals(runState)) {
            debug("adapter [" + adapter.getName() + "] has state [" + runState + "], will retry...");
            int count = 30;
            while (count-- > 0 && !(RunStateEnum.STARTED).equals(runState)) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runState = adapter.getRunState();
                if (!(RunStateEnum.STARTED).equals(runState)) {
                    debug("adapter [" + adapter.getName() + "] has state [" + runState + "], retries left [" + count + "]");
                } else {
                    debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
                }
            }
        } else {
            debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
        }
        if ((RunStateEnum.STARTED).equals(runState)) {
            adaptersStarted++;
        } else {
            error("adapter [" + adapter.getName() + "] has state [" + runState + "]");
        }
    }
    String msg = "adapters started [" + adaptersStarted + "] from [" + adaptersCount + "]";
    if (adaptersCount == adaptersStarted) {
        debug(msg);
        return true;
    } else {
        error(msg);
        return false;
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) IAdapter(nl.nn.adapterframework.core.IAdapter)

Aggregations

IbisContext (nl.nn.adapterframework.configuration.IbisContext)15 AppConstants (nl.nn.adapterframework.util.AppConstants)3 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 ServletContext (javax.servlet.ServletContext)2 Configuration (nl.nn.adapterframework.configuration.Configuration)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 IbisManager (nl.nn.adapterframework.configuration.IbisManager)2 IAdapter (nl.nn.adapterframework.core.IAdapter)2 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)2 RunStateEnum (nl.nn.adapterframework.util.RunStateEnum)2 File (java.io.File)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1