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


Java InitialContext.lookup方法代码示例

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


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

示例1: main

import javax.naming.InitialContext; //导入方法依赖的package包/类
public static void main(String[] args) throws NamingException {
	checkArgs(args);
	
	Properties p = new Properties();
	
	p.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
	InitialContext ic = new WildFlyInitialContext(p);
	
	Simple proxy = (Simple) ic.lookup("ejb:EAP71-PLAYGROUND-server/ejb/SimpleBean!" + Simple.class.getName());
	
	try {
		proxy.logText("Simple invocation without security at " + new Date());
		log.info("Expected to work with the default configuration, to get a security failure remote the <local> element from the ApplicationRealm!");
	} catch (Exception e) {
		log.severe("Expected to fail if no <local> configuration in ApplicationRealm, unfortunately no good Exception");
		e.printStackTrace();
	}
}
 
开发者ID:wfink,项目名称:jboss-eap7.1-playground,代码行数:19,代码来源:SimpleWildFlyInitialContextClient.java

示例2: check

import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
public HealthStatus check() {

  try {
    InitialContext ic = new InitialContext();
    DataSource dataSource = (DataSource) ic.lookup(jndiName);

    try (Connection connection = dataSource.getConnection()) {

      try (Statement statement = connection.createStatement()) {
        if (statement.execute(healthQuery)) {
          return reportUp();
        }
      }
    }
  } catch (Exception ex) {
    return reportDown().withAttribute("message", ex.getMessage());
  }

  return reportDown();
}
 
开发者ID:thomasdarimont,项目名称:keycloak-health-checks,代码行数:22,代码来源:DatabaseHealthIndicator.java

示例3: main

import javax.naming.InitialContext; //导入方法依赖的package包/类
public static void main(String[] args) throws NamingException {
	checkArgs(args);

	// One option is to use the java context, the INITIAL_CONTEXT_FACTORY is added by jndi.properties
	// the URI and credentials by wildfly-config.xml
	InitialContext ic = new InitialContext();

	Simple proxy = (Simple) ic.lookup("ejb:EAP71-PLAYGROUND-server/ejb/SimpleBean!" + Simple.class.getName());
	
	try {
		if(proxy.checkApplicationUser("user1")) {
			log.info("Expected 'user1'");
		} else {
			log.severe("Unexpected user, see server.log");
		}
	} catch (EJBException e) {
		throw e;
	}
}
 
开发者ID:wfink,项目名称:jboss-eap7.1-playground,代码行数:20,代码来源:SimpleWildFlyConfigClient.java

示例4: getBeanManager

