Example usage for javax.naming Context URL_PKG_PREFIXES

List of usage examples for javax.naming Context URL_PKG_PREFIXES

Introduction

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

Prototype

String URL_PKG_PREFIXES

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

Click Source Link

Document

Constant that holds the name of the environment property for specifying the list of package prefixes to use when loading in URL context factories.

Usage

From source file:com.duroty.application.files.actions.DownloadFileAction.java

/**
 * DOCUMENT ME!/*w  w w . j a  v  a  2s  .  c  om*/
 *
 * @param request DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
protected Hashtable getContextProperties(HttpServletRequest request) {
    Hashtable props = (Hashtable) SessionManager.getObject(Constants.CONTEXT_PROPERTIES, request);

    if (props == null) {
        props = new Hashtable();

        props.put(Context.INITIAL_CONTEXT_FACTORY,
                Configuration.properties.getProperty(Configuration.JNDI_INITIAL_CONTEXT_FACTORY));
        props.put(Context.URL_PKG_PREFIXES,
                Configuration.properties.getProperty(Configuration.JNDI_URL_PKG_PREFIXES));
        props.put(Context.PROVIDER_URL, Configuration.properties.getProperty(Configuration.JNDI_PROVIDER_URL));

        Principal principal = request.getUserPrincipal();
        props.put(Context.SECURITY_PRINCIPAL, principal.getName());
        props.put(Context.SECURITY_CREDENTIALS, SessionManager.getObject(Constants.JAAS_PASSWORD, request));

        props.put(Context.SECURITY_PROTOCOL,
                Configuration.properties.getProperty(Configuration.SECURITY_PROTOCOL));

        SessionManager.setObject(Constants.CONTEXT_PROPERTIES, props, request);
    }

    return props;
}

From source file:nl.nn.adapterframework.jms.JNDIBase.java

protected Hashtable getJndiEnv() throws NamingException {
    Properties jndiEnv = new Properties();

    if (StringUtils.isNotEmpty(getJndiProperties())) {
        URL url = ClassUtils.getResourceURL(classLoader, getJndiProperties());
        if (url == null) {
            throw new NamingException("cannot find jndiProperties from [" + getJndiProperties() + "]");
        }/*from w w  w  .  j a  v  a2  s  .com*/
        try {
            jndiEnv.load(url.openStream());
        } catch (IOException e) {
            throw new NamingException("cannot load jndiProperties [" + getJndiProperties() + "] from url ["
                    + url.toString() + "]");
        }
    }
    if (getInitialContextFactoryName() != null)
        jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY, getInitialContextFactoryName());
    if (getProviderURL() != null)
        jndiEnv.put(Context.PROVIDER_URL, getProviderURL());
    if (getAuthentication() != null)
        jndiEnv.put(Context.SECURITY_AUTHENTICATION, getAuthentication());
    if (getPrincipal() != null || getCredentials() != null || getJndiAuthAlias() != null) {
        CredentialFactory jndiCf = new CredentialFactory(getJndiAuthAlias(), getPrincipal(), getCredentials());
        if (StringUtils.isNotEmpty(jndiCf.getUsername()))
            jndiEnv.put(Context.SECURITY_PRINCIPAL, jndiCf.getUsername());
        if (StringUtils.isNotEmpty(jndiCf.getPassword()))
            jndiEnv.put(Context.SECURITY_CREDENTIALS, jndiCf.getPassword());
    }
    if (getUrlPkgPrefixes() != null)
        jndiEnv.put(Context.URL_PKG_PREFIXES, getUrlPkgPrefixes());
    if (getSecurityProtocol() != null)
        jndiEnv.put(Context.SECURITY_PROTOCOL, getSecurityProtocol());

    if (log.isDebugEnabled()) {
        for (Iterator it = jndiEnv.keySet().iterator(); it.hasNext();) {
            String key = (String) it.next();
            String value = jndiEnv.getProperty(key);
            log.debug("jndiEnv [" + key + "] = [" + value + "]");
        }
    }
    return jndiEnv;
}

From source file:org.grouter.core.readers.JmsReaderJob.java

private static InitialContext getInitialContext(String providerUrl, String initialContextFactory,
        String urlPkgPrefixes) throws NamingException {
    Hashtable<String, String> hashtable = new Hashtable<String, String>();
    hashtable.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
    hashtable.put(Context.PROVIDER_URL, providerUrl);
    hashtable.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
    return new InitialContext(hashtable);
}

From source file:org.wso2.carbon.apimgt.impl.dao.test.CertificateMgtDaoTest.java

