/** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); initialContext = new InitialContext(); initialContext.createSubcontext("java:comp"); // This is what we need to bind to get handle of JTA's // UserTransaction. initialContext.bind("java:comp/UserTransaction", new KunderaJTAUserTransaction()); emf = Persistence.createEntityManagerFactory("couchdbJTA_pu"); pu = "couchdbJTA_pu"; super.setUpBase(((EntityManagerFactoryImpl) emf).getKunderaMetadataInstance()); em = emf.createEntityManager(); }
/** * Ensure that the given name is bound to a context. * @param ctx * @param name * @throws NamingException */ public static final Context ensureCtx(InitialContext ctx, String name) throws NamingException { try { return ctx.createSubcontext(name); } catch (NameAlreadyBoundException e) { // this is ok return (Context) ctx.lookup(name); } }
CloakJNDI() { try { InitialContext ic = new InitialContext(); if (ic.lookup(DEFAULT_ENV_CONTEXT) == null) { ic.createSubcontext(DEFAULT_ENV_CONTEXT); } } catch (NamingException e) { throw new CloakDBException("Failed to establish an InitialContext."); } }
@Override public Context createSubcontext(Name name) throws NamingException { Context out; if (this.initialContext == null) { out = this.defaultInitCtx.createSubcontext(name); } else { out = this.initialContext.createSubcontext(name); } return out; }
@Override public Context createSubcontext(String name) throws NamingException { Context out; if (this.initialContext == null) { out = this.defaultInitCtx.createSubcontext(name); } else { out = this.initialContext.createSubcontext(name); } return out; }
@Override public Context createSubcontext(Name name) throws NamingException { Context out; if (this.initialContext == null) { out = this.defaultInitCtx.createSubcontext(name); } else { out = this.initialContext.createSubcontext(name); } return out; }
@Override public Context createSubcontext(String name) throws NamingException { Context out; if (this.initialContext == null) { out = this.defaultInitCtx.createSubcontext(name); } else { out = this.initialContext.createSubcontext(name); } return out; }
private synchronized void setInitialContext() { if (initialContext == null) { try { initialContext = new InitialContext(); try { Context.class.cast(initialContext.lookup("java:comp")); } catch (Exception e) { initialContext.createSubcontext("java:comp"); } } catch (NamingException e) { Assert.fail("Failed to create context : " + e.getMessage()); } } }
private synchronized void setInitialContext() { if (initialContext == null) { try { initialContext = new InitialContext(); try { Context.class.cast(initialContext.lookup("java:comp")); } catch (Exception e) { initialContext.createSubcontext("java:comp"); } } catch (NamingException e) { Assert.fail("Failed to create context : " + e.getMessage()); } } }
@BeforeClass public static void setUpClass() throws Exception { try { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("jboss"); ic.createSubcontext("jboss/datasources"); ic.createSubcontext("jboss/datasources/myDatasource"); OracleConnectionPoolDataSource ds = new OracleConnectionPoolDataSource(); ds.setURL("jdbc:oracle:thin:@xxxxx:1521:xxxxx"); ds.setUser("myUserid"); ds.setPassword("myPass"); ic.rebind("jboss/datasources/myDatasource", ds); } catch (NamingException ex) { ex.printStackTrace(); } }
public static void main(String[] args) throws NamingException { // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.createSubcontext("java:comp"); ic.createSubcontext("java:comp/env"); ic.createSubcontext("java:comp/env/jdbc"); MysqlConnectionPoolDataSource mysqlConnectionPoolDataSource = new MysqlConnectionPoolDataSource(); mysqlConnectionPoolDataSource.setUser("root"); mysqlConnectionPoolDataSource.setPassword("root"); mysqlConnectionPoolDataSource.setURL("jdbc:mysql://localhost:3306/test_my_database"); ic.bind("java:comp/env/jdbc/test", mysqlConnectionPoolDataSource); }
InitialContext ctx = new InitialContext(); // check if we have a JNDI binding for "jdbc". If we do not, we are // running locally (i.e. through JUnit, etc) boolean isJndiBound = true; try { ctx.lookup("jdbc"); } catch(NameNotFoundException ex) { isJndiBound = false; } if(!isJndiBound) { // Create the "jdbc" sub-context (i.e. the directory) ctx.createSubcontext("jdbc"); //parse the jetty-web.xml file Map<String, DataSource> dataSourceProperties = JettyWebParser.parse(); //add the data sources to the sub-context for(String key : dataSourceProperties.keySet()) { DataSource ds = dataSourceProperties.get(key); ctx.bind(key, ds); } }
@Override public void start() throws LifecycleException { UserTransactionManager utm = getTransactionManager(); try { try { utm.init(); } catch (SystemException ex) { Logger.getLogger(TransactionManagerProvider.class.getName()).log(Level.SEVERE, null, ex); } initialContext.createSubcontext("java:comp"); initialContext.bind("java:comp/UserTransaction", utm); } catch (NamingException ex) { Logger.getLogger(TransactionManagerProvider.class.getName()).log(Level.SEVERE, null, ex); } }
try { // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.createSubcontext("java:comp"); ic.createSubcontext("java:comp/env"); // Construct DataSource for staging // Construct DataSource for wfms PGSimpleDataSource ds = new PGSimpleDataSource(); ds.setUrl("jdbc:postgresql://localhost:5432/maintenanceDB");//you might get this from context ds.setUser("paul");//you might get this from context ds.setPassword("1234");//you might get this from context ic.bind("java:comp/env/maintenanceDB", wfmsds); } catch (NamingException ex) { ex.printStackTrace(); }
public static void setupInitialContext() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("jdbc"); PGSimpleDataSource ds = new PGSimpleDataSource(); ds.setDatabaseName("postgres"); ds.setUser("postgres"); ds.setPassword("admin"); ic.bind("jdbc/something", ds); }
private Context createJoramJndiContext() throws NamingException { log.start(); Context joramContext = null; // get the local container from the JNDI registry InitialContext rootContext = jndiService.getInitialContext(); if (JNDIUtil.isBound(rootContext, "/", TRANSPORTER_NAME)) { joramContext = (Context) rootContext.lookup(TRANSPORTER_NAME); } else { joramContext = rootContext.createSubcontext(TRANSPORTER_NAME); } log.end(); return joramContext; } }
public synchronized Context getUsersContext() throws NamingException { //lazy synchronized on this method this.log.call(); if (this.usersContext == null) { try { this.usersContext = (Context) this.getInitialContext().lookup(USERS_REF); } catch (final NameNotFoundException e) { this.usersContext = this.getInitialContext().createSubcontext(USERS_REF); } catch (final NameAlreadyBoundException e) { // in distributed mode, it is possible that 2 containers are // creating the context in the same time, the second // container get an Already Bound exception this.usersContext = (Context) this.getInitialContext().lookup(USERS_REF); } } return this.usersContext; }
/** * {@inheritDoc} */ public Context createSubcontext(Name name) throws NamingException { if (isInitialContextInitializerCall()) { return super.createSubcontext(name); } return getContext().createSubcontext(name); }
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); }
/** * {@inheritDoc} */ public Context createSubcontext(String name) throws NamingException { if (isInitialContextInitializerCall()) { return super.createSubcontext(name); } return getContext().createSubcontext(name); }