Example usage for javax.naming ConfigurationException ConfigurationException

List of usage examples for javax.naming ConfigurationException ConfigurationException

Introduction

In this page you can find the example usage for javax.naming ConfigurationException ConfigurationException.

Prototype

public ConfigurationException(String explanation) 

Source Link

Document

Constructs a new instance of ConfigurationException using an explanation.

Usage

From source file:com.cloud.utils.ProcessUtil.java

public static void pidCheck(String pidDir, String run) throws ConfigurationException {

    String dir = pidDir == null ? "/var/run" : pidDir;

    try {/*from   w w w  .j av a2s. com*/
        final File propsFile = PropertiesUtil.findConfigFile("environment.properties");
        if (propsFile == null) {
            s_logger.debug("environment.properties could not be opened");
        } else {
            final Properties props = PropertiesUtil.loadFromFile(propsFile);
            dir = props.getProperty("paths.pid");
            if (dir == null) {
                dir = pidDir == null ? "/var/run" : pidDir;
            }
        }
    } catch (IOException e) {
        s_logger.debug("environment.properties could not be opened");
    }

    final File pidFile = new File(dir + File.separator + run);
    try {
        if (!pidFile.createNewFile()) {
            if (!pidFile.exists()) {
                throw new ConfigurationException("Unable to write to " + pidFile.getAbsolutePath()
                        + ".  Are you sure you're running as root?");
            }

            final String pidLine = FileUtils.readFileToString(pidFile).trim();
            if (pidLine.isEmpty()) {
                throw new ConfigurationException(
                        "Java process is being started twice.  If this is not true, remove "
                                + pidFile.getAbsolutePath());
            }
            try {
                final long pid = Long.parseLong(pidLine);
                final Script script = new Script("bash", 120000, s_logger);
                script.add("-c", "ps -p " + pid);
                final String result = script.execute();
                if (result == null) {
                    throw new ConfigurationException(
                            "Java process is being started twice.  If this is not true, remove "
                                    + pidFile.getAbsolutePath());
                }
                if (!pidFile.delete()) {
                    throw new ConfigurationException(
                            "Java process is being started twice.  If this is not true, remove "
                                    + pidFile.getAbsolutePath());
                }
                if (!pidFile.createNewFile()) {
                    throw new ConfigurationException(
                            "Java process is being started twice.  If this is not true, remove "
                                    + pidFile.getAbsolutePath());
                }
            } catch (final NumberFormatException e) {
                throw new ConfigurationException(
                        "Java process is being started twice.  If this is not true, remove "
                                + pidFile.getAbsolutePath());
            }
        }
        pidFile.deleteOnExit();

        final Script script = new Script("bash", 120000, s_logger);
        script.add("-c", "echo $PPID");
        final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
        script.execute(parser);

        final String pid = parser.getLine();

        FileUtils.writeStringToFile(pidFile, pid + "\n");
    } catch (final IOException e) {
        throw new CloudRuntimeException(
                "Unable to create the " + pidFile.getAbsolutePath() + ".  Are you running as root?", e);
    }
}

From source file:io.netlibs.bgp.config.nodes.impl.ClientConfigurationImpl.java

public ClientConfigurationImpl(final InetAddress addr, final int port) throws ConfigurationException {
    if (addr == null) {
        throw new ConfigurationException("null remote address not allowed");
    }/* ww w  .j  a  v a 2  s. co m*/
    if (addr.isAnyLocalAddress()) {
        throw new ConfigurationException("wildcard remote address not allowed");
    }
    if ((port < 0) || (port > 65535)) {
        throw new ConfigurationException("port " + port + " not allowed");
    }

    this.remoteAddress = new InetSocketAddress(addr, port);
}

From source file:com.wso2telco.proxy.util.DecryptAES.java

public static String decrypt(String encryptedText) throws NoSuchPaddingException, NoSuchAlgorithmException,
        InvalidKeyException, BadPaddingException, IllegalBlockSizeException, ConfigurationException {
    if (encryptionKey != null) {
        byte[] encryptionKeyByteValue = encryptionKey.getBytes();
        SecretKey secretKey = new SecretKeySpec(encryptionKeyByteValue, AuthProxyConstants.ASE_KEY);
        String decryptedText = null;
        if (encryptedText != null) {
            byte[] encryptedTextByte = Base64.decodeBase64(encryptedText);
            Cipher cipher = Cipher.getInstance("AES");

            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            byte[] decryptedByte = cipher.doFinal(encryptedTextByte);
            decryptedText = new String(decryptedByte);
        }/*from ww  w.j av a 2 s .co  m*/
        return decryptedText;
    } else {
        throw new ConfigurationException("MSISDN EncryptionKey could not be found in mobile-connect.xml");
    }
}

