public static void main(String[] args) { File o; try { o = (File) NamingManager.getInitialContext(null).lookup("fs/test"); } catch (NamingException e) { throw new RuntimeException("could not get the test directory", e); } System.out.println(o.getAbsolutePath()); } }
@Override public DataSource getDefaultConnection() throws NamingException { Object dso = NamingManager.getInitialContext(null).lookup(defaultConnect()); return (DataSource) dso; }
static ClassLoader getExtClassLoader() { try { return ((JndiContext) NamingManager.getInitialContext(null)).getExtCl(); } catch (NamingException e) { // Don't do anything - this actually cannot happen. Death to checked exceptions. return null; } }
static ClassLoader getExtClassLoader() { try { return ((JndiContext) NamingManager.getInitialContext(null)).getExtCl(); } catch (NamingException e) { // Don't do anything - this actually cannot happen. Death to checked exceptions. return null; } }
@Override public ClassLoader getExtensionClassloader() { ClassLoader extLoader = null; try { extLoader = ((JndiContext) NamingManager.getInitialContext(null)).getExtCl(); } catch (NamingException e) { jqmlogger.warn("could not find ext directory class loader. Il will not be used", e); } return extLoader; }
@Override public DataSource getDefaultConnection() throws NamingException { Object dso = NamingManager.getInitialContext(null).lookup(defaultConnect()); return (DataSource) dso; }
@Override public ClassLoader getExtensionClassloader() { ClassLoader extLoader = null; try { extLoader = ((JndiContext) NamingManager.getInitialContext(null)).getExtCl(); } catch (NamingException e) { jqmlogger.warn("could not find ext directory class loader. Il will not be used", e); } return extLoader; }
/** * Retrieves the initial context by calling * <code>NamingManager.getInitialContext()</code> and cache it in * defaultInitCtx. Set <code>gotDefault</code> so that we know we've tried * this before. * * @return The non-null cached initial context. * @exception NoInitialContextException * If cannot find an initial context. * @exception NamingException * If a naming exception was encountered. */ @Override final protected Context getDefaultInitCtx() throws NamingException { if (!gotDefault) { defaultInitCtx = NamingManager.getInitialContext(myProps); gotDefault = true; } if (defaultInitCtx == null) throw new NoInitialContextException(); return defaultInitCtx; }
/** * This ldap connection will attempt to establish a connection using the configuration, * replacing the principal and the password * * @param config * @param bindDn * @param password * @throws LdapException */ public DefaultLdapConnection( LdapConnectionConfiguration config, String bindDn, String password ) throws LdapException { this.config = config; Hashtable<Object, Object> e = getEnvironment(); e.put( Context.SECURITY_PRINCIPAL, bindDn ); e.put( Context.SECURITY_CREDENTIALS, password ); try { context = (DirContext) NamingManager.getInitialContext( e ); } catch ( NamingException ex ) { throw new LdapException( "Could not connect to the server.", ex ); } }
static synchronized void registerAgent(int registryPort, int serverPort, String hostname) throws JqmInitError { if (init) { // The agent is JVM-global, not engine specific, so prevent double start. return; } jqmlogger.trace("registering remote agent"); try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); JndiContext ctx = (JndiContext) NamingManager.getInitialContext(null); ctx.registerRmiContext(LocateRegistry.createRegistry(registryPort)); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostname + ":" + serverPort + "/jndi/rmi://" + hostname + ":" + registryPort + "/jmxrmi"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); init = true; jqmlogger.info("The JMX remote agent was registered. Connection string is " + url); } catch (Exception e) { throw new JqmInitError("Could not create remote JMX agent", e); } } }
/** * Will create a JNDI Context and register it as the initial context factory builder * * @return the context * @throws NamingException * on any issue during initial context factory builder registration */ static JndiContext createJndiContext() throws NamingException { try { if (!NamingManager.hasInitialContextFactoryBuilder()) { JndiContext ctx = new JndiContext(); NamingManager.setInitialContextFactoryBuilder(ctx); return ctx; } else { return (JndiContext) NamingManager.getInitialContext(null); } } catch (Exception e) { jqmlogger.error("Could not create JNDI context: " + e.getMessage()); NamingException ex = new NamingException("Could not initialize JNDI Context"); ex.setRootCause(e); throw ex; } }
private DirContext getRootContext() throws NamingException { DirContext rootCtx = null; // test for the root of the namespace (the empty name) if (ctx.getNameInNamespace().length() == 0) { rootCtx = ctx; // context is already a root context } else { // Make properties suitable for the root context env = generateRootContextProperties(env); rootCtx = (DirContext) NamingManager.getInitialContext(env); // Propagate any context request controls (to rootCtx) if (ctx instanceof LdapContext) { ((LdapContext)rootCtx).setRequestControls( ((LdapContext)ctx).getRequestControls()); } } return rootCtx; } }
private DirContext getRootContext() throws NamingException { DirContext rootCtx = null; // test for the root of the namespace (the empty name) if (ctx.getNameInNamespace().length() == 0) { rootCtx = ctx; // context is already a root context } else { // Make properties suitable for the root context env = generateRootContextProperties(env); rootCtx = (DirContext) NamingManager.getInitialContext(env); // Propagate any context request controls (to rootCtx) if (ctx instanceof LdapContext) { ((LdapContext)rootCtx).setRequestControls( ((LdapContext)ctx).getRequestControls()); } } return rootCtx; } }
public DefaultLdapConnection( LdapConnectionConfiguration config, Rdn subRdn ) throws LdapException { this.config = config; LdapName baseDn = new LdapName( config.getBaseDn().getRdns() ); if ( subRdn != null ) { baseDn.add( subRdn ); } log.debug( "baseDn: {}", baseDn ); baseDnRdns = Collections.unmodifiableList( baseDn.getRdns() ); if ( context != null ) { throw new LdapException( "Already connected." ); } log.debug( "baseDnRdns: {}", baseDnRdns ); Hashtable<Object, Object> e = getEnvironment(); try { context = (DirContext) NamingManager.getInitialContext( e ); } catch ( NamingException ex ) { throw new LdapException( "Could not connect to the server.", ex ); } }
@Test public void testFileJndi() throws Exception { // Create JMS JNDI references for use by the test jar String path = "./testdir"; CreationTools.createJndiFile(cnx, "fs/testdirectory", "test directory", path); cnx.commit(); // Create the directory... (new File(path)).mkdir(); // Test try { File f = (File) NamingManager.getInitialContext(null).lookup("fs/testdirectory"); Assert.assertTrue(f.isDirectory()); f.delete(); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Test public void testUrlJndi() throws Exception { // Create JMS JNDI references for use by the test jar String url = "http://www.marsupilami.com"; CreationTools.createJndiUrl(cnx, "url/testurl", "test directory", url); cnx.commit(); try { URL f = (URL) NamingManager.getInitialContext(null).lookup("url/testurl"); Assert.assertEquals(url, f.toString()); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Before public void beforeTest() { jqmlogger.debug("**********************************************************"); jqmlogger.debug("Starting test " + testName.getMethodName()); try { ((JndiContext) NamingManager.getInitialContext(null)).resetSingletons(); } catch (NamingException e) { jqmlogger.warn("Could not purge test JNDI context", e); } JqmClientFactory.resetClient(null); cnx = getNewDbSession(); TestHelpers.cleanup(cnx); TestHelpers.createTestData(cnx); cnx.commit(); }
@Before public void before() throws Exception { // Create initial context mockStatic( NamingManager.class ); this.remoteInitialContext = mock(InitialContext.class); try { Mockito.when(NamingManager.getInitialContext(Mockito.any(Properties.class))).thenReturn(remoteInitialContext); } catch (NamingException e) { // do nothing.. } String prop = CONNECTION_FACTORY_NAME; this.connectionFactory = mock(ConnectionFactory.class); doReturn(this.connectionFactory).when(remoteInitialContext).lookup(prop); prop = SSL_CONNECTION_FACTORY_NAME; doReturn(this.connectionFactory).when(remoteInitialContext).lookup(prop); prop = SESSION_QUEUE_NAME; this.ksessionQueue = mock(Queue.class); doReturn(this.ksessionQueue).when(remoteInitialContext).lookup(prop); prop = TASK_QUEUE_NAME; this.taskQueue = mock(Queue.class); doReturn(this.taskQueue).when(remoteInitialContext).lookup(prop); prop = RESPONSE_QUEUE_NAME; this.responseQueue = mock(Queue.class); doReturn(responseQueue).when(remoteInitialContext).lookup(prop); System.out.println( ">>> " + testName.getMethodName()); }
@Before public void before() throws Exception { // Create initial context mockStatic( NamingManager.class ); this.remoteInitialContext = mock(InitialContext.class); try { Mockito.when(NamingManager.getInitialContext(Mockito.any(Properties.class))).thenReturn(remoteInitialContext); } catch (NamingException e) { // do nothing.. } String prop = CONNECTION_FACTORY_NAME; this.connectionFactory = mock(ConnectionFactory.class); doReturn(this.connectionFactory).when(remoteInitialContext).lookup(prop); prop = SSL_CONNECTION_FACTORY_NAME; doReturn(this.connectionFactory).when(remoteInitialContext).lookup(prop); prop = SESSION_QUEUE_NAME; this.ksessionQueue = mock(Queue.class); doReturn(this.ksessionQueue).when(remoteInitialContext).lookup(prop); prop = TASK_QUEUE_NAME; this.taskQueue = mock(Queue.class); doReturn(this.taskQueue).when(remoteInitialContext).lookup(prop); prop = RESPONSE_QUEUE_NAME; this.responseQueue = mock(Queue.class); doReturn(responseQueue).when(remoteInitialContext).lookup(prop); System.out.println( ">>> " + testName.getMethodName()); }
@Before public void before() throws Exception { // Create initial context mockStatic( NamingManager.class ); this.remoteInitialContext = mock(InitialContext.class); try { Mockito.when(NamingManager.getInitialContext(Mockito.any(Properties.class))).thenReturn(remoteInitialContext); } catch (NamingException e) { // do nothing.. } String prop = CONNECTION_FACTORY_NAME; this.connectionFactory = mock(ConnectionFactory.class); doReturn(this.connectionFactory).when(remoteInitialContext).lookup(prop); prop = SSL_CONNECTION_FACTORY_NAME; doReturn(this.connectionFactory).when(remoteInitialContext).lookup(prop); prop = SESSION_QUEUE_NAME; this.ksessionQueue = mock(Queue.class); doReturn(this.ksessionQueue).when(remoteInitialContext).lookup(prop); prop = TASK_QUEUE_NAME; this.taskQueue = mock(Queue.class); doReturn(this.taskQueue).when(remoteInitialContext).lookup(prop); prop = RESPONSE_QUEUE_NAME; this.responseQueue = mock(Queue.class); doReturn(responseQueue).when(remoteInitialContext).lookup(prop); System.out.println( ">>> " + testName.getMethodName()); }