import javax.naming.InitialContext; //导入方法依赖的package包/类
private BeanManager getBeanManager() {
    try {
        InitialContext ctx = new InitialContext();
        return (BeanManager) ctx.lookup("java:comp/BeanManager");
    } catch (NamingException e) {
        throw new RuntimeException("Unable to lookup CDI bean manager", e);
    }
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:9,代码来源:AbstractAuditable.java

示例5: main

import javax.naming.InitialContext; //导入方法依赖的package包/类
public static void main(String[] args) throws NamingException {
	checkArgs(args);
	
	// Option is to use the WF context with no properties, this is not working because of JBEAP-xxxx at this moment
	InitialContext ic = new WildFlyInitialContext();
	
	Simple proxy = (Simple) ic.lookup("ejb:EAP71-PLAYGROUND-server/ejb/SimpleBean!" + Simple.class.getName());
	
	try {
		if(proxy.checkApplicationUser("admin")) {
			log.info("Expected 'admin'");
		} else {
			log.severe("Unexpected user, see server.log");
		}
	} catch (EJBException e) {
		throw e;
	}
}
 
开发者ID:wfink,项目名称:jboss-eap7.1-playground,代码行数:19,代码来源:WildFlyICConfigClient.java

示例6: main

import javax.naming.InitialContext; //导入方法依赖的package包/类
public static void main(String[] args) throws NamingException {
	checkArgs(args);
	
	Properties p = new Properties();
	
	p.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
	p.put(Context.PROVIDER_URL, "http-remoting://localhost:9080");
	
	p.put(Context.SECURITY_PRINCIPAL, "delegateUser");
	p.put(Context.SECURITY_CREDENTIALS, "delegateUser");
	InitialContext ic = new InitialContext(p);
	
	Delegate proxy = (Delegate) ic.lookup("ejb:EAP71-PLAYGROUND-MainServer-icApp/ejb/DelegateBean!" + Delegate.class.getName());
	proxy.checkApplicationUser4DedicatedConnection("delegateUser", "delegateUserR");
	
	ic.close();
}
 
开发者ID:wfink,项目名称:jboss-eap7.1-playground,代码行数:18,代码来源:DelegateClient.java

示例7: testSpecificConsumerRetrieval

import javax.naming.InitialContext; //导入方法依赖的package包/类
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testSpecificConsumerRetrieval(String username, String password,
                                          String hostname, String port) throws Exception {
    String queueName = "testSpecificConsumerRetrieval";

    // Create a durable queue using a JMS client
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(username, password, hostname, port)
            .withQueue(queueName)
            .build();

    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    QueueConnection connection = connectionFactory.createQueueConnection();
    connection.start();

    QueueSession queueSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(queueName);
    QueueReceiver receiver = queueSession.createReceiver(queue);

    HttpGet getAllConsumers = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
                                          + "/" + queueName + "/consumers");

    CloseableHttpResponse response = client.execute(getAllConsumers);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
    String body = EntityUtils.toString(response.getEntity());

    ConsumerMetadata[] consumers = objectMapper.readValue(body, ConsumerMetadata[].class);

    Assert.assertTrue(consumers.length > 0, "Number of consumers returned is incorrect.");

    int id = consumers[0].getId();
    HttpGet getConsumer = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/"
                                              + queueName + "/consumers/" + id);

    response = client.execute(getConsumer);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
    String consumerString = EntityUtils.toString(response.getEntity());
    ConsumerMetadata consumerMetadata = objectMapper.readValue(consumerString, ConsumerMetadata.class);

    Assert.assertEquals(consumerMetadata.getId().intValue(), id, "incorrect message id");

    receiver.close();
    queueSession.close();
    connection.close();
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:48,代码来源:ConsumersRestApiTest.java

示例8: sessionDestroyed

