Example usage for javax.naming Context INITIAL_CONTEXT_FACTORY

List of usage examples for javax.naming Context INITIAL_CONTEXT_FACTORY

Introduction

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

Prototype

String INITIAL_CONTEXT_FACTORY

To view the source code for javax.naming Context INITIAL_CONTEXT_FACTORY.

Click Source Link

Document

Constant that holds the name of the environment property for specifying the initial context factory to use.

Usage

From source file:nl.nn.adapterframework.extensions.ifsa.jms.IfsaMessagingSourceFactory.java

protected Context createContext() throws NamingException {
    log.info("IFSA API installed version [" + IFSAConstants.getVersionInfo() + "]");
    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, IFSA_INITIAL_CONTEXT_FACTORY);
    env.put(Context.PROVIDER_URL, getProviderUrl());
    // Create context as required by IFSA 2.0. Ignore the possible deprecation....
    return new IFSAContext((Context) new InitialContext(env));
}

From source file:org.wso2.carbon.attachment.mgt.core.datasource.impl.BasicDataSourceManager.java

private DataSource lookupInJNDI(String remoteObjectName) throws NamingException {
    InitialContext ctx = null;/*from  w  w  w  . j a  va 2  s  . co m*/
    try {
        if (dataSourceConfig.getDataSourceJNDIRepoInitialContextFactory() != null
                && dataSourceConfig.getDataSourceJNDIRepoProviderURL() != null) {
            Properties jndiProps = new Properties();

            jndiProps.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                    dataSourceConfig.getDataSourceJNDIRepoInitialContextFactory());
            jndiProps.setProperty(Context.PROVIDER_URL, dataSourceConfig.getDataSourceJNDIRepoProviderURL());

            ctx = new InitialContext(jndiProps);
        } else {
            ctx = new InitialContext();
        }
        return (DataSource) ctx.lookup(remoteObjectName);
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (Exception ex1) {
                log.error("Error closing JNDI connection.", ex1);
            }
        }

    }
}

From source file:com.legstar.mq.client.AbstractCicsMQ.java

/**
 * Given the endpoint parameters, setup a JNDI context to lookup JMS
 * resources./*from   w  ww  . j  av  a2 s.  co  m*/
 * 
 * @param cicsMQEndpoint the endpoint paramers
 * @return the JNDI context
 * @throws CicsMQConnectionException if JNDI context cannot be created
 */
protected Context createJndiContext(final CicsMQEndpoint cicsMQEndpoint) throws CicsMQConnectionException {
    try {
        Properties env = new Properties();
        if (cicsMQEndpoint.getInitialContextFactory() != null
                && cicsMQEndpoint.getInitialContextFactory().length() > 0) {
            env.put(Context.INITIAL_CONTEXT_FACTORY, cicsMQEndpoint.getInitialContextFactory());
        }
        if (cicsMQEndpoint.getJndiProviderURL() != null && cicsMQEndpoint.getJndiProviderURL().length() > 0) {
            env.put(Context.PROVIDER_URL, cicsMQEndpoint.getJndiProviderURL());
        }
        if (cicsMQEndpoint.getJndiUrlPkgPrefixes() != null
                && cicsMQEndpoint.getJndiUrlPkgPrefixes().length() > 0) {
            env.put(Context.URL_PKG_PREFIXES, cicsMQEndpoint.getJndiUrlPkgPrefixes());
        }
        if (cicsMQEndpoint.getJndiProperties() != null) {
            env.putAll(getProperties(cicsMQEndpoint.getJndiProperties()));
        }
        if (env.size() > 0) {
            return new InitialContext(env);
        } else {
            return new InitialContext();
        }
    } catch (NamingException e) {
        throw new CicsMQConnectionException(e);
    }
}

From source file:org.apache.synapse.message.store.impl.jdbc.util.JDBCConfiguration.java

/**
 * Reading lookup information for existing datasource
 *
 * @param parameters -  parameters given in configuration
 *///from   w  w  w .  j  av  a  2 s  . co  m
