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.baremetal.networkservice.BaremetalPingPxeResource.java

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    super.configure(name, params);
    _storageServer = (String) params.get(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_IP);
    _pingDir = (String) params.get(BaremetalPxeService.PXE_PARAM_PING_ROOT_DIR);
    _tftpDir = (String) params.get(BaremetalPxeService.PXE_PARAM_TFTP_DIR);
    _cifsUserName = (String) params.get(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_USERNAME);
    _cifsPassword = (String) params.get(BaremetalPxeService.PXE_PARAM_PING_STORAGE_SERVER_PASSWORD);

    if (_podId == null) {
        throw new ConfigurationException("No Pod specified");
    }//from ww w  .  j ava2 s.  com

    if (_storageServer == null) {
        throw new ConfigurationException("No stroage server specified");
    }

    if (_tftpDir == null) {
        throw new ConfigurationException("No tftp directory specified");
    }

    if (_pingDir == null) {
        throw new ConfigurationException("No PING directory specified");
    }

    if (_cifsUserName == null || _cifsUserName.equalsIgnoreCase("")) {
        _cifsUserName = "xxx";
    }

    if (_cifsPassword == null || _cifsPassword.equalsIgnoreCase("")) {
        _cifsPassword = "xxx";
    }

    String pingDirs[] = _pingDir.split("/");
    if (pingDirs.length != 2) {
        throw new ConfigurationException(
                "PING dir should have format like myshare/direcotry, eg: windows/64bit");
    }
    _share = pingDirs[0];
    _dir = pingDirs[1];

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

    s_logger.debug(String.format("Trying to connect to PING 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 PING PXE server(IP=%1$s, username=%2$s, password=%3$s",
                            _ip, _username, "******"));
        }

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

        SCPClient scp = new SCPClient(sshConnection);
        String prepareScript = "scripts/network/ping/prepare_tftp_bootfile.py";
        String prepareScriptPath = Script.findScript("", prepareScript);
        if (prepareScriptPath == null) {
            throw new ConfigurationException("Can not find prepare_tftp_bootfile.py at " + prepareScriptPath);
        }
        scp.put(prepareScriptPath, "/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 " + userDataScriptPath);
        }
        scp.put(userDataScriptPath, "/usr/bin/", "0755");

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

From source file:com.dattack.naming.standalone.StandaloneContextFactory.java

private static String getResourcesDirectory(final CompositeConfiguration configuration)
        throws ConfigurationException {

    final Object configDir = PropertyConverter
            .interpolate(configuration.getProperty(RESOURCES_DIRECTORY_PROPERTY), configuration);

    if (configDir == null) {
        throw new ConfigurationException(
                String.format("JNDI configuration error: missing property '%s'", RESOURCES_DIRECTORY_PROPERTY));
    }//  w  w w . j a v  a2 s.  c  om

    return configDir.toString();
}

From source file:com.dattack.naming.standalone.StandaloneContextFactory.java

private static Context loadInitialContext(final Hashtable<?, ?> environment) // NOPMD by cvarela
        throws NamingException {

    LOGGER.debug("loadInitialContext: {}", environment);
    final CompositeConfiguration configuration = getConfiguration(environment);

    final Object configDir = getResourcesDirectory(configuration);

    final File dir = FilesystemUtils.locateFile(ObjectUtils.toString(configDir));

    if ((dir != null) && dir.exists()) {
        return createInitialContext(dir, environment, configuration);
    }//from w  w  w  . jav a2s  .c om

    throw new ConfigurationException(
            String.format("JNDI configuration error: directory not exists '%s'", configDir));
}

From source file:com.wso2telco.dbUtil.DataBaseConnectUtils.java

/**
 * Add user details in Back Channeling Scenario
 *
 * @param backChannelUserDetails BackChannelRequestDetails
 *//*from w w  w . j a  va2 s  .c om*/
public static void addBackChannelRequestDetails(BackChannelRequestDetails backChannelUserDetails)
        throws ConfigurationException, CommonAuthenticatorException {
    Connection connection = null;
    PreparedStatement preparedStatement = null;

    String addUserDetailsQuery = "insert into backchannel_request_details(correlation_id,msisdn,notification_bearer_token,"
            + "notification_url,request_initiated_time,client_id,redirect_url) values(?," + "?,?,?,NOW(),?,?);";

    try {
        connection = getConnectDBConnection();

        if (log.isDebugEnabled()) {
            log.debug("Executing the query " + addUserDetailsQuery);
        }

        preparedStatement = connection.prepareStatement(addUserDetailsQuery);
        preparedStatement.setString(1, backChannelUserDetails.getCorrelationId());
        preparedStatement.setString(2, backChannelUserDetails.getMsisdn());
        preparedStatement.setString(3, backChannelUserDetails.getNotificationBearerToken());
        preparedStatement.setString(4, backChannelUserDetails.getNotificationUrl());
        preparedStatement.setString(5, backChannelUserDetails.getClientId());
        preparedStatement.setString(6, backChannelUserDetails.getRedirectUrl());

        preparedStatement.execute();

    } catch (SQLException e) {
        handleException("Error occurred while inserting user details for : "
                + backChannelUserDetails.getMsisdn() + "in " + "BackChannel Scenario.", e);
    } catch (NamingException e) {
        throw new ConfigurationException("DataSource could not be found in mobile-connect.xml");
    } finally {
        closeAllConnections(preparedStatement, connection);
    }
}