private static void initializeDatabase(String configFilePath)
        throws IOException, XMLStreamException, NamingException {

    InputStream in;/*from   w w  w .j a  va 2 s. c  o  m*/
    in = FileUtils.openInputStream(new File(configFilePath));
    StAXOMBuilder builder = new StAXOMBuilder(in);
    String dataSource = builder.getDocumentElement().getFirstChildWithName(new QName("DataSourceName"))
            .getText();
    OMElement databaseElement = builder.getDocumentElement().getFirstChildWithName(new QName("Database"));
    String databaseURL = databaseElement.getFirstChildWithName(new QName("URL")).getText();
    String databaseUser = databaseElement.getFirstChildWithName(new QName("Username")).getText();
    String databasePass = databaseElement.getFirstChildWithName(new QName("Password")).getText();
    String databaseDriver = databaseElement.getFirstChildWithName(new QName("Driver")).getText();

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(databaseDriver);
    basicDataSource.setUrl(databaseURL);
    basicDataSource.setUsername(databaseUser);
    basicDataSource.setPassword(databasePass);

    // Create initial context
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
    try {
        InitialContext.doLookup("java:/comp/env/jdbc/WSO2AM_DB");
    } catch (NamingException e) {
        InitialContext ic = new InitialContext();
        ic.createSubcontext("java:");
        ic.createSubcontext("java:/comp");
        ic.createSubcontext("java:/comp/env");
        ic.createSubcontext("java:/comp/env/jdbc");

        ic.bind("java:/comp/env/jdbc/WSO2AM_DB", basicDataSource);
    }
}

From source file:com.joseflavio.iperoxo.IpeRoxo.java

/**
 * Inicia a {@link DataSource} e a {@link EntityManagerFactory}.
 *//*from  w  w  w .j a  v  a 2 s  . c om*/
private static void executarFonteDeDados() throws IOException, NamingException {

    if (Boolean.parseBoolean(getPropriedade("DataSource.Enable"))) {
        log.info(getMensagem(null, "Log.Iniciando.DataSource"));
    } else {
        return;
    }

    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");

    dataSource = new BasicDataSource();
    dataSource.setDriverClassName(getPropriedade("DataSource.Driver"));
    dataSource.setUrl(getPropriedade("DataSource.URL"));
    dataSource.setUsername(getPropriedade("DataSource.Username"));
    dataSource.setPassword(getPropriedade("DataSource.Password"));
    dataSource.setInitialSize(Integer.parseInt(getPropriedade("DataSource.InitialSize")));
    dataSource.setMaxTotal(Integer.parseInt(getPropriedade("DataSource.MaxTotal")));
    dataSource.setMinIdle(Integer.parseInt(getPropriedade("DataSource.MinIdle")));
    dataSource.setMaxIdle(Integer.parseInt(getPropriedade("DataSource.MaxIdle")));
    dataSource.setTestOnCreate(Boolean.parseBoolean(getPropriedade("DataSource.TestOnCreate")));
    dataSource.setTestWhileIdle(Boolean.parseBoolean(getPropriedade("DataSource.TestWhileIdle")));
    dataSource.setTestOnBorrow(Boolean.parseBoolean(getPropriedade("DataSource.TestOnBorrow")));
    dataSource.setTestOnReturn(Boolean.parseBoolean(getPropriedade("DataSource.TestOnReturn")));

    Context contexto = new InitialContext();
    try {
        contexto.bind("FONTE", dataSource);
    } finally {
        contexto.close();
    }

    while (true) {
        try (Connection con = getConnection()) {
            break;
        } catch (Exception e) {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException f) {
            }
        }
    }

    if (Boolean.parseBoolean(getPropriedade("DataSource.JPA.Enable"))) {
        log.info(getMensagem(null, "Log.Iniciando.JPA"));
    } else {
        return;
    }

    emf = Persistence.createEntityManagerFactory("JPA");

    try {
        emf.createEntityManager().close();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }

}

From source file:org.wso2.carbon.apimgt.impl.dao.test.APIMgtDAOTest.java

private void initializeDatabase(String configFilePath) {

    InputStream in = null;//from  w  w  w . j a va2  s  .  c o  m
    try {
        in = FileUtils.openInputStream(new File(configFilePath));
        StAXOMBuilder builder = new StAXOMBuilder(in);
        String dataSource = builder.getDocumentElement().getFirstChildWithName(new QName("DataSourceName"))
                .getText();
        OMElement databaseElement = builder.getDocumentElement().getFirstChildWithName(new QName("Database"));
        String databaseURL = databaseElement.getFirstChildWithName(new QName("URL")).getText();
        String databaseUser = databaseElement.getFirstChildWithName(new QName("Username")).getText();
        String databasePass = databaseElement.getFirstChildWithName(new QName("Password")).getText();
        String databaseDriver = databaseElement.getFirstChildWithName(new QName("Driver")).getText();

        BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setDriverClassName(databaseDriver);
        basicDataSource.setUrl(databaseURL);
        basicDataSource.setUsername(databaseUser);
        basicDataSource.setPassword(databasePass);

        // Create initial context
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
        System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
        try {
            InitialContext.doLookup("java:/comp/env/jdbc/WSO2AM_DB");
        } catch (NamingException e) {
            InitialContext ic = new InitialContext();
            ic.createSubcontext("java:");
            ic.createSubcontext("java:/comp");
            ic.createSubcontext("java:/comp/env");
            ic.createSubcontext("java:/comp/env/jdbc");

            ic.bind("java:/comp/env/jdbc/WSO2AM_DB", basicDataSource);
        }
    } catch (XMLStreamException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }
}

