当前位置: 首页>>代码示例>>Java>>正文


Java InitialDirContext.lookup方法代码示例

本文整理汇总了Java中javax.naming.directory.InitialDirContext.lookup方法的典型用法代码示例。如果您正苦于以下问题:Java InitialDirContext.lookup方法的具体用法?Java InitialDirContext.lookup怎么用?Java InitialDirContext.lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.naming.directory.InitialDirContext的用法示例。


在下文中一共展示了InitialDirContext.lookup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLdapDataSource

import javax.naming.directory.InitialDirContext; //导入方法依赖的package包/类
@Override
public DataSource createLdapDataSource(Properties loginProperties, String ldapName) throws NamingException
{
    DataSource ds;
    // borisv: this code stores all parameters in static baseEnvironment. So if you have multiple connections, next connection will get parameters from previous (unless overwriten by loginParamters).
    loginProperties.put(USE_JNDI_JDBC_CONNECTION_POOL_KEY, "false");
    if (loginProperties.getProperty(JAVA_NAMING_FACTORY_INITIAL) == null)
    {
        loginProperties.put(JAVA_NAMING_FACTORY_INITIAL, "com.sun.jndi.ldap.LdapCtxFactory");
    }
    InitialDirContext context = new JdbcInitialDirContext(loginProperties);

    Enumeration propKeys = loginProperties.keys();
    while(propKeys.hasMoreElements())
    {
        Object key = propKeys.nextElement();
        context.addToEnvironment((String)key, loginProperties.get(key));
    }

    ds = (DataSource) context.lookup(ldapName);
    return ds;
}
 
开发者ID:goldmansachs,项目名称:reladomo,代码行数:23,代码来源:JndiJdbcLdapDataSourceProvider.java

示例2: testConnectControls2

import javax.naming.directory.InitialDirContext; //导入方法依赖的package包/类
public void testConnectControls2() throws Exception {
    // set connect controls by property "java.naming.ldap.control.connect"
    env.put("java.naming.ldap.control.connect",
            new Control[] { new SortControl("", Control.NONCRITICAL) });

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

    InitialDirContext initialDirContext = new InitialDirContext(env);

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_SEARCH_RESULT_DONE,
            new EncodableLdapResult(), null) });
    LdapContext context = (LdapContext) initialDirContext.lookup("");

    Control[] controls = context.getConnectControls();
    assertNotNull(controls);
    assertEquals(1, controls.length);
    Control c = controls[0];
    assertTrue(c instanceof SortControl);
    assertEquals(Control.NONCRITICAL, c.isCritical());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:23,代码来源:LdapContextServerMockedTest.java

示例3: performTask

import javax.naming.directory.InitialDirContext; //导入方法依赖的package包/类
/**
 * Method performTask Control the flow of control of the logical operations
 * (方法performTask 可控制逻辑操作的控制流)
 */
public synchronized void performTask() throws Exception {
	System.out.println("\n Setting Up Initial JNDI Context ");
	Hashtable env = new Hashtable();
	env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
	env.put(Context.PROVIDER_URL, providerUrl);
	env.put(Context.REFERRAL, "throw");
	jndiContext = new InitialDirContext(env);
	System.out.println("\n Get QueueConnectionFactory ");
	queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup(qcfName);
	
	System.out.println("\n Get Queue ");
	queue = (Queue) jndiContext.lookup(queueName);
	
	System.out.println("\n Create Queue Connections ");
	queueConnection = queueConnectionFactory.createQueueConnection();
	
	//为连接对象queueConnection 设置了异常侦听器
	PtpListener jmsListener = new PtpListener();
	queueConnection.setExceptionListener(jmsListener);
	
	System.out.println("\n Start Queue Connection ");
	queueConnection.start();
	
	System.out.println("\n Create Queue Session ");
	queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
	
	System.out.println("\n Create Queue Receiver ");
	queueReceiver = queueSession.createReceiver(queue);
	
	//注册消息侦听器
	System.out.println("\n Register the Listener");
	queueReceiver.setMessageListener(jmsListener);
	
	// Wait for new messages.(等待新消息。)
	wait();
}
 