From source file:com.cloud.network.resource.NuageVspResource.java

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {

    _name = (String) params.get("name");
    if (_name == null) {
        throw new ConfigurationException("Unable to find name");
    }//from w  w w. j  a  v  a 2 s.c  o  m

    _guid = (String) params.get("guid");
    if (_guid == null) {
        throw new ConfigurationException("Unable to find the guid");
    }

    _zoneId = (String) params.get("zoneId");
    if (_zoneId == null) {
        throw new ConfigurationException("Unable to find zone");
    }

    String hostname = (String) params.get("hostname");
    if (hostname == null) {
        throw new ConfigurationException("Unable to find hostname");
    }

    String cmsUser = (String) params.get("cmsuser");
    if (cmsUser == null) {
        throw new ConfigurationException("Unable to find CMS username");
    }

    String cmsUserPassBase64 = (String) params.get("cmsuserpass");
    if (cmsUserPassBase64 == null) {
        throw new ConfigurationException("Unable to find CMS password");
    }

    String port = (String) params.get("port");
    if (port == null) {
        throw new ConfigurationException("Unable to find port");
    }

    String apiRelativePath = (String) params.get("apirelativepath");
    if ((apiRelativePath != null) && (!apiRelativePath.isEmpty())) {
        String apiVersion = apiRelativePath.substring(apiRelativePath.lastIndexOf('/') + 1);
        if (!Pattern.matches("v\\d+_\\d+", apiVersion)) {
            throw new ConfigurationException("Incorrect API version");
        }
    } else {
        throw new ConfigurationException("Unable to find API version");
    }

    String retryCount = (String) params.get("retrycount");
    if ((retryCount != null) && (!retryCount.isEmpty())) {
        try {
            _numRetries = Integer.parseInt(retryCount);
        } catch (NumberFormatException ex) {
            throw new ConfigurationException("Number of retries has to be between 1 and 10");
        }
        if ((_numRetries < 1) || (_numRetries > 10)) {
            throw new ConfigurationException("Number of retries has to be between 1 and 10");
        }
    } else {
        throw new ConfigurationException("Unable to find number of retries");
    }

    String retryInterval = (String) params.get("retryinterval");
    if ((retryInterval != null) && (!retryInterval.isEmpty())) {
        try {
            _retryInterval = Integer.parseInt(retryInterval);
        } catch (NumberFormatException ex) {
            throw new ConfigurationException("Retry interval has to be between 0 and 10000 ms");
        }
        if ((_retryInterval < 0) || (_retryInterval > 10000)) {
            throw new ConfigurationException("Retry interval has to be between 0 and 10000 ms");
        }
    } else {
        throw new ConfigurationException("Unable to find retry interval");
    }

    _relativePath = new StringBuffer().append("https://").append(hostname).append(":").append(port)
            .append(apiRelativePath).toString();

    String cmsUserPass = org.apache.commons.codec.binary.StringUtils
            .newStringUtf8(Base64.decodeBase64(cmsUserPassBase64));
    _cmsUserInfo = new String[] { CMS_USER_ENTEPRISE_NAME, cmsUser, cmsUserPass };

    try {
        loadNuageClient();
    } catch (Exception e) {
        throw new CloudRuntimeException("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
    }

    try {
        login();
    } catch (Exception e) {
        s_logger.error("Failed to login to Nuage VSD on " + name + " as user " + cmsUser + " Exception "
                + e.getMessage());
        throw new CloudRuntimeException("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
    }

    return true;
}

From source file:com.cloud.network.resource.NuageVspResourceConfiguration.java

public NuageVspApiVersion getApiVersion() throws ConfigurationException {
    try {/*from w w w  .j  a  v a  2 s .c  o  m*/
        if (_apiVersion != null) {
            return NuageVspApiVersion.fromString(_apiVersion);
        }
        return null;
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException("Incorrect API version");
    }
}

From source file:com.cloud.maint.UpgradeManagerImpl.java

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    _name = name;/*from   w w w .jav  a2s. c om*/

    final ComponentLocator locator = ComponentLocator.getCurrentLocator();
    _upgradeDao = locator.getDao(AgentUpgradeDao.class);
    if (_upgradeDao == null) {
        throw new ConfigurationException("Unable to retrieve the storage layer.");
    }

    ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
    if (configDao == null) {
        throw new ConfigurationException("Unable to get the configuration dao.");
    }

    final Map<String, String> configs = configDao.getConfiguration("UpgradeManager", params);

    File agentUpgradeFile = PropertiesUtil.findConfigFile("agent-update.properties");
    Properties agentUpgradeProps = new Properties();
    try {
        if (agentUpgradeFile != null) {
            agentUpgradeProps.load(new FileInputStream(agentUpgradeFile));
        }

        _minimalVersion = agentUpgradeProps.getProperty("agent.minimal.version");
        _recommendedVersion = agentUpgradeProps.getProperty("agent.recommended.version");

        if (_minimalVersion == null) {
            _minimalVersion = "0.0.0.0";
        }

        if (_recommendedVersion == null) {
            _recommendedVersion = _minimalVersion;
        }

        //_upgradeUrl = configs.get("upgrade.url");

        //         if (_upgradeUrl == null) {
        //            s_logger.debug("There is no upgrade url found in configuration table");
        //                // _upgradeUrl = "http://updates.vmops.com/releases/rss.xml";
        //            }

        return true;
    } catch (IOException ex) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Error reading agent-update.properties:  " + ex);
        }
    }
    return false;
}

