Search in sources :

Example 1 with ConfigurationException

use of org.restexpress.common.exception.ConfigurationException in project FrameworkBenchmarks by TechEmpower.

the class Main method main.

public static void main(String[] args) throws Throwable {
    Configuration config = Environment.load(args, Configuration.class);
    RestExpress server = new RestExpress().setName("RestExpress").setExecutorThreadCount(config.getExecutorThreadPoolSize()).setUseTcpNoDelay(true).setKeepAlive(true).noCompression().setEnforceHttpSpec(true).alias("HelloWorld", HelloWorld.class).addPostprocessor(new RequiredResponseHeaders());
    switch(config.getDatabase()) {
        case MongoDB:
            {
                server.uri("/plaintext", config.getPlaintextController()).action("sayHello", HttpMethod.GET).noSerialization();
                server.uri("/json", config.getJsonController()).action("sayHello", HttpMethod.GET);
                server.uri("/db", config.getMongodbController()).method(HttpMethod.GET);
                server.uri("/query", config.getQueriesMongodbController()).method(HttpMethod.GET);
            }
            break;
        case MySQL:
            {
                server.uri("/db", config.getMysqlController()).method(HttpMethod.GET);
                server.uri("/query", config.getQueriesMysqlController()).method(HttpMethod.GET);
            }
            break;
        default:
            throw new ConfigurationException("No Database configured in the environment.properties file.");
    }
    server.bind(config.getPort());
    server.awaitShutdown();
}
Also used : Configuration(hello.config.Configuration) ConfigurationException(org.restexpress.common.exception.ConfigurationException) RestExpress(org.restexpress.RestExpress) HelloWorld(hello.controller.JsonController.HelloWorld)

Example 2 with ConfigurationException

use of org.restexpress.common.exception.ConfigurationException in project FrameworkBenchmarks by TechEmpower.

the class MysqlConfig method configureMysqlConnections.

private MysqlConnectionPoolDataSource configureMysqlConnections(String uri, String dbUser, String dbPassword, String useConfigs) {
    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
    ds.setUrl(uri);
    if (dbUser != null) {
        ds.setUser(dbUser);
    }
    if (dbPassword != null) {
        ds.setPassword(dbPassword);
    }
    if (useConfigs != null) {
        try {
            ds.setUseConfigs(useConfigs);
        } catch (java.sql.SQLException e) {
            throw new ConfigurationException("Unable to set DataSource config", e);
        }
    }
    return ds;
}
Also used : ConfigurationException(org.restexpress.common.exception.ConfigurationException) MysqlConnectionPoolDataSource(com.mysql.cj.jdbc.MysqlConnectionPoolDataSource)

Aggregations

ConfigurationException (org.restexpress.common.exception.ConfigurationException)2 MysqlConnectionPoolDataSource (com.mysql.cj.jdbc.MysqlConnectionPoolDataSource)1 Configuration (hello.config.Configuration)1 HelloWorld (hello.controller.JsonController.HelloWorld)1 RestExpress (org.restexpress.RestExpress)1