private void readLookupConfig(Map<String, Object> parameters) {
    String dataSourceName = (String) parameters.get(JDBCMessageStoreConstants.JDBC_DSNAME);
    this.setDataSourceName(dataSourceName);

    if (parameters.get(JDBCMessageStoreConstants.JDBC_ICCLASS) != null) {
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, parameters.get(JDBCMessageStoreConstants.JDBC_ICCLASS));
        props.put(Context.PROVIDER_URL, parameters.get(JDBCMessageStoreConstants.JDBC_CONNECTION_URL));
        props.put(Context.SECURITY_PRINCIPAL, parameters.get(JDBCMessageStoreConstants.JDBC_USERNAME));
        props.put(Context.SECURITY_CREDENTIALS, parameters.get(JDBCMessageStoreConstants.JDBC_PASSWORD));

        this.setJndiProperties(props);
    }
}

From source file:org.apache.cloudstack.ldap.LdapContextFactory.java

private Hashtable<String, String> getEnvironment(final String principal, final String password,
        final String providerUrl, final boolean isSystemContext, Long domainId) {
    final String factory = _ldapConfiguration.getFactory();
    String url = providerUrl == null ? _ldapConfiguration.getProviderUrl(domainId) : providerUrl;
    if (StringUtils.isEmpty(url) && domainId != null) {
        //try a default ldap implementation
        url = _ldapConfiguration.getProviderUrl(null);
    }//from w  w w.  ja  va 2 s  .  c  o m

    final Hashtable<String, String> environment = new Hashtable<>();

    environment.put(Context.INITIAL_CONTEXT_FACTORY, factory);
    environment.put(Context.PROVIDER_URL, url);
    environment.put("com.sun.jndi.ldap.read.timeout", _ldapConfiguration.getReadTimeout(domainId).toString());
    environment.put("com.sun.jndi.ldap.connect.pool", "true");

    enableSSL(environment);
    setAuthentication(environment, isSystemContext, domainId);

    if (principal != null) {
        environment.put(Context.SECURITY_PRINCIPAL, principal);
    }

    if (password != null) {
        environment.put(Context.SECURITY_CREDENTIALS, password);
    }

    return environment;
}

From source file:org.miloss.fgsms.common.UtilityTest.java

