Search in sources :

Example 1 with RepositoryServiceFactoryException

use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.

the class TestSqlRepositoryFactory method updateConfigurationFromFile.

private void updateConfigurationFromFile(Configuration configuration, String filePath) throws RepositoryServiceFactoryException {
    Properties properties = new Properties();
    try {
        File file = new File(filePath);
        LOGGER.debug("Config file absolute path '{}'.", new Object[] { file.getAbsolutePath() });
        if (!file.exists() || !file.isFile() || !file.canRead()) {
            throw new RepositoryServiceFactoryException("Config file '" + filePath + "' doesn't exist or can't be read.");
        }
        Reader reader = new InputStreamReader(new FileInputStream(file), "utf-8");
        properties.load(reader);
    } catch (RepositoryServiceFactoryException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new RepositoryServiceFactoryException(ex.getMessage(), ex);
    }
    //override loaded configuration based on properties file...
    updateConfigurationFromProperties(configuration, properties);
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Properties(java.util.Properties) File(java.io.File) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) FileInputStream(java.io.FileInputStream) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Example 2 with RepositoryServiceFactoryException

use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.

the class SqlRepositoryFactory method checkPort.

private void checkPort(int port) throws RepositoryServiceFactoryException {
    if (port >= 65635 || port < 0) {
        throw new RepositoryServiceFactoryException("Port must be in range 0-65634, not '" + port + "'.");
    }
    ServerSocket ss = null;
    try {
        ss = new ServerSocket(port);
        ss.setReuseAddress(true);
    } catch (BindException e) {
        throw new RepositoryServiceFactoryException("Configured port (" + port + ") for H2 already in use.", e);
    } catch (IOException e) {
        LOGGER.error("Reported IO error, while binding ServerSocket to port " + port + " used to test availability " + "of port for H2 Server", e);
    } finally {
        try {
            if (ss != null) {
                ss.close();
            }
        } catch (IOException ex) {
            LOGGER.error("Reported IO error, while closing ServerSocket used to test availability " + "of port for H2 Server", ex);
        }
    }
}
Also used : BindException(java.net.BindException) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Example 3 with RepositoryServiceFactoryException

use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.

the class RepositoryFactory method getRepositoryService.

public synchronized RepositoryService getRepositoryService() {
    if (repositoryService == null) {
        try {
            LOGGER.debug("Creating repository service using factory {}", factory);
            repositoryService = factory.getRepositoryService();
        } catch (RepositoryServiceFactoryException | RuntimeException ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Failed to get repository service from factory " + factory, ex);
            throw new SystemException("Failed to get repository service from factory " + factory, ex);
        } catch (Error ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Failed to get repository service from factory " + factory, ex);
            throw ex;
        }
    }
    return repositoryService;
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Example 4 with RepositoryServiceFactoryException

use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.

the class TestSqlRepositoryConfigurationFactory method updateConfigurationFromFile.

private void updateConfigurationFromFile(Configuration configuration, String filePath) throws RepositoryServiceFactoryException {
    Properties properties = new Properties();
    try {
        File file = new File(filePath);
        LOGGER.debug("Config file absolute path '{}'.", file.getAbsolutePath());
        if (!file.exists() || !file.isFile() || !file.canRead()) {
            throw new RepositoryServiceFactoryException("Config file '" + filePath + "' doesn't exist or can't be read.");
        }
        Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
        properties.load(reader);
    } catch (RepositoryServiceFactoryException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new RepositoryServiceFactoryException(ex.getMessage(), ex);
    }
    // override loaded configuration based on properties file...
    updateConfigurationFromProperties(configuration, properties);
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Properties(java.util.Properties) File(java.io.File) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) FileInputStream(java.io.FileInputStream) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Example 5 with RepositoryServiceFactoryException

use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.

the class SqlEmbeddedRepository method checkPort.

private void checkPort(int port) throws RepositoryServiceFactoryException {
    if (port >= 65635 || port < 0) {
        throw new RepositoryServiceFactoryException("Port must be in range 0-65634, not '" + port + "'.");
    }
    ServerSocket ss = null;
    try {
        ss = new ServerSocket(port);
        ss.setReuseAddress(true);
    } catch (BindException e) {
        throw new RepositoryServiceFactoryException("Configured port (" + port + ") for H2 already in use.", e);
    } catch (IOException e) {
        LOGGER.error("Reported IO error, while binding ServerSocket to port " + port + " used to test availability " + "of port for H2 Server", e);
    } finally {
        try {
            if (ss != null) {
                ss.close();
            }
        } catch (IOException ex) {
            LOGGER.error("Reported IO error, while closing ServerSocket used to test availability " + "of port for H2 Server", ex);
        }
    }
}
Also used : BindException(java.net.BindException) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Aggregations

RepositoryServiceFactoryException (com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)16 IOException (java.io.IOException)7 BindException (java.net.BindException)6 File (java.io.File)5 AuditServiceFactoryException (com.evolveum.midpoint.audit.api.AuditServiceFactoryException)3 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 ServerSocket (java.net.ServerSocket)2 Properties (java.util.Properties)2 NamingException (javax.naming.NamingException)2 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)1 SqaleRepoContext (com.evolveum.midpoint.repo.sqale.SqaleRepoContext)1 SqlRepositoryConfiguration (com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration)1 SqlRepositoryFactory (com.evolveum.midpoint.repo.sql.SqlRepositoryFactory)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 PropertyVetoException (java.beans.PropertyVetoException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1