Example usage for javax.naming NamingException getMessage

List of usage examples for javax.naming NamingException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.wso2.carbon.appfactory.userstore.internal.OTLDAPUtil.java

public static NamingEnumeration<SearchResult> searchForUser(String searchFilter, String[] returnedAtts,
        DirContext dirContext, String userSearchBase) throws UserStoreException {
    SearchControls searchCtls = new SearchControls();
    searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    if (returnedAtts != null && returnedAtts.length > 0) {
        searchCtls.setReturningAttributes(returnedAtts);
    }//w w w  .  java2 s  .  c  o  m
    try {
        return dirContext.search(userSearchBase, searchFilter, searchCtls);
    } catch (NamingException e) {
        log.error("Search failed.", e);
        throw new UserStoreException(e.getMessage());
    }
}

From source file:OCCIConnectionServlet.java

public static ConnectionPoolDataSource getConnectionPoolDataSource(String baseName) {
    Context context = null;// ww  w  .  ja va2  s  .c o m
    ConnectionPoolDataSource cpds = null;
    try {
        Properties properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        properties.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
        context = new InitialContext(properties);
        cpds = (ConnectionPoolDataSource) context.lookup(baseName);
    } catch (NamingException e) {
        System.err.println(e.getMessage() + " creating JNDI context for " + baseName);
    }
    return cpds;
}

From source file:org.adeptnet.auth.kerberos.Krb5.java

public static String resolveServerName(final String serverName) {
    try {/*  w  w w  .  j  a v  a 2  s  .  com*/
        return recurseResolveToA(new Nameserver(), new HashSet<>(), serverName);
    } catch (NamingException ex) {
        LOG.error(String.format("Cannot Resolve %s - %s", serverName, ex.getMessage()), ex);
        return null;
    }
}

From source file:br.gov.jfrj.siga.persistencia.oracle.JDBCUtilOracle.java

public static Connection getConnectionPool(final String dataSource) {

    Context initContext = null;/*from www.  j  ava  2 s . c om*/
    Context envContext = null;
    Connection conn = null;

    try {
        JDBCUtilOracle.log.debug("Criando variavel de contexto");
        initContext = new InitialContext();

        envContext = (Context) initContext.lookup("java:/comp/env");
        JDBCUtilOracle.log.debug("Criando datasource ");
        final DataSource ds = (DataSource) envContext.lookup(dataSource);
        conn = ds.getConnection();

    } catch (final NamingException e) {
        JDBCUtilOracle.log.error(Messages.getString("Oracle.LookUpErro"));
        System.err.print(Messages.getString("Oracle.LookUpErro") + e.getMessage());

    } catch (final SQLException ex) {
        System.err.print(Messages.getString("Oracle.SQLErro") + ex.getMessage());
    }
    return conn;
}

From source file:org.pepstock.jem.springbatch.tasks.ChunkDataSourcesManager.java

/**
 * Clears all JDNI defintions//from  w  ww .  j a  v a  2  s.  co m
 * @param context JNDI context to clear
 * @param dataSourceList list of datasources to unbind
 */
static void clearJNDIContext(InitialContext context, List<DataSource> dataSourceList) {
    for (DataSource source : dataSourceList) {
        // unbinds all resources
        try {
            context.unbind(source.getName());
        } catch (NamingException e) {
            // ignore
            LogAppl.getInstance().ignore(e.getMessage(), e);
        }
    }
}

From source file:org.bibsonomy.lucene.util.JNDITestDatabaseBinder.java

private static void bindDatabaseContext(final String contextName, final String fileName) {
    final InitialContext ctx;
    final DataSource ds = getBasicDataSource(fileName);
    try {/*from  w  ww. j  a va  2 s . c  o  m*/
        // create Mock JNDI context
        MockContextFactory.setAsInitial();
        ctx = new InitialContext();
        ctx.bind("java:comp/env/jdbc/" + contextName, ds);
        ctx.bind("java:/comp/env/jdbc/" + contextName, ds);
    } catch (NamingException ex) {
        log.error("Error when trying to bind test database connection '" + contextName + "' via JNDI");
        log.error(ex.getMessage());
    }

}

From source file:org.wso2.extension.siddhi.store.rdbms.util.RDBMSTableTestUtils.java

