类javax.naming.NoInitialContextException源码实例Demo

下面列出了怎么用javax.naming.NoInitialContextException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: quarkus   文件: QuarkusDirContextFactory.java
@Override
public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) throws NamingException {
    final String className = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
    try {
        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
        return (InitialContextFactory) Class.forName(className, true, cl).newInstance();
    } catch (Exception e) {
        NoInitialContextException ne = new NoInitialContextException(
                "Cannot instantiate class: " + className);
        ne.setRootCause(e);
        throw ne;
    }
}
 
源代码2 项目: openjdk-jdk9   文件: AppletIsNotUsed.java
private static void testWith(String appletProperty) throws NamingException {
    Hashtable<Object, Object> env = new Hashtable<>();
    // Deliberately put java.lang.Object rather than java.applet.Applet
    // if an applet was used we would see a ClassCastException down there
    env.put(appletProperty, new Object());
    // It's ok to instantiate InitialContext with no parameters
    // and be unaware of it right until you try to use it
    Context ctx = new InitialContext(env);
    boolean threw = true;
    try {
        ctx.lookup("whatever");
        threw = false;
    } catch (NoInitialContextException e) {
        String m = e.getMessage();
        if (m == null || m.contains("applet"))
            throw new RuntimeException("The exception message is incorrect", e);
    } catch (Throwable t) {
        throw new RuntimeException(
                "The test was supposed to catch NoInitialContextException" +
                        " here, but caught: " + t.getClass().getName(), t);
    } finally {
        ctx.close();
    }

    if (!threw)
        throw new RuntimeException("The test was supposed to catch NoInitialContextException here");
}
 
源代码3 项目: javamelody   文件: JdbcWrapperHelper.java
static Map<String, DataSource> getJndiAndSpringDataSources() throws NamingException {
	Map<String, DataSource> dataSources;
	try {
		dataSources = new LinkedHashMap<String, DataSource>(getJndiDataSources());
	} catch (final NoInitialContextException e) {
		dataSources = new LinkedHashMap<String, DataSource>();
	}
	dataSources.putAll(SPRING_DATASOURCES);
	return dataSources;
}
 
源代码4 项目: tutorials   文件: JndiExceptionsUnitTest.java
@Test
@Order(1)
void givenNoContext_whenLookupObject_thenThrowNoInitialContext() {
    assertThrows(NoInitialContextException.class, () -> {
        JndiTemplate jndiTemplate = new JndiTemplate();
        InitialContext ctx = (InitialContext) jndiTemplate.getContext();
        ctx.lookup("java:comp/env/jdbc/datasource");
    }).printStackTrace();
}
 
private static NoInitialContextException createNamingException(Exception e) {
	final NoInitialContextException ex = new NoInitialContextException(e.toString());
	ex.initCause(e);
	return ex;
}
 
 类所在包
 类方法
 同包方法