本文整理汇总了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();
}
}
示例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();
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
示例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();
}
示例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);
}
}
}
}
示例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!");
}
示例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");
}
}
示例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;
}
}
示例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);
}
示例14: getDestination
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected Topic getDestination(InitialContext ctx, String topicName) throws Exception
{
return (Topic) ctx.lookup(topicName);
}
示例15: getConnectionFactory
import javax.naming.InitialContext; //导入方法依赖的package包/类
@Override
protected TopicConnectionFactory getConnectionFactory(InitialContext iniCtx) throws Exception
{
return (TopicConnectionFactory) iniCtx.lookup(jmsRemoteFactory);
}