public static void setupJNDIDatasource(String url, String driverClassName) {
    try {// w w w  .j  av a 2s .  c  o  m
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
        System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
        InitialContext context = new InitialContext();
        context.createSubcontext("java:");
        context.createSubcontext("java:comp");
        context.createSubcontext("java:comp/env");
        context.createSubcontext("java:comp/env/jdbc");
        Properties connectionProperties = new Properties();
        connectionProperties.setProperty("jdbcUrl", url);
        connectionProperties.setProperty("dataSource.user", user);
        connectionProperties.setProperty("dataSource.password", password);
        connectionProperties.setProperty("driverClassName", driverClassName);
        connectionProperties.setProperty("poolName", "JNDI_Pool");
        HikariConfig config = new HikariConfig(connectionProperties);
        DataSource testDataSourceJNDI = new HikariDataSource(config);
        context.bind(JNDI_RESOURCE, testDataSourceJNDI);
    } catch (NamingException e) {
        log.error("Error while bind the datasource as JNDI resource." + e.getMessage(), e);
    }
}

From source file:org.ballerinalang.stdlib.ldap.nativeimpl.Authenticate.java

public static boolean doAuthenticate(Strand strand, ObjectValue authStore, String userName, String password) {
    byte[] credential = password.getBytes(Charset.forName(LdapConstants.UTF_8_CHARSET));
    LdapConnectionContext connectionSource = (LdapConnectionContext) authStore
            .getNativeData(LdapConstants.LDAP_CONNECTION_SOURCE);
    DirContext ldapConnectionContext = (DirContext) authStore
            .getNativeData(LdapConstants.LDAP_CONNECTION_CONTEXT);
    CommonLdapConfiguration ldapConfiguration = (CommonLdapConfiguration) authStore
            .getNativeData(LdapConstants.LDAP_CONFIGURATION);
    LdapUtils.setServiceName((String) authStore.getNativeData(LdapConstants.ENDPOINT_INSTANCE_ID));

    if (LdapUtils.isNullOrEmptyAfterTrim(userName)) {
        //TODO verify why both return and throw are needed
        //            context.setReturnValues(new BBoolean(false));
        throw new BallerinaException("username or credential value is empty or null.");
    }//from   w  w  w . jav a  2 s  . c o m

    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Authenticating user " + userName);
        }
        String name = LdapUtils.getNameInSpaceForUsernameFromLDAP(userName.trim(), ldapConfiguration,
                ldapConnectionContext);
        if (name != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Authenticating with " + name);
            }
            return bindAsUser(name, credential, connectionSource);
        }
        return false;
    } catch (NamingException e) {
        LOG.error("Cannot bind user : " + userName, e);
        return false;
    } catch (UserStoreException e) {
        LOG.error(e.getMessage(), e);
        return false;
    } finally {
        LdapUtils.removeServiceName();
    }
}

From source file:com.tdclighthouse.prototype.utils.EmailUtils.java

public static Session getMailSession(final String sessionName) {
    Session result = null;/*  www.  j a  v  a  2  s. c o m*/
    InitialContext initialContext = null;
    try {
        initialContext = new InitialContext();
        Context context = (Context) initialContext.lookup("java:comp/env");
        result = (Session) context.lookup(sessionName);
    } catch (NamingException e) {
        throw new HstComponentException(e);
    } finally {
        try {
            if (initialContext != null) {
                initialContext.close();
            }
        } catch (NamingException e) {
            LOG.error(e.getMessage(), e);
        }
    }

    return result;
}

From source file:org.wso2.carbon.appmgt.impl.utils.APIMgtDBUtil.java

/**
 * Initialize received data source//from   w  ww.  j  a v a 2s  . com
 * 
 * @param dataSourceName
 *            : Data source name needs to be initialized
 * @return DataSource
 * @throws org.wso2.carbon.appmgt.api.AppManagementException
 *             if an error occurs while initializing the data source
 */
public static DataSource initializeDataSource(String dataSourceName) throws AppManagementException {
    DataSource ds = null;
    if (dataSourceName != null) {
        try {
            Context ctx = new InitialContext();
            ds = (DataSource) ctx.lookup(dataSourceName);
        } catch (NamingException e) {
            log.error("An exception occurred while initializing the DataSource " + dataSourceName + " - "
                    + e.getMessage(), e);
            throw new AppManagementException("Error while looking up the data " + "source: " + dataSourceName,
                    e);
        }
    }
    return ds;
}