From source file:io.netlibs.bgp.config.nodes.impl.ClientConfigurationImpl.java

public ClientConfigurationImpl(final InetSocketAddress remoteAddress) throws ConfigurationException {
    if (remoteAddress.getAddress().isAnyLocalAddress()) {
        throw new ConfigurationException("wildcard remote address not allowed");
    }//from  ww  w  . ja  v  a 2s  .c  om

    this.remoteAddress = remoteAddress;
}

From source file:com.wso2telco.proxy.util.DBUtils.java

private static void initializeDatasource() throws NamingException {
    if (dataSource != null) {
        return;/* w w w. j  ava2s . c o  m*/
    }

    String dataSourceName = null;
    try {
        Context ctx = new InitialContext();
        dataSourceName = configurationService.getDataHolder().getMobileConnectConfig().getAuthProxy()
                .getDataSourceName();
        if (dataSourceName != null) {
            dataSource = (DataSource) ctx.lookup(dataSourceName);
        } else {
            throw new ConfigurationException("DataSource could not be found in mobile-connect.xml");
        }
    } catch (ConfigurationException e) {
        throw new ConfigurationException("DataSource could not be found in mobile-connect.xml");
    } catch (NamingException e) {
        throw new NamingException("Exception occurred while initiating data source : " + dataSourceName);
    }
}

From source file:com.wso2telco.gsma.authenticators.dao.impl.AttributeConfigDaoImpl.java

private static void initializeConnectDatasource() throws NamingException {
    if (mConnectDatasource != null) {
        return;//from   w  ww .j a  va 2s  .  co  m
    }

    String dataSourceName = null;
    try {
        Context ctx = new InitialContext();
        ConfigurationService configurationService = new ConfigurationServiceImpl();
        dataSourceName = configurationService.getDataHolder().getMobileConnectConfig().getDataSourceName();
        mConnectDatasource = (DataSource) ctx.lookup(dataSourceName);
    } catch (NamingException e) {
        throw new ConfigurationException("DataSource could not be found in mobile-connect.xml:" + e);
    }
}

From source file:com.cloud.baremetal.networkservice.BaremetalKickStartPxeResource.java

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    super.configure(name, params);
    _tftpDir = (String) params.get(BaremetalPxeService.PXE_PARAM_TFTP_DIR);
    if (_tftpDir == null) {
        throw new ConfigurationException("No tftp directory specified");
    }//from   w ww  .  java  2 s. c om

    com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22);

    s_logger.debug(
            String.format("Trying to connect to kickstart PXE server(IP=%1$s, username=%2$s, password=%3$s",
                    _ip, _username, "******"));
    try {
        sshConnection.connect(null, 60000, 60000);
        if (!sshConnection.authenticateWithPassword(_username, _password)) {
            s_logger.debug("SSH Failed to authenticate");
            throw new ConfigurationException(String.format(
                    "Cannot connect to kickstart PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip,
                    _username, "******"));
        }

        String cmd = String.format("[ -f /%1$s/pxelinux.0 ]", _tftpDir);
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) {
            throw new ConfigurationException(
                    "Miss files in TFTP directory at " + _tftpDir + " check if pxelinux.0 are here");
        }

        SCPClient scp = new SCPClient(sshConnection);
        String prepareScript = "scripts/network/ping/prepare_kickstart_bootfile.py";
        String prepareScriptPath = Script.findScript("", prepareScript);
        if (prepareScriptPath == null) {
            throw new ConfigurationException("Can not find prepare_kickstart_bootfile.py at " + prepareScript);
        }
        scp.put(prepareScriptPath, "/usr/bin/", "0755");

        String cpScript = "scripts/network/ping/prepare_kickstart_kernel_initrd.py";
        String cpScriptPath = Script.findScript("", cpScript);
        if (cpScriptPath == null) {
            throw new ConfigurationException("Can not find prepare_kickstart_kernel_initrd.py at " + cpScript);
        }
        scp.put(cpScriptPath, "/usr/bin/", "0755");

        String userDataScript = "scripts/network/ping/baremetal_user_data.py";
        String userDataScriptPath = Script.findScript("", userDataScript);
        if (userDataScriptPath == null) {
            throw new ConfigurationException("Can not find baremetal_user_data.py at " + userDataScript);
        }
        scp.put(userDataScriptPath, "/usr/bin/", "0755");

        return true;
    } catch (Exception e) {
        throw new CloudRuntimeException(e);
    } finally {
        if (sshConnection != null) {
            sshConnection.close();
        }
    }
}