From source file:org.grouter.common.hibernate.HibernateUtilContextAware.java

/**
 * Create session factories and configurations and store in hibernateConfigMap. On
 * completion we enter INITIALISED state.
 *//*from   w  w  w. j a va  2s . co m*/
private static void createSessionFactoriesFromConfigMap() {
    // read in all config and create session factories
    Iterator iter = hibernateConfigMap.keySet().iterator();
    while (iter.hasNext()) {
        SessionFactory sessionFactory;
        String key = (String) iter.next();
        HibernateConfigItem hibernateConfigItem = hibernateConfigMap.get(key);
        String file = hibernateConfigItem.getConfigFile();
        Configuration configuration;
        if (file == null) {
            log.info("Loading properties config and not from file ");
            configuration = hibernateConfigItem.getConfiguration();
        } else {
            log.info("Loading properties from : " + file);
            configuration = new Configuration();
            configuration = configuration.configure(file);
        }
        try {
            String sessionFactoryName = configuration.getProperty(Environment.SESSION_FACTORY_NAME);
            if (sessionFactoryName != null) {
                log.debug("Looking up SessionFactory in JNDI with name : " + sessionFactoryName);
                try {
                    Hashtable env = new Hashtable();
                    env.put(Context.INITIAL_CONTEXT_FACTORY, configuration.getProperty(Environment.JNDI_CLASS));
                    env.put(Context.URL_PKG_PREFIXES, configuration.getProperty(Environment.JNDI_PREFIX));
                    env.put(Context.PROVIDER_URL, configuration.getProperty(Environment.JNDI_URL));
                    Context context = new InitialContext(env);
                    JNDIUtils.printJNDI(context, log);
                    sessionFactory = (SessionFactory) context.lookup(sessionFactoryName);
                    if (sessionFactory == null) {
                        throw new IllegalStateException(
                                "SessionFactory from JNDI lookup returned a null implemenation  using file : "
                                        + file);
                    }
                } catch (NamingException ex) {
                    log.error("Failed looking up sessinfactory : " + sessionFactoryName, ex);
                    throw new RuntimeException(ex);
                }
            } else {
                sessionFactory = configuration.buildSessionFactory();
                if (sessionFactory == null) {
                    throw new IllegalStateException(
                            "SessionFactory could not be createed from the configuration using file : " + file);
                }
            }
            hibernateConfigItem.setConfiguration(configuration);
            hibernateConfigItem.setSessionFactory(sessionFactory);
            // We need to have a default sessionfactory / configuration
            if (hibernateConfigItem.isDeafult()) {
                hibernateConfigItemDefault = hibernateConfigItem;
            }
            // setInterceptor(configuration, null);
            // hibernateConfigMap.put(key)
        } catch (Throwable ex) {
            log.error("Failed initializing from configuration.", ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    currentState = STATE.INITIALISED;
    log.info("Entered state : " + currentState);
}

From source file:org.apache.openaz.xacml.std.pip.engines.ldap.LDAPEngine.java

@Override
public void configure(String id, Properties properties) throws PIPException {
    /*//from   w  w  w  .  j a va  2s .c  o m
     * Handle the standard properties
     */
    super.configure(id, properties);
    String propertyPrefix = id + ".";

    /*
     * Configure the LDAP environment: I think the only required property is the provider_url
     */
    if (!this.configureStringProperty(propertyPrefix, Context.PROVIDER_URL, properties, null)) {
        throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No "
                + propertyPrefix + Context.PROVIDER_URL);
    }
    this.configureStringProperty(propertyPrefix, Context.AUTHORITATIVE, properties, null);
    this.configureIntegerProperty(propertyPrefix, Context.BATCHSIZE, properties, null);
    this.configureStringProperty(propertyPrefix, Context.DNS_URL, properties, null);
    this.configureStringProperty(propertyPrefix, Context.INITIAL_CONTEXT_FACTORY, properties,
            DEFAULT_CONTEXT_FACTORY);
    this.configureStringProperty(propertyPrefix, Context.LANGUAGE, properties, null);
    this.configureStringProperty(propertyPrefix, Context.OBJECT_FACTORIES, properties, null);
    this.configureStringProperty(propertyPrefix, Context.REFERRAL, properties, null);
    this.configureStringProperty(propertyPrefix, Context.SECURITY_AUTHENTICATION, properties, null);
    this.configureStringProperty(propertyPrefix, Context.SECURITY_CREDENTIALS, properties, null);
    this.configureStringProperty(propertyPrefix, Context.SECURITY_PRINCIPAL, properties, null);
    this.configureStringProperty(propertyPrefix, Context.SECURITY_PROTOCOL, properties, null);
    this.configureStringProperty(propertyPrefix, Context.STATE_FACTORIES, properties, null);
    this.configureStringProperty(propertyPrefix, Context.URL_PKG_PREFIXES, properties, null);

    String ldapScopeValue = properties.getProperty(propertyPrefix + PROP_LDAP_SCOPE, DEFAULT_SCOPE);
    if (LDAP_SCOPE_SUBTREE.equals(ldapScopeValue)) {
        this.ldapScope = SearchControls.SUBTREE_SCOPE;
    } else if (LDAP_SCOPE_OBJECT.equals(ldapScopeValue)) {
        this.ldapScope = SearchControls.OBJECT_SCOPE;
    } else if (LDAP_SCOPE_ONELEVEL.equals(ldapScopeValue)) {
        this.ldapScope = SearchControls.ONELEVEL_SCOPE;
    } else {
        this.logger.warn("Invalid LDAP Scope value '" + ldapScopeValue + "'; using " + DEFAULT_SCOPE);
        this.ldapScope = SearchControls.SUBTREE_SCOPE;
    }

    /*
     * Get list of resolvers defined for this LDAP Engine
     */
    String resolversList = properties.getProperty(propertyPrefix + PROP_RESOLVERS);
    if (resolversList == null || resolversList.isEmpty()) {
        throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No "
                + propertyPrefix + PROP_RESOLVERS);
    }

    /*
     * Iterate the resolvers
     */
    for (String resolver : Splitter.on(',').trimResults().omitEmptyStrings().split(resolversList)) {
        /*
         * Get the LDAPResolver for this LDAPEngine
         */
        String resolverClassName = properties
                .getProperty(propertyPrefix + PROP_RESOLVER + "." + resolver + ".classname");
        if (resolverClassName == null) {
            throw new PIPException("Invalid configuration for " + this.getClass().getName() + ": No "
                    + propertyPrefix + PROP_RESOLVER + "." + resolver + ".classname");
        }

        LDAPResolver ldapResolverNew = null;
        try {
            Class<?> classResolver = Class.forName(resolverClassName);
            if (!LDAPResolver.class.isAssignableFrom(classResolver)) {
                this.logger.error("LDAPResolver class " + resolverClassName + " does not implement "
                        + LDAPResolver.class.getCanonicalName());
                throw new PIPException("LDAPResolver class " + resolverClassName + " does not implement "
                        + LDAPResolver.class.getCanonicalName());
            }
            ldapResolverNew = LDAPResolver.class.cast(classResolver.newInstance());
        } catch (Exception ex) {
            this.logger.error("Exception instantiating LDAPResolver for class '" + resolverClassName + "': "
                    + ex.getMessage(), ex);
            throw new PIPException("Exception instantiating LDAPResolver for class '" + resolverClassName + "'",
                    ex);
        }
        assert ldapResolverNew != null;
        ldapResolverNew.configure(propertyPrefix + PROP_RESOLVER + "." + resolver, properties,
                this.getIssuer());

        this.ldapResolvers.add(ldapResolverNew);
    }

}

From source file:org.bonitasoft.engine.test.BonitaTestEngine.java

private void initializeEnvironment() {
    setSystemPropertyIfNotSet("sysprop.bonita.db.vendor", "h2");

    // Force these system properties
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
            "org.bonitasoft.engine.local.SimpleMemoryContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.bonitasoft.engine.local");

    final List<String> springConfigLocations = getSpringConfigLocations();
    springContext = new ClassPathXmlApplicationContext(
            springConfigLocations.toArray(new String[springConfigLocations.size()]));
}

From source file:org.settings4j.connector.JNDIConnector.java

private InitialContext getJNDIContext() throws NamingException {
    InitialContext initialContext;

    if (StringUtils.isEmpty(this.providerUrl) && StringUtils.isEmpty(this.initialContextFactory)
            && StringUtils.isEmpty(this.urlPkgPrefixes)) {

        initialContext = new InitialContext();
    } else {/*www  .  ja v a 2 s. co  m*/
        final Properties prop = new Properties();
        prop.put(Context.PROVIDER_URL, this.providerUrl);
        prop.put(Context.INITIAL_CONTEXT_FACTORY, this.initialContextFactory);
        prop.put(Context.URL_PKG_PREFIXES, this.urlPkgPrefixes);
        initialContext = new InitialContext(prop);
    }

    return initialContext;
}