import javax.naming.InitialContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
   @Override
   public void sessionDestroyed(HttpSessionEvent sessionEvent) {
if (SessionListener.authenticationManager == null) {
    try {
	InitialContext initialContext = new InitialContext();
	SessionListener.authenticationManager = (CacheableManager<?, Principal>) initialContext
		.lookup("java:jboss/jaas/lams/authenticationMgr");
    } catch (NamingException e) {
	SessionListener.log.error("Error while getting authentication manager.", e);
    }
}

// clear the authentication cache when the session is invalidated
HttpSession session = sessionEvent.getSession();
if (session != null) {
    UserDTO userDTO = (UserDTO) session.getAttribute(AttributeNames.USER);
    if (userDTO == null) {
	SessionManager.removeSessionByID(session.getId(), false);
    } else {
	// this is set in SsoHandler
	// if user logs in from another browser, cache must not be flushed,
	// otherwise current authentication process fails
	Boolean noFlush = (Boolean) session.getAttribute(SsoHandler.NO_FLUSH_FLAG);
	if (!Boolean.TRUE.equals(noFlush)) {
	    String login = userDTO.getLogin();
	    Principal principal = new SimplePrincipal(login);
	    SessionListener.authenticationManager.flushCache(principal);

	    // remove obsolete mappings to session
	    // the session is either already invalidated or will be very soon by another module
	    SessionManager.removeSessionByLogin(login, false);
	}
    }
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:SessionListener.java

示例9: getEjb21Local

import javax.naming.InitialContext; //导入方法依赖的package包/类
public Ejb21Local getEjb21Local() {
	try {
		InitialContext jndiContext = new InitialContext();
		Ejb21LocalHome sessionHome = (Ejb21LocalHome) jndiContext.lookup("java:comp/env/injected1");
		return sessionHome.create();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:10,代码来源:BeanCallingOtherBeans.java

示例10: initialize

import javax.naming.InitialContext; //导入方法依赖的package包/类
/** Connect to the server, and lookup the managed resources. 
 * @throws JMSException */
public void initialize() throws NamingException {
	System.out.println("Getting the InitialContext");
	InitialContext context = new InitialContext();

	//lookup our JMS objects
	System.out.println("Looking up our JMS resources");
	queueCF = (QueueConnectionFactory) context.lookup(NOTIFICATION_QCF);
	queue = (Queue) context.lookup(NOTIFICATION_Q);

	initialized = true;
	System.out.println("Initialization completed successfully!");
}
 
开发者ID:IBMStockTrader,项目名称:loyalty-level,代码行数:15,代码来源:LoyaltyLevel.java

示例11: main

import javax.naming.InitialContext; //导入方法依赖的package包/类
public static void main(String[] args) throws NamingException {
	checkArgs(args);

	Properties p = new Properties();
	
	p.put(Context.INITIAL_CONTEXT_FACTORY, InitialContextFactory.class.getName());
	p.put(Context.PROVIDER_URL, "http-remoting://localhost:8080,http-remoting://localhost:8180");
	p.put(Context.SECURITY_PRINCIPAL, "user1");
	p.put(Context.SECURITY_CREDENTIALS, "user1+");
	p.put("jboss.naming.client.ejb.context", true);
	InitialContext ic = new InitialContext(p);
	
	final String lookup = "EAP71-PLAYGROUND-server/ejb/SimpleBean!" + Simple.class.getName();
	Simple proxy = (Simple) ic.lookup(lookup);
	log.fine("Proxy after lookup is : " + proxy);
	
	HashSet<String> serverList = new HashSet<>();

	log.info("Try to invoke SimpleBean with server @8080 @8180");
	try {
		for (int i = 0; i < 20; i++) {
			serverList.add(proxy.getJBossServerName());
			if(i == 0) log.fine("Proxy after first invocation is : " + proxy);
		}
	} catch (Exception e) {
		log.severe("Invocation failed! " + e.getMessage());
	}
	
	if(serverList.size() > 1) {
		log.info("Server should be part of a cluster as the invocation was executed on the following servers : " + serverList);
	}else if(serverList.size() == 1) {
		log.info("Server is not part of a cluster as the invocation was executed on a single server : " + new ArrayList<String>(serverList).get(0));
	}else{
		log.severe("No successfull invocation");
	}
}
 
开发者ID:wfink,项目名称:jboss-eap7.1-playground,代码行数:37,代码来源:LegacyMultipleServerRemoteNamingClient.java

示例12: getJmsConnectionFactory

import javax.naming.InitialContext; //导入方法依赖的package包/类
/**
 * Get the OSCM task queue factory
 * 
 * @param context
 *            a JNDI context
 * @return the task queue factory
 */
private ConnectionFactory getJmsConnectionFactory(InitialContext context) {
    try {
        Object lookup = context.lookup(JMS_QUEUE_FACTORY_JNDI_NAME);
        return ConnectionFactory.class.cast(lookup);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:SubscriptionAgent.java

示例13: findRMIServerJNDI

import javax.naming.InitialContext; //导入方法依赖的package包/类
/**
 * Lookup the RMIServer stub in a directory.
 * @param jndiURL A JNDI URL indicating the location of the Stub
 *                (see {@link javax.management.remote.rmi}), e.g.:
 *   <ul><li><tt>rmi://registry-host:port/rmi-stub-name</tt></li>
 *       <li>or <tt>iiop://cosnaming-host:port/iiop-stub-name</tt></li>
 *       <li>or <tt>ldap://ldap-host:port/java-container-dn</tt></li>
 *   </ul>
 * @param env the environment Map passed to the connector.
 * @param isIiop true if the stub is expected to be an IIOP stub.
 * @return The retrieved RMIServer stub.
 * @exception NamingException if the stub couldn't be found.
 **/
private RMIServer findRMIServerJNDI(String jndiURL, Map<String, ?> env,
        boolean isIiop)
        throws NamingException {

    InitialContext ctx = new InitialContext(EnvHelp.mapToHashtable(env));

    Object objref = ctx.lookup(jndiURL);
    ctx.close();

    if (isIiop)
        return narrowIIOPServer(objref);
    else
        return narrowJRMPServer(objref);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:RMIConnector.java

示例14: getDestination

import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected Topic getDestination(InitialContext ctx, String topicName) throws Exception
{
    return (Topic) ctx.lookup(topicName);
}
 
开发者ID:nuagenetworks,项目名称:jmsclient,代码行数:6,代码来源:JMSTopicClient.java

示例15: getConnectionFactory

import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected TopicConnectionFactory getConnectionFactory(InitialContext iniCtx) throws Exception
{
    return (TopicConnectionFactory) iniCtx.lookup(jmsRemoteFactory);
}
 
开发者ID:nuagenetworks,项目名称:jmsclient,代码行数:6,代码来源:JMSTopicClient.java


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