Example usage for java.lang ExceptionInInitializerError ExceptionInInitializerError

List of usage examples for java.lang ExceptionInInitializerError ExceptionInInitializerError

Introduction

In this page you can find the example usage for java.lang ExceptionInInitializerError ExceptionInInitializerError.

Prototype

public ExceptionInInitializerError(String s) 

Source Link

Document

Constructs an ExceptionInInitializerError with the specified detail message string.

Usage

From source file:at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils.java

public static void initHibernate(Configuration config, Properties hibernateProperties) {

    String scm = StringUtils.trimToNull(hibernateProperties.getProperty(SESSION_HANDLING_KEY));
    if (scm != null) {
        automaticSessionHandling = scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[0]) != -1
                || scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[1]) != -1;
    }/*from  ww w .  ja v a 2  s . com*/
    Logger.debug("Evaluating hibernate property \"" + SESSION_HANDLING_KEY + "\".");
    if (automaticSessionHandling) {
        Logger.info("Hibernate is automatically handling session context management.");
    } else {
        Logger.info(
                "Hibernate is NOT automatically handling session context management. Using build-in ThreadLocal session handling.");
    }
    try {
        //Create the SessionFactory
        Logger.debug("Creating initial MOASession session factory...");

        config.configure("hibernate_moasession.cfg.xml");
        //serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

        serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

        sessionFactory = config.buildSessionFactory(serviceRegistry);
        Logger.debug("Initial MOASession session factory successfully created.");

    } catch (Throwable ex) {
        Logger.error("Initial MOASession session factory creation failed: " + ex.getMessage());
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils.java

public static void initHibernate(Configuration config, Properties hibernateProperties) {

    String scm = StringUtils.trimToNull(hibernateProperties.getProperty(SESSION_HANDLING_KEY));
    if (scm != null) {
        automaticSessionHandling = scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[0]) != -1
                || scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[1]) != -1;
    }//  w w w.j av a  2 s .c om
    Logger.debug("Evaluating hibernate property \"" + SESSION_HANDLING_KEY + "\".");
    if (automaticSessionHandling) {
        Logger.info("Hibernate is automatically handling session context management.");
    } else {
        Logger.info(
                "Hibernate is NOT automatically handling session context management. Using build-in ThreadLocal session handling.");
    }
    try {
        //Create the SessionFactory
        Logger.debug("Creating initial StatisicLogger session factory...");

        config.configure("hibernate_statistic.cfg.xml");
        //serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

        serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

        sessionFactory = config.buildSessionFactory(serviceRegistry);
        Logger.debug("Initial StatisicLogger session factory successfully created.");

    } catch (Throwable ex) {
        Logger.error("Initial StatisicLogger session factory creation failed: " + ex.getMessage());
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:org.mycore.common.xml.MCREntityResolver.java

private MCREntityResolver() {
    Enumeration<URL> systemResources;
    try {//  w ww.j a v  a  2 s.  co  m
        systemResources = this.getClass().getClassLoader().getResources("catalog.xml");
    } catch (IOException e) {
        throw new ExceptionInInitializerError(e);
    }
    Vector<String> catalogURIs = new Vector<>();
    while (systemResources.hasMoreElements()) {
        URL catalogURL = systemResources.nextElement();
        LOGGER.info("Using XML catalog: " + catalogURL);
        catalogURIs.add(catalogURL.toString());
    }
    String[] catalogs = catalogURIs.toArray(new String[catalogURIs.size()]);
    catalogResolver = new XMLCatalogResolver(catalogs);
    int cacheSize = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "StaticFiles.CacheSize", 100);
    bytesCache = new MCRCache<String, InputSourceProvider>(cacheSize, "EntityResolver Resources");
}

From source file:org.string_db.psicquic.index.StringDbScoresDataReader.java

StringDbScoresDataReader(DbFacade dbFacade, JdbcTemplate jdbcTemplate, Integer speciesId) {
    log.info("init()");
    try {/* w w w . j a v  a  2s.  com*/
        this.scoreTypes = dbFacade.loadScoreTypes();
        jdbcTemplate.setFetchSize(FETCH_SIZE);
        preparedStatement = jdbcTemplate.getDataSource().getConnection()
                .prepareStatement(scoresQuery + speciesId);

        //            this.rs = jdbcTemplate.queryForRowSet(scoresQuery + speciesId);
        this.rs = preparedStatement.executeQuery();
        nextCalled = false;
    } catch (Exception e) {
        throw new ExceptionInInitializerError(e);
    }
    log.info("done()");
}

From source file:com.yanzhenjie.nohttp.NoHttp.java

/**
 * Test initialized.//w  w  w  . j  av  a 2s. c o  m
 */
private static void testInitialize() {
    if (sContext == null)
        throw new ExceptionInInitializerError(
                "Please invoke NoHttp.initialize(Application) on " + "Application#onCreate()");
}

From source file:cc.redpen.server.api.RedPenService.java

/**
 * Create redpens for the given context//from ww  w  .  ja  v a2  s .  co m
 *
 * @param context the servlet context
 */