From source file:datadidit.helpful.hints.processors.csv.converter.ConvertCSVToJSON.java

@OnScheduled
public void onScheduled(final ProcessContext context) throws ConfigurationException {
    //Retrieve properties from context
    Boolean header = context.getProperty(HEADER).asBoolean();
    String fieldNames = context.getProperty(FIELD_NAMES).getValue();

    /*/*from w  w  w .ja v a 2s . c  o m*/
     * Create Schema based on properties from user. 
     */
    if (!header && fieldNames != null) {
        Builder build = CsvSchema.builder();
        for (String field : fieldNames.split(",")) {
            build.addColumn(field, CsvSchema.ColumnType.NUMBER_OR_STRING);
        }
        schema = build.build();
    } else if (header && fieldNames != null && !fieldNames.equals("")) {
        schema = this.buildCsvSchema(fieldNames, header);
    } else if (!header && fieldNames == null) {
        throw new ConfigurationException("File must either contain headers or you must provide them..");
    } else {
        schema = CsvSchema.emptySchema().withHeader();
    }
}

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

/**
 * Get Operators' Properties.//from w w w .j av a2  s. co m
 *
 * @return operators properties map.
 * @throws SQLException    on errors.
 * @throws NamingException on errors.
 */
public static Map<String, Operator> getOperatorProperties() throws SQLException, NamingException {
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    Map<String, Operator> operatorProperties = new HashMap<String, Operator>();
    String queryToGetOperatorProperties = "SELECT ID, operatorName, requiredIPValidation, ipHeader FROM operators";
    try {
        connection = getConnectDBConnection();
        preparedStatement = connection.prepareStatement(queryToGetOperatorProperties);
        resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            Operator operator = new Operator();
            int operatorId = resultSet.getInt(AuthProxyConstants.ID);
            String operatorName = resultSet.getString(AuthProxyConstants.OPERATOR_NAME);
            boolean requiredIPValidation = resultSet.getBoolean(AuthProxyConstants.REQUIRED_IP_VALIDATION);
            String ipHeader = resultSet.getString(AuthProxyConstants.IP_HEADER);
            operator.setOperatorId(operatorId);
            operator.setOperatorName(operatorName);
            operator.setRequiredIpValidation(requiredIPValidation);
            operator.setIpHeader(ipHeader);
            operatorProperties.put(operatorName, operator);
        }
    } catch (SQLException e) {
        throw new SQLException("Error occurred while retrieving operator properties.", e);
    } catch (NamingException e) {
        throw new ConfigurationException("DataSource could not be found in mobile-connect.xml");
    } finally {
        closeAllConnections(preparedStatement, connection, resultSet);
    }
    return operatorProperties;
}

From source file:com.wso2telco.dbUtil.DataBaseConnectUtils.java

/**
 * Update user details in Back Channeling Scenario : update Session ID
 *
 * @param sessionId     ID of the session
 * @param correlationId unique ID of the user
 *//*from   w w w . j a va 2  s  . co  m*/
public static void updateSessionIdInBackChannel(String correlationId, String sessionId)
        throws ConfigurationException, CommonAuthenticatorException {

    Connection connection = null;
    PreparedStatement preparedStatement = null;
    String updateUserDetailsQuery = null;

    updateUserDetailsQuery = "update backchannel_request_details set session_id=? where correlation_id=?;";

    try {
        connection = getConnectDBConnection();

        if (log.isDebugEnabled()) {
            log.debug("Executing the query " + updateUserDetailsQuery);
        }

        preparedStatement = connection.prepareStatement(updateUserDetailsQuery);
        preparedStatement.setString(1, sessionId);
        preparedStatement.setString(2, correlationId);
        preparedStatement.executeUpdate();

    } catch (SQLException e) {
        handleException("Error occurred while updating user details for : " + correlationId + "in "
                + "BackChannel Scenario.", e);
    } catch (NamingException e) {
        throw new ConfigurationException("DataSource could not be found in mobile-connect.xml");
    } finally {
        closeAllConnections(preparedStatement, connection);
    }
}