List of usage examples for javax.naming Context URL_PKG_PREFIXES
String URL_PKG_PREFIXES
To view the source code for javax.naming Context URL_PKG_PREFIXES.
Click Source Link
From source file:org.grouter.common.jndi.JNDIUtils.java
public static void createInMemoryJndiProvider(List<BindingItem> bindings) { if (bindings == null) { throw new IllegalArgumentException("Can not bind null to jndi tree."); }/* w ww . j av a2s . c o m*/ try { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.commons.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); Iterator<BindingItem> bindingItemIterator = bindings.iterator(); while (bindingItemIterator.hasNext()) { BindingItem item = bindingItemIterator.next(); InitialContext initialContext = new InitialContext(); logger.debug("Creating component context : " + item.getJndipath()[0]); Context compContext = initialContext.createSubcontext(item.getJndipath()[0]); logger.debug("Creating environment context : " + item.getJndipath()[1]); Context envContext = compContext.createSubcontext(item.getJndipath()[1]); logger.debug("Bidning : " + item.getJndiName() + " to implementation : " + item.getImplemenation()); envContext.bind(item.getJndiName(), item.getImplemenation()); printJNDI(envContext, logger); //logger.debug(envContext.listBindings(initialContext.getNameInNamespace())); } } catch (NamingException e) { logger.error(e, e); } }
From source file:it.unipmn.di.dcs.sharegrid.web.model.StandardEnvironment.java
private Context getContext() throws NamingException { if (this.envCtx == null) { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, ManagementContextFactory.class.getName()); //env.put(Context.PROVIDER_URL, ""); //env.put(Context.OBJECT_FACTORIES, "foo.bar.ObjFactory"); //System.err.println( "INITIAL_CONTEXT_FACTORY: " + Context.INITIAL_CONTEXT_FACTORY );//XXX //System.err.println( "URL_PKG_PREFIXES: " + Context.URL_PKG_PREFIXES );//XXX env.put(Context.URL_PKG_PREFIXES, ManagementContextFactory.class.getName()); //System.err.println("ENV URI: " + envUri);//XXX Context ctx = new InitialContext(env); if (ctx != null) { //System.err.println("CONTEXT NOT NULL");//XXX String[] parts = this.envUri.split("/"); Context[] ctxs = new Context[parts.length + 1]; ctxs[0] = ctx;// w w w .jav a2 s .c o m int i = 1; for (String envPart : parts) { //System.err.println("ENV PART: " + envPart);//XXX ctxs[i] = (Context) this.getOrCreateSubcontext(envPart, ctxs[i - 1]); i++; } this.envCtx = (Context) this.getOrCreateSubcontext(this.envUri, ctx); //System.err.println("ENV CONTEXT: " + this.envCtx);//XXX //Properties properties = new Properties(); //properties.put( "driverClassName", "com.mysql.jdbc.Driver" ); //properties.put( "url", "jdbc:mysql://localhost:3306/sharegrid" ); //properties.put( "username", "root" ); //properties.put( "password", "" ); //javax.sql.DataSource dataSource = org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource( properties ); //this.envCtx.rebind( "jdbc/mysql", dataSource ); } } return this.envCtx; }
From source file:de.escidoc.core.admin.common.util.spring.RemoteJndiLocator.java
/** * Set the JNDI properties./*from w ww. j a v a 2 s.com*/ * * @throws WebserverSystemException * Thrown in case of an internal error. */ private void setInitialContextJndiProperties() throws WebserverSystemException { Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.setProperty(Context.URL_PKG_PREFIXES, "org.jnp.interfaces:org.jboss.naming"); properties.setProperty(Context.PROVIDER_URL, jndiUrl); this.setJndiEnvironment(properties); }
From source file:it.unipmn.di.dcs.sharegrid.web.management.ManagementEnv.java
/** Initialized the JNDI. */ protected void initJNDI() throws ManagementException { try {// w w w .ja v a 2s . c om this.ctxFactoryBuild = new ManagementContextFactoryBuilder(); NamingManager.setInitialContextFactoryBuilder(this.ctxFactoryBuild); NamingManager.setObjectFactoryBuilder(this.ctxFactoryBuild); // Initial environment with various properties Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, ManagementContextFactory.class.getName()); //env.put(Context.PROVIDER_URL, ""); //env.put(Context.OBJECT_FACTORIES, "foo.bar.ObjFactory"); env.put(Context.URL_PKG_PREFIXES, ManagementContextFactory.class.getPackage().getName()); this.initCtx = new InitialContext(env); Context javaCompCtx = (Context) this.getOrCreateSubcontext("java:comp", initCtx); if (javaCompCtx == null) { throw new ManagementException("JNDI problem. Cannot get java:comp context from InitialContext."); } Context envCtx = (Context) this.getOrCreateSubcontext("env", javaCompCtx); if (envCtx == null) { throw new ManagementException("JNDI problem. Cannot get env context from java:comp context."); } Context jdbcCtx = (Context) this.getOrCreateSubcontext("jdbc", envCtx); if (jdbcCtx == null) { throw new ManagementException("JNDI problem. Cannot get jdbc context from java:comp/env context."); } // Create the DataSource //Properties properties = new Properties(); //properties.put( "driverClassName", "com.mysql.jdbc.Driver" ); //properties.put( "url", "jdbc:mysql://localhost:3306/DB" ); //properties.put( "username", "username" ); //properties.put( "password", "********" ); // //DataSource dataSource = BasicDataSourceFactory.createDataSource( properties ); //initContext.bind( "java:comp/env/jdbc/db", dataSource ); //Reference ref = new Reference( "javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null ); //ref.add(new StringRefAddr("driverClassName", "com.mysql.jdbc.Driver")); //ref.add(new StringRefAddr("url", "jdbc:mysql://localhost:3306/sharegrid")); //ref.add(new StringRefAddr("username", "root")); //ref.add(new StringRefAddr("password", "")); //initCtx.rebind( "java:comp/env/jdbc/mysql", ref ); java.util.Properties properties = new java.util.Properties(); properties.put("driverClassName", "com.mysql.jdbc.Driver"); properties.put("url", "jdbc:mysql://localhost:3306/sharegrid"); properties.put("username", "root"); properties.put("password", ""); javax.sql.DataSource dataSource = org.apache.commons.dbcp.BasicDataSourceFactory .createDataSource(properties); initCtx.rebind("java:comp/env/jdbc/mysql", dataSource); } catch (Exception ex) { throw new ManagementException("JNDI problem.", ex); } }
From source file:org.jboss.as.test.integration.ejb.security.RunAsPrincipalCustomDomainTestCase.java
private WhoAmI lookupEntryBean() throws Exception { final Properties pr = new Properties(); pr.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); return (WhoAmI) new InitialContext(pr).lookup( "ejb:/" + DEPLOYMENT + "/" + EntryBean.class.getSimpleName() + "!" + WhoAmI.class.getName()); }
From source file:org.bonitasoft.engine.LocalServerTestsInitializer.java
public void prepareEnvironment() throws IOException, ClassNotFoundException, NoSuchMethodException, BonitaHomeNotSetException, IllegalAccessException, InvocationTargetException { System.out.println("========= PREPARE ENVIRONMENT ======="); String bonitaHome = setSystemPropertyIfNotSet(BONITA_HOME_PROPERTY, BONITA_HOME_DEFAULT_PATH); final String dbVendor = setSystemPropertyIfNotSet("sysprop.bonita.db.vendor", "h2"); // paste the default local server properties // TODO do not handle the default local server like this File platformInit = new File(bonitaHome, "engine-server/conf/platform-init"); FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/local-server.xml"), new File(platformInit, "local-server.xml")); FileUtils.copyInputStreamToFile(this.getClass().getResourceAsStream("/local-server.properties"), new File(platformInit, "local-server.properties")); // 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"); if ("h2".equals(dbVendor)) { this.h2Server = startH2Server(); }/*from ww w . j a v a 2 s. c om*/ }
From source file:org.modeshape.connector.meta.jdbc.DatasourceHelper.java
public static void bindInJNDI(String name) throws NamingException { // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.commons.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.bind("java:/" + name, dataSource); }
From source file:org.grouter.common.jndi.JNDIUtils.java
/** * Get context for remote jboss server.// w w w .ja v a 2 s . c om * * @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:com.legstar.mq.client.AbstractCicsMQ.java
/** * Given the endpoint parameters, setup a JNDI context to lookup JMS * resources.//from www.j a v a2s . c o 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.andromda.timetracker.test.EJB3Container.java
private static Hashtable<String, String> getInitialContextProperties() { Hashtable<String, String> props = new Hashtable<String, String>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.LocalOnlyContextFactory"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); return props; }