From source file:com.launchkey.example.springmvc.AuthManager.java

@Autowired
public AuthManager(LaunchKeyConfig config) throws ConfigurationException, IOException {
    final Long rocketKey = config.getRocketKey();
    final String secretKey = config.getSecretKey();
    final String privateKeyLocation = config.getPrivateKeyLocation();

    boolean halt = false;
    if (rocketKey == null) {
        log.error("launchkey.rocket-key property not provided");
        halt = true;/*from w  w  w  .jav  a2s .  c  o m*/
    }
    if (secretKey == null) {
        log.error("launchkey.secret-key property not provided");
        halt = true;
    }
    if (privateKeyLocation == null) {
        log.error("launchkey.private-key-location property not provided");
        halt = true;
    }
    if (halt)
        throw new ConfigurationException("Missing required LaunchKey configuration");

    BufferedReader br = new BufferedReader(new FileReader(privateKeyLocation));
    StringBuilder sb = new StringBuilder();
    try {
        String line = br.readLine();

        while (line != null) {
            sb.append(line);
            sb.append("\n");
            line = br.readLine();
        }
    } finally {
        br.close();
    }
    String privateKey = sb.toString();
    LaunchKeyClient launchKeyClient = LaunchKeyClient.factory(rocketKey, secretKey, privateKey,
            new BouncyCastleProvider());
    this.authService = launchKeyClient.auth();
    this.sessionAuthenticationMap = Collections.synchronizedMap(new HashMap<String, Boolean>());
    this.sessionAuthRequestMap = new ConcurrentHashMap<String, String>();
    this.userHashSessionMap = new ConcurrentHashMap<String, List<String>>();
}

From source file:com.dattack.naming.loader.factory.DataSourceFactory.java

@Override
public DataSource getObjectInstance(final Properties properties, final Collection<File> extraClasspath)
        throws NamingException {

    final CompositeConfiguration configuration = new CompositeConfiguration();
    configuration.addConfiguration(new SystemConfiguration());
    configuration.addConfiguration(new EnvironmentConfiguration());
    configuration.addConfiguration(new MapConfiguration(properties));

    final String driver = configuration.getString(DRIVER_KEY);
    if (driver == null) {
        throw new ConfigurationException(String.format("Missing property '%s'", DRIVER_KEY));
    }/*from   w  w  w. j ava  2  s  .  c om*/

    final String url = configuration.getString(URL_KEY);
    if (url == null) {
        throw new ConfigurationException(String.format("Missing property '%s'", URL_KEY));
    }

    final String user = configuration.getString(USERNAME_KEY);
    final String password = configuration.getString(PASSWORD_KEY);

    DataSource dataSource = null;
    try {
        final Properties props = ConfigurationConverter.getProperties(configuration);
        dataSource = BasicDataSourceFactory.createDataSource(props);
    } catch (final Exception e) { // NOPMD by cvarela on 8/02/16 22:28
        // we will use a DataSource without a connection pool
        LOGGER.info(e.getMessage());
        dataSource = new SimpleDataSource(driver, url, user, password);
    }

    return new DataSourceClasspathDecorator(dataSource, extraClasspath);
}

From source file:org.agatom.springatom.cmp.wizards.core.StepHelperDelegate.java

private StepHelperDelegate(StepHelper... helpers) throws ConfigurationException {
    this.helperMap = Maps.newHashMapWithExpectedSize(helpers.length);
    for (StepHelper helper : helpers) {
        this.helperMap.put(helper.getStep(), helper);
        if (helper.isFinalStep()) {
            if (StringUtils.hasText(lastStep)) {
                throw new ConfigurationException(String.format(
                        "More than one stepHelper reports being final step helper, one already found is %s and the new one is %s",
                        this.lastStep, helper.getStep()));
            }//from   w w w . j a v  a 2  s.co m
            this.lastStep = helper.getStep();
        }
    }
}