开发者ID:dreajay,项目名称:jcode,代码行数:41,代码来源:PtpAsyncConsumer.java

示例4: start

import javax.naming.directory.InitialDirContext; //导入方法依赖的package包/类
/**
 * start the connector
 */
public void start() throws Exception {
    LOG.info("connecting...");
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    this.ldapURI = getUri();
    LOG.debug("    URI [{}]", this.ldapURI);
    env.put(Context.PROVIDER_URL, this.ldapURI.toString());
    if (anonymousAuthentication) {
        LOG.debug("    login credentials [anonymous]");
        env.put(Context.SECURITY_AUTHENTICATION, "none");
    } else {
        LOG.debug("    login credentials [{}:******]", user);
        env.put(Context.SECURITY_PRINCIPAL, user);
        env.put(Context.SECURITY_CREDENTIALS, password);
    }
    boolean isConnected = false;
    while (!isConnected) {
        try {
            context = new InitialDirContext(env);
            isConnected = true;
        } catch (CommunicationException err) {
            if (failover) {
                this.ldapURI = getUri();
                LOG.error("connection error [{}], failover connection to [{}]", env.get(Context.PROVIDER_URL), this.ldapURI.toString());
                env.put(Context.PROVIDER_URL, this.ldapURI.toString());
                Thread.sleep(curReconnectDelay);
                curReconnectDelay = Math.min(curReconnectDelay * 2, maxReconnectDelay);
            } else {
                throw err;
            }
        }
    }

    // add connectors from search results
    LOG.info("searching for network connectors...");
    LOG.debug("    base   [{}]", base);
    LOG.debug("    filter [{}]", searchFilter);
    LOG.debug("    scope  [{}]", searchControls.getSearchScope());
    NamingEnumeration<SearchResult> results = context.search(base, searchFilter, searchControls);
    while (results.hasMore()) {
        addConnector(results.next());
    }

    // register persistent search event listener
    if (searchEventListener) {
        LOG.info("registering persistent search listener...");
        EventDirContext eventContext = (EventDirContext) context.lookup("");
        eventContext.addNamingListener(base, searchFilter, searchControls, this);
    } else { // otherwise close context (i.e. connection as it is no longer needed)
        context.close();
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:56,代码来源:LdapNetworkConnector.java

示例5: testAddToEnvironment

import javax.naming.directory.InitialDirContext; //导入方法依赖的package包/类
public void testAddToEnvironment() throws Exception {
    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

    assertNull(env.get(Context.REFERRAL));

    InitialDirContext initialDirContext = new InitialDirContext(env);

    // Context.REFERRAL changed doesn't cause re-bind operation
    initialDirContext.addToEnvironment(Context.REFERRAL, "ignore");

    assertEquals("ignore", initialDirContext.getEnvironment().get(
            Context.REFERRAL));

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_DEL_RESPONSE, new EncodableLdapResult(),
            null) });

    initialDirContext.destroySubcontext("cn=test");

    /*
     * Context.SECURITY_AUTHENTICATION will case re-bind when invoke context
     * methods at first time
     */
    Object preValue = initialDirContext.addToEnvironment(
            Context.SECURITY_AUTHENTICATION, "none");
    assertFalse("none".equals(preValue));

    server.setResponseSeq(new LdapMessage[] {
            new LdapMessage(LdapASN1Constant.OP_BIND_RESPONSE,
                    new BindResponse(), null),
            new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                    new EncodableLdapResult(), null) });

    initialDirContext.lookup("");

    preValue = initialDirContext.addToEnvironment(
            Context.SECURITY_AUTHENTICATION, "simple");
    assertFalse("simple".equals(preValue));

    // initialDirContext is shared connection, will create new connection
    server = new MockLdapServer(server);
    server.start();
    server.setResponseSeq(new LdapMessage[] {
            new LdapMessage(LdapASN1Constant.OP_BIND_RESPONSE,
                    new BindResponse(), null),
            new LdapMessage(LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                    new EncodableLdapResult(), null) });

    initialDirContext.lookup("");

}
 
开发者ID:shannah,项目名称:cn1,代码行数:53,代码来源:LdapContextServerMockedTest.java


注:本文中的javax.naming.directory.InitialDirContext.lookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。