private int deleteDeclaration1(String spediDeklNr, String spediNr) throws Exception { Hashtable ht = new Hashtable(); ht.put(InitialContext.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); int countBefore = 0; int countAfter = 0; InitialContext initialContext = new InitialContext(ht); DataSource ds = (DataSource) initialContext.lookup("jdbc/EdecDataSourceNonXA"); Connection con = null; PreparedStatement statement = null; ResultSet rs = null; try { con = ds.getConnection(); .prepareStatement("select count(*) as rowcount from edec_deklarationen_mgt where dko_spediteur_dekl_nr like ? and dko_spediteur_nr = ? "); statement.setString(1, spediDeklNr); statement.setString(2, spediNr); rs = statement.executeQuery(); rs.next(); countBefore = rs.getInt("rowcount"); rs.close(); .prepareStatement("DELETE FROM edec_deklarationen_mgt where dko_spediteur_dekl_nr like ? and dko_spediteur_nr = ?"); statement.setString(1, spediDeklNr); statement.setString(2, spediNr); .prepareStatement("DELETE FROM edec_deklarationen WHERE dek_id IN (SELECT d.dek_id FROM edec_deklarationen d " + "INNER JOIN edec_dekl_kopf k ON d.dek_id = k.dko_dek_id WHERE k.dko_spediteur_dekl_nr like ? )"); statement.setString(1, spediDeklNr);
@Override protected RedissonClient buildClient() throws LifecycleException { InitialContext context = null; try { context = new InitialContext(); Context envCtx = (Context) context.lookup("java:comp/env"); return (RedissonClient) envCtx.lookup(jndiName); } catch (NamingException e) { throw new LifecycleException("Unable to locate Redisson instance by name: " + jndiName, e); } finally { if (context != null) { try { context.close(); } catch (NamingException e) { throw new LifecycleException("Unable to close JNDI context", e); } } } }
private void unbind(String name) { InitialContext rootCtx = null; try { rootCtx = new InitialContext(); rootCtx.unbind(name); NonSerializableFactory.unbind(name); } catch (NamingException e) { log.warn("Failed to unbind scheduler with jndiName: " + name, e); } finally { if (rootCtx != null) { try { rootCtx.close(); } catch (NamingException ignore) {} } } } }
/** * Check whether a default JNDI environment, as in a Java EE environment, * is available on this JVM. * @return {@code true} if a default InitialContext can be used, * {@code false} if not */ public static boolean isDefaultJndiEnvironmentAvailable() { if (shouldIgnoreDefaultJndiEnvironment) { return false; } try { new InitialContext().getEnvironment(); return true; } catch (Throwable ex) { return false; } }
try { InitialContext ctx = new InitialContext(); myStateful = (MyStateful)ctx.lookup("java:comp/env/MyStatefulBean"); session.setAttribute("my_stateful", myStateful); } catch (Exception e) { // exception handling }
public void initialize() { try { this.workManager = (WorkManager) new InitialContext().lookup(workManagerName); } catch (NamingException e) { throw new IllegalStateException("Could not locate WorkManager: " + e.getMessage(), e); } }
Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); // set any other properties you want Context context = new InitialContext(p); Object o = context.lookup("WidgetBeanRemote");
private void init() { if (this.config == null || !this.config.containsKey(DS_JNDI_NAME) || !this.config.containsKey(PRINCIPAL_QUERY) || !this.config.containsKey(ROLES_QUERY) || !this.config.containsKey(USER_ROLES_QUERY)) { throw new IllegalArgumentException("All properties must be given ("+ DS_JNDI_NAME + "," + PRINCIPAL_QUERY +"," + ROLES_QUERY +"," +USER_ROLES_QUERY +")"); } String jndiName = this.config.getProperty(DS_JNDI_NAME, "java:/DefaultDS"); try { InitialContext ctx = new InitialContext(); ds = (DataSource) ctx.lookup(jndiName); } catch (Exception e) { throw new IllegalStateException("Can get data source for DB usergroup callback, JNDI name: " + jndiName, e); } }
protected Context createJndiContext() throws Exception { Properties properties = new Properties(); // jndi.properties is optional InputStream in = getClass().getClassLoader().getResourceAsStream("jndi.properties"); if (in != null) { log.debug("Using jndi.properties from classpath root"); properties.load(in); } else { properties.put("java.naming.factory.initial", "org.apache.camel.util.jndi.CamelInitialContextFactory"); } return new InitialContext(new Hashtable<>(properties)); }
/** * Create a new JNDI initial context. Invoked by {@link #execute}. * <p>The default implementation use this template's environment settings. * Can be subclassed for custom contexts, e.g. for testing. * * @return the initial Context instance * @throws NamingException in case of initialization errors */ @SuppressWarnings({"unchecked"}) protected Context createInitialContext() throws NamingException { Properties env = getEnvironment(); Hashtable icEnv = null; if (env != null) { icEnv = new Hashtable(env.size()); for (Enumeration en = env.propertyNames(); en.hasMoreElements();) { String key = (String) en.nextElement(); icEnv.put(key, env.getProperty(key)); } } return new InitialContext(icEnv); }
public JMSQueueSink(String qcfBindingName, String queueBindingName, String username, String password) { try { Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); env.put(Context.PROVIDER_URL, "tcp://localhost:61616"); Context ctx = new InitialContext(env); QueueConnectionFactory queueConnectionFactory; queueConnectionFactory = (QueueConnectionFactory) lookup(ctx, qcfBindingName); System.out.println("Queue Cnx Factory found"); Queue queue = (Queue) ctx.lookup(queueBindingName); System.out.println("Queue found: " + queue.getQueueName()); QueueConnection queueConnection = queueConnectionFactory .createQueueConnection(username, password); System.out.println("Queue Connection created"); QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer queueConsumer = queueSession.createConsumer(queue); queueConsumer.setMessageListener(this); queueConnection.start(); System.out.println("Queue Connection started"); } catch (Exception e) { logger.error("Could not read JMS message.", e); } }
Properties env = new Properties( ); env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName); if(providerURL != null) { env.put(Context.PROVIDER_URL, providerURL); } else { LogLog.warn("You have set InitialContextFactoryName option but not the " jndi = new InitialContext(env); } else { jndi = new InitialContext(); topicConnection.start(); jndi.close(); } catch(JMSException e) { errorHandler.error("Error while activating options for appender named ["+name+
public static <T> T lookupIIOP(String serverHost, int iiopPort, Class<T> homeClass, Class<?> beanClass) throws NamingException { final Properties prope = new Properties(); prope.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"); prope.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.iiop.naming:org.jboss.naming.client"); prope.put(Context.PROVIDER_URL, "corbaloc::" + serverHost +":" + iiopPort + "/JBoss/Naming/root"); final InitialContext context = new InitialContext(prope); final Object ejbHome = context.lookup(beanClass.getSimpleName()); return homeClass.cast(PortableRemoteObject.narrow(ejbHome, homeClass)); }
@Override public void start() { if (dataSourceName == null || dataSourceName.equals("")) { Log.error("No name specified for DataSource. JNDI lookup will fail", new Throwable()); return; } try { Properties contextProperties = new Properties(); for (String key: jndiPropertyKeys) { String value = JiveGlobals.getXMLProperty(key); if (value != null) { contextProperties.setProperty(key, value); } } Context context; if (contextProperties.size() > 0) { context = new InitialContext(contextProperties); } else { context = new InitialContext(); } dataSource = (DataSource)context.lookup(dataSourceName); } catch (Exception e) { Log.error("Could not lookup DataSource at '" + dataSourceName + "'", e); } }
public static Context getInitialContext() throws javax.naming.NamingException { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, " org.jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); return new javax.naming.InitialContext(p); }
@LocalClient public class MoviesTest extends TestCase { @EJB private Movies movies; @Resource private UserTransaction userTransaction; @PersistenceContext private EntityManager entityManager; public void setUp() throws Exception { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); p.put("movieDatabase", "new://Resource?type=DataSource"); p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); InitialContext initialContext = new InitialContext(p); // Here's the fun part initialContext.bind("inject", this); }
sanitizedPoolingProperties.setProperty("username", driverProperties.getProperty("user")); sanitizedPoolingProperties.setProperty("password", driverProperties.getProperty("password")); InitialContext initContext = new InitialContext(); initContext.rebind(uniqueName, managedDataSource); initContext.rebind("java:comp/UserTransaction", com.arjuna.ats.jta.UserTransaction.userTransaction()); initContext.rebind("java:comp/TransactionManager", tm); initContext.rebind("java:comp/TransactionSynchronizationRegistry", tsr); } catch (NamingException e) { logger.warning("No InitialContext available, resource won't be accessible via lookup");
Hashtable env = new Hashtable(5); env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); //Assuming weblogic server is running on localhost at port 7001 env.put(Context.PROVIDER_URL, "t3://localhost:7001"); Context ic = new InitialContext(env); //obtain a reference to the home or local home interface FooHome fooHome = (FooHome)ic.lookup("MyBeans/FooHome"); //Get a reference to an object that implements the beans remote (component) interface Foo foo = fooHome.create(); //call the service exposed by the bean foo.shoutFoo()
Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); //props.put(Context.PROVIDER_URL,"vm://localhost");//Either this or below props.put(Context.PROVIDER_URL,"tcp://localhost:65432"); props.put("queue.SendReceiveQueue", "org.apache.geronimo.configs/activemq-ra/JCAAdminObject/SendReceiveQueue"); InitialContext context = new InitialContext(props); QueueConnectionFactory connectionFactory = (QueueConnectionFactory)context.lookup ("ConnectionFactory"); Queue q = (Queue) context.lookup("SendReceiveQueue"); System.out.println("conn is : " + connectionFactory.getClass().getName()); System.out.println("queue is : " + q.getQueueName());
/** * Opens a new connection from JNDI data source by name using explicit JNDI properties. This method can be used in cases * when file <code>jndi.properties</code> cannot be easily updated. * * @param jndiName name of JNDI data source. * @param jndiProperties JNDI properties */ public DB open(String jndiName, Properties jndiProperties) { checkExistingConnection(name); try { Context ctx = new InitialContext(jndiProperties); DataSource ds = (DataSource) ctx.lookup(jndiName); Connection connection = ds.getConnection(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, jndiProperties.contains("url") ? jndiProperties.getProperty("url") : jndiName); return this; } catch (Exception e) { throw new InitException("Failed to connect to JNDI name: " + jndiName, e); } }