Search in sources :

Example 16 with StartupException

use of org.olat.core.logging.StartupException in project openolat by klemens.

the class WebappHelper method setUserDataRoot.

/**
 * [spring]
 * @param userDataRoot
 */
public void setUserDataRoot(String userDataRoot) {
    if (!StringHelper.containsNonWhitespace(userDataRoot)) {
        userDataRoot = System.getProperty("java.io.tmpdir") + "/olatdata";
        log.info("using java.io.tmpdir as userdata. this is the default if userdata.dir is not set");
    }
    File fUserData = new File(userDataRoot);
    if (!fUserData.exists()) {
        if (!fUserData.mkdirs())
            throw new StartupException("Unable to create userdata dir '" + userDataRoot + "'. Please fix!");
    }
    // fxdiff: reset tmp-dir from within application to circumvent startup-params.
    // do not write to system default (/var/tmp) as this leads to permission problems with multiple instances on one host!
    log.info("Setting userdata root to: " + userDataRoot);
    WebappHelper.userDataRoot = userDataRoot;
}
Also used : StartupException(org.olat.core.logging.StartupException) File(java.io.File)

Example 17 with StartupException

use of org.olat.core.logging.StartupException in project openolat by klemens.

the class LoginModule method init.

@Override
public void init() {
    // configure timed cache default params: refresh 1 minute, timeout according to configuration
    failedLoginCache = coordinatorManager.getCoordinator().getCacher().getCache(LoginModule.class.getSimpleName(), "blockafterfailedattempts");
    updateProperties();
    boolean defaultProviderFound = false;
    for (Iterator<AuthenticationProvider> iterator = authenticationProviders.iterator(); iterator.hasNext(); ) {
        AuthenticationProvider provider = iterator.next();
        if (provider.isDefault()) {
            defaultProviderFound = true;
            defaultProviderName = provider.getName();
            log.info("Using default authentication provider '" + defaultProviderName + "'.");
        }
    }
    if (!defaultProviderFound) {
        throw new StartupException("Defined DefaultAuthProvider::" + defaultProviderName + " not existent or not enabled. Please fix.");
    }
}
Also used : StartupException(org.olat.core.logging.StartupException) AuthenticationProvider(org.olat.login.auth.AuthenticationProvider)

Example 18 with StartupException

use of org.olat.core.logging.StartupException in project openolat by klemens.

the class InstitutionConfiguration method init.

/**
 * initializes the institution portlet config
 */
public void init() {
    institutions = new FastHashMap();
    File configurationFile = new File(WebappHelper.getContextRealPath(CONFIG_FILE));
    XStream xstream = getInstitutionConfigXStream();
    InstitutionConfiguration configuration = (InstitutionConfiguration) xstream.fromXML(configurationFile);
    for (InstitutionPortletEntry institution : configuration.getInstitution()) {
        String shortName = institution.shortname;
        if (shortName == null) {
            throw new StartupException("Institution portlet startup: No shortname given for one entry!");
        }
        institutions.put(shortName.toLowerCase(), institution);
    }
    // from now on optimize for non-synchronized read access
    institutions.setFast(true);
}
Also used : StartupException(org.olat.core.logging.StartupException) XStream(com.thoughtworks.xstream.XStream) FastHashMap(org.apache.commons.collections.FastHashMap) File(java.io.File)

Example 19 with StartupException

use of org.olat.core.logging.StartupException in project OpenOLAT by OpenOLAT.

the class AbstractHierarchicalIndexer method addIndexer.

public void addIndexer(Indexer indexer) {
    try {
        childIndexers.add(indexer);
        logDebug("Adding indexer from configuraton. TypeName=" + indexer.getSupportedTypeName());
    } catch (ClassCastException cce) {
        throw new StartupException("Configured indexer is not of type Indexer", cce);
    }
}
Also used : StartupException(org.olat.core.logging.StartupException)

Example 20 with StartupException

use of org.olat.core.logging.StartupException in project OpenOLAT by OpenOLAT.

the class DatabaseUpgradeManager method loadAndExecuteSqlStatements.

/**
 * load file with alter statements and add to batch
 * @param statements
 * @param alterDbStatements
 */
private void loadAndExecuteSqlStatements(Statement statement, String alterDbStatements, Dialect dialect) {
    try {
        Resource setupDatabaseFile = new ClassPathResource("/database/" + dialect + "/" + alterDbStatements);
        if (!setupDatabaseFile.exists()) {
            throw new StartupException("The database upgrade file was not found on the classpath: " + "/database/" + dialect + "/" + alterDbStatements);
        }
        InputStream in = setupDatabaseFile.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        StringBuilder sb = new StringBuilder();
        // Read File Line By Line
        while ((strLine = br.readLine()) != null) {
            if (strLine.length() > 1 && (!strLine.startsWith("--") && !strLine.startsWith("#"))) {
                sb.append(strLine.trim()).append(' ');
            }
        }
        StringTokenizer tokenizer = new StringTokenizer(sb.toString(), ";");
        String sql = null;
        while (tokenizer.hasMoreTokens()) {
            try {
                String token = tokenizer.nextToken();
                if (!StringHelper.containsNonWhitespace(token)) {
                    continue;
                }
                sql = token + ";".toLowerCase();
                if (sql.startsWith("update") || sql.startsWith("delete") || sql.startsWith("alter") || sql.startsWith("insert")) {
                    statement.executeUpdate(sql);
                } else {
                    statement.execute(sql);
                }
                logInfo("Successfully upgraded database with the following sql: " + sql);
            } catch (SQLException e) {
                if (isErrorFatal(dialect, sql, e)) {
                    throw new StartupException("Fatal error trying to update database.", e);
                }
            } catch (Exception e) {
                // handle non sql errors
                logError("Could not upgrade your database!", e);
                throw new StartupException("Could not add alter db statements to batch.", e);
            }
        }
        in.close();
    } catch (FileNotFoundException e1) {
        logError("could not find deleteDatabase.sql file!", e1);
        abort(e1);
    } catch (IOException e) {
        logError("could not read deleteDatabase.sql file!", e);
        abort(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) StartupException(org.olat.core.logging.StartupException) StringTokenizer(java.util.StringTokenizer) StartupException(org.olat.core.logging.StartupException) BufferedReader(java.io.BufferedReader)

Aggregations

StartupException (org.olat.core.logging.StartupException)26 File (java.io.File)10 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Resource (org.springframework.core.io.Resource)6 InputStream (java.io.InputStream)4 Statement (java.sql.Statement)4 XStream (com.thoughtworks.xstream.XStream)2 BufferedReader (java.io.BufferedReader)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2 ResultSet (java.sql.ResultSet)2 Properties (java.util.Properties)2 StringTokenizer (java.util.StringTokenizer)2 FastHashMap (org.apache.commons.collections.FastHashMap)2 CoreSpringFactory (org.olat.core.CoreSpringFactory)2 AssertException (org.olat.core.logging.AssertException)2 AuthenticationProvider (org.olat.login.auth.AuthenticationProvider)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2