public UtilityTest() throws Exception {
    File f = new File("../resources/test-database.properties");
    Properties db = new Properties();
    if (f.exists()) {
        FileInputStream fis = new FileInputStream(f);
        db.load(fis);//from  w  w  w.  j a v  a  2  s  .  c  o  m
        fis.close();
    } else {
        fail("cannot load test-database.properties");
    }
    try {
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitialContextFactoryForTest.class.getName());
        // Construct DataSource 
        //jdbc:postgresql://localhost:5432/fgsmsPerformance
        PGPoolingDataSource ds = new PGPoolingDataSource();
        ds.setMaxConnections(Integer.parseInt((String) db.get("perf_maxconnections")));
        ds.setServerName((String) db.get("perf_servername"));
        ds.setPortNumber(Integer.parseInt((String) db.get("perf_port")));
        ds.setDatabaseName((String) db.get("perf_db"));
        ds.setUser((String) db.get("perf_user"));
        ds.setPassword((String) db.get("perf_password"));
        ds.setSsl((Boolean) Boolean.parseBoolean((String) db.get("perf_ssl")));
        ds.setInitialConnections(Integer.parseInt((String) db.get("perf_initialconnections")));
        System.out.println("Binding to " + ds.getServerName() + ":" + ds.getPortNumber());
        InitialContextFactoryForTest.bind("java:fgsmsPerformance", ds);

        ds = new PGPoolingDataSource();
        ds.setMaxConnections(Integer.parseInt((String) db.get("config_maxconnections")));
        ds.setServerName((String) db.get("config_servername"));
        ds.setPortNumber(Integer.parseInt((String) db.get("config_port")));
        ds.setDatabaseName((String) db.get("config_db"));
        ds.setUser((String) db.get("config_user"));
        ds.setPassword((String) db.get("config_password"));
        ds.setSsl((Boolean) Boolean.parseBoolean((String) db.get("config_ssl")));
        ds.setInitialConnections(Integer.parseInt((String) db.get("config_initialconnections")));
        System.out.println("Binding to " + ds.getServerName() + ":" + ds.getPortNumber());
        InitialContextFactoryForTest.bind("java:fgsmsConfig", ds);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:org.grouter.common.jndi.JNDIUtils.java

/**
 * Get context for remote jboss server./*  w ww  .  j a  v a 2 s. com*/
 *
 * @param jndiUrl the jndiurl, if null a default will be used for jboss
 * @return initialcontext
 * @throws NamingException  see {@link NamingException}
 */
@SuppressWarnings({ "UnnecessaryLocalVariable", "SameParameterValue" })
public static InitialContext getJbossInitialContextForServer(String jndiUrl) throws NamingException {
    if (jndiUrl == null) {
        jndiUrl = "jnp://127.0.0.1:1099";
    }
    Hashtable<String, String> hashtable = new Hashtable<String, String>();
    hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    hashtable.put(Context.PROVIDER_URL, jndiUrl);
    hashtable.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
    InitialContext iniCtx = new InitialContext(hashtable);
    return iniCtx;
}

From source file:org.seedstack.seed.ws.internal.jms.SoapJmsUri.java

static Context getContext(SoapJmsUri soapJmsUri) throws NamingException {
    Properties properties = new Properties();

    String jndiInitialContextFactory = soapJmsUri.getParameter("jndiInitialContextFactory");
    if (!StringUtils.isEmpty(jndiInitialContextFactory)) {
        properties.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory);
    }/* w w  w. j a  va2  s.  c  o  m*/

    String jndiURL = soapJmsUri.getParameter("jndiURL");
    if (!StringUtils.isEmpty(jndiURL)) {
        properties.setProperty(javax.naming.Context.PROVIDER_URL, jndiURL);
    }

    return new InitialContext(properties);
}

From source file:OCCIConnectionServlet.java

public static ConnectionPoolDataSource getConnectionPoolDataSource(String baseName) {
    Context context = null;//from w ww  .j a  v a2  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:com.clican.pluto.common.util.JndiUtils.java

/**
 * Unbind the rsource manager instance from the JNDI directory.
 * <p>/*w w w .j a v a2 s . c om*/
 * After this method is called, it is no longer possible to obtain the
 * resource manager instance from the JNDI directory.
 * <p>
 * Note that this method will not remove the JNDI contexts corresponding to
 * the individual path segments of the full resource manager JNDI path.
 * 
 * @param jndiName
 *            The full JNDI path at which the resource manager instance was
 *            previously bound.
 * @return <b>true</b> if the resource manager was successfully unbound
 *         from JNDI; otherwise <b>false</b>.
 * 
 * @see #bind(String, Object)
 */
public static boolean unbind(String jndiName) {
    if (log.isDebugEnabled()) {
        log.debug("Unbinding object at path [" + jndiName + "] from the JNDI repository.");
    }
    Context ctx = null;
    try {
        Hashtable<String, String> ht = new Hashtable<String, String>();
        // If a special JNDI initial context factory was specified in the
        // constructor, then use it.
        if (jndiInitialContextFactory != null) {
            ht.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory);
        }
        ctx = new InitialContext(ht);
        Object obj = lookupObject(jndiName);
        if (obj instanceof Serializable || jndiInitialContextFactory != null) {
            ctx.unbind(jndiName);
        } else {
            NonSerializableFactory.unbind(jndiName);
        }
    } catch (NamingException ex) {
        log.error("An error occured while unbinding [" + jndiName + "] from JNDI:", ex);
        return false;
    } finally {
        if (ctx != null) {
            try {
                ctx.close();
            } catch (NamingException ne) {
                log.error("Close context error:", ne);
            }
        }
    }
    return true;
}