public RedPenService(ServletContext context) {
    synchronized (redPens) {
        if (redPens.isEmpty()) {
            LOG.info("Creating RedPen instances");
            try {
                List<Document> emptyDocuments = new ArrayList<>();
                emptyDocuments.add(Document.builder().build());
                for (String key : Configuration.getDefaultConfigKeys()) {
                    RedPen redpen = new RedPen(
                            Configuration.builder(key).secure().addAvailableValidatorConfigs().build());
                    redpen.validate(emptyDocuments);
                    redPens.put(key, redpen);
                }

                String configPath = context != null ? context.getInitParameter("redpen.conf.path") : null;
                if (configPath != null) {
                    LOG.info("Config Path is set to \"{}\"", configPath);
                    Configuration configuration;
                    try {
                        configuration = new ConfigurationLoader().secure().loadFromResource(configPath);
                    } catch (RedPenException rpe) {
                        configuration = new ConfigurationLoader().secure().load(new File(configPath));
                    }
                    RedPen defaultRedPen = new RedPen(configuration);
                    redPens.put(DEFAULT_LANGUAGE, defaultRedPen);
                } else {
                    // if config path is not set, fallback to default config path
                    LOG.info("No Config Path set, using default configurations");
                    redPens.put(DEFAULT_LANGUAGE, redPens.get("en"));
                }
                LOG.info("Document Validator Server is running.");
            } catch (RedPenException e) {
                LOG.error("Unable to initialize RedPen", e);
                throw new ExceptionInInitializerError(e);
            }
        }
    }
}

From source file:org.apache.geode.internal.cache.BackupJUnitTest.java

@Before
public void setUp() throws Exception {
    if (tmpDir == null) {
        props.setProperty(MCAST_PORT, "0");
        props.setProperty(LOCATORS, "");
        String tmpDirName = System.getProperty("java.io.tmpdir");
        tmpDir = new File(tmpDirName == null ? "" : tmpDirName);
        try {/*from   w  w  w . j av  a 2 s  .  co m*/
            URL url = BackupJUnitTest.class.getResource("BackupJUnitTest.cache.xml");
            cacheXmlFile = new File(url.toURI().getPath());
        } catch (URISyntaxException e) {
            throw new ExceptionInInitializerError(e);
        }
        props.setProperty(CACHE_XML_FILE, cacheXmlFile.getAbsolutePath());
        props.setProperty(LOG_LEVEL, "config"); // to keep diskPerf logs smaller
    }

    createCache();

    backupDir = new File(tmpDir, getName() + "backup_Dir");
    backupDir.mkdir();
    diskDirs = new File[2];
    diskDirs[0] = new File(tmpDir, getName() + "_diskDir1");
    diskDirs[0].mkdir();
    diskDirs[1] = new File(tmpDir, getName() + "_diskDir2");
    diskDirs[1].mkdir();
}

From source file:com.yolanda.nohttp.NoHttp.java

/**
 * Get application of app./*  ww  w.j  a va 2 s .c  o m*/
 *
 * @return {@link Application}.
 */
public static Application getContext() {
    if (sApplication == null)
        throw new ExceptionInInitializerError(
                "Please invoke NoHttp.initialize(Application) on Application#onCreate()");
    return sApplication;
}

From source file:ezbake.data.postgres.hibernate.HibernateUtil.java

private static SessionFactory buildSessionFactory(Properties ezConfig, EzSecurityToken token,
        SessionType sessionType) {/*from w  ww . ja va2s  . c  o  m*/
    try {
        String appName = ezConfig.getProperty(EzBakePropertyConstants.EZBAKE_APPLICATION_NAME);
        switch (sessionType) {
        case EZBAKE: {

            // Create the SessionFactory from hibernate.cfg.xml
            Configuration configuration = new Configuration();
            for (Map.Entry<Object, Object> entry : ezConfig.entrySet()) {
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();

                configuration.setProperty("hibernate.connection." + key, value);
            }

            return configuration
                    .setProperty("hibernate.connection.driver_class", "ezbake.data.postgres.EzPostgresDriver")
                    .setProperty("hibernate.connection.username",
                            ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_USERNAME))
                    .setProperty("hibernate.connection.password",
                            ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_PASSWORD))
                    .setProperty("hibernate.connection.url",
                            String.format("jdbc:ezbake:postgresql://%s:%s/%s",
                                    ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_HOST),
                                    ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_PORT), appName))
                    .setProperty("hibernate.default_schema", "public")
                    .setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect")
                    .setProperty("EzSecurityToken",
                            new String(Base64.encodeBase64(new TSerializer().serialize(token)),
                                    Charsets.US_ASCII))
                    .setProperty("hibernate.hbm2ddl.auto", "update").configure().buildSessionFactory();
        }
        case POSTGRES: {
            return new Configuration().setProperty("hibernate.connection.driver_class", "org.postgresql.Driver")
                    .setProperty("hibernate.connection.username",
                            ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_USERNAME))
                    .setProperty("hibernate.connection.password",
                            ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_PASSWORD))
                    .setProperty("hibernate.connection.url",
                            String.format("jdbc:postgresql://%s:%s/%s",
                                    ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_HOST),
                                    ezConfig.getProperty(EzBakePropertyConstants.POSTGRES_PORT), appName))
                    .setProperty("hibernate.default_schema", "public")
                    .setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect")
                    .setProperty("hibernate.show_sql", "true").setProperty("hibernate.hbm2ddl.auto", "update")
                    .configure().buildSessionFactory();
        }
        default: {
            throw new Exception("Invalid session type [" + sessionType + "].");
        }
        }
    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:mil.dod.th.ose.junit4xmltestrunner.ant.XMLJUnitResultFormatter.java

private static DocumentBuilder getDocumentBuilder() {
    try {/*from ww w .j a v a2s .  com*/
        return DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (final Exception exc) {
        throw new ExceptionInInitializerError(exc);
    }
}