List of usage examples for javax.naming InitialContext lookup
public Object lookup(Name name) throws NamingException
From source file:org.firstopen.singularity.cep.RuleService.java
/** * Subscribe with a local JMX service uri * //from w w w.j av a 2 s. co m */ protected void subscribeALE() { InitialContext jndiContext; try { jndiContext = JNDIUtil.getInitialContext(); AleSLSBHome aHome = (AleSLSBHome) jndiContext.lookup("ejb/ale/AleSLSB"); AleSLSBRemote aSLSB = aHome.create(); Set<String> ecSpecList = ruleBaseList.getAllECSpecs(); for (Iterator iter = ecSpecList.iterator(); iter.hasNext();) { String element = (String) iter.next(); aSLSB.subscribe(element, "jmx://localhost/" + serviceName); } // end for all ecSpecs } catch (Exception e) { log.error(e); throw new InfrastructureException(e); } }
From source file:org.geowebcache.diskquota.jdbc.JDBCQuotaStoreFactory.java
private DataSource getDataSource(JDBCConfiguration config) throws ConfigurationException { try {//from w ww . j a v a2 s . c o m DataSource ds = null; if (config.getJNDISource() != null) { InitialContext context = new InitialContext(); ds = (DataSource) context.lookup(config.getJNDISource()); } else if (config.getConnectionPool() != null) { ConnectionPoolConfiguration cp = config.getConnectionPool(); BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(cp.getDriver()); bds.setUrl(cp.getUrl()); bds.setUsername(cp.getUsername()); bds.setPassword(cp.getPassword()); bds.setPoolPreparedStatements(true); bds.setMaxOpenPreparedStatements(cp.getMaxOpenPreparedStatements()); bds.setMinIdle(cp.getMinConnections()); bds.setMaxActive(cp.getMaxConnections()); bds.setMaxWait(cp.getConnectionTimeout() * 1000); bds.setValidationQuery(cp.getValidationQuery()); ds = bds; } // verify the datasource works Connection c = null; try { c = ds.getConnection(); } catch (SQLException e) { throw new ConfigurationException("Failed to get a database connection: " + e.getMessage(), e); } finally { if (c != null) { try { c.close(); } catch (SQLException e) { // nothing we can do about it, but at least let the admin know log.debug("An error occurred while closing the test JDBC connection: " + e.getMessage(), e); } } } return ds; } catch (NamingException e) { throw new ConfigurationException("Failed to locate the data source in JNDI", e); } }
From source file:endpoint.protocol.jms.JMSBrokerController.java
public JMSBrokerController(String providerURL, Properties properties) { this.providerURL = providerURL; InitialContext ctx; try {/* w ww.ja v a2s .c o m*/ ctx = new InitialContext(properties); this.connectionFactory = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory"); } catch (NamingException e) { log.info("Error while creating connection factory"); } }
From source file:org.apache.stratos.autoscaler.integration.TopicPublisher.java
public void connect() throws NamingException, JMSException, IOException { // Prepare JNDI properties Properties properties = new Properties(); properties.put("java.naming.provider.url", "tcp://localhost:61616"); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); properties.put("connectionfactoryName", "ConnectionFactory"); properties.put("java.naming.security.principal", "admin"); properties.put("java.naming.security.credentials", "admin"); InitialContext ctx = new InitialContext(properties); // Lookup connection factory String connectionFactoryName = properties.get("connectionfactoryName").toString(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) ctx.lookup(connectionFactoryName); topicConnection = connectionFactory.createTopicConnection(); topicConnection.start();/*from w w w. j av a2s . c o m*/ topicSession = topicConnection.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE); // Create topic topic = topicSession.createTopic(topicName); }
From source file:eu.uqasar.util.UQasarUtil.java
/** * //from ww w . jav a 2s .com * @param node Node whose value is studied * @return */ private static Multimap<SuggestionType, Object> getSuggestionForNode(TreeNode node) { // For storing the suggestion type and the payload Multimap<SuggestionType, Object> suggestionsMultimap = ArrayListMultimap.create(); final String EMPTY = ""; try { InitialContext ic = new InitialContext(); ProjectSimilarityService projectSimilarityService = (ProjectSimilarityService) ic .lookup("java:module/ProjectSimilarityService"); QualityObjectiveSimilarityService qoSimilarityService = (QualityObjectiveSimilarityService) ic .lookup("java:module/QualityObjectiveSimilarityService"); //TODO: Finding similar metrics if (node instanceof QualityObjective) { QualityObjective qo = (QualityObjective) node; Float value = qo.getValue(); // If the value of a quality objective cannot be computed, // attempt to obtain a suggestion if (value == null || value.isNaN()) { // Attempt to find a suitable project Project proj = qo.getProject(); Project similarProject = null; if (proj != null) { // Get a list of similar projects List<Project> similarProjects = projectSimilarityService.getSimilarProjects(proj); if (similarProjects != null && similarProjects.size() > 0) { // For now obtain the first suitable project similarProject = similarProjects.get(0); } } // If a suitable similar project was found, search for similar Quality Objective(s) to be suggested if (similarProject != null) { // Get similar QOs from a similar project List<QualityObjective> qos = qoSimilarityService.getSimilarQOs(qo, similarProject); // If results were found, construct a suggestion (for now obtain the first one). if (qos != null && qos.size() > 0) { suggestionsMultimap.put(SuggestionType.QO_REPLACE, qos.get(0)); return suggestionsMultimap; } } // Otherwise suggest the QO to be removed suggestionsMultimap.put(SuggestionType.QO_REMOVE, null); return suggestionsMultimap; } } // if a metric has no value / the value is 0, return a suggestion to // remove the metric if (node instanceof Metric) { Metric metric = (Metric) node; Float value = metric.getValue(); if (value == null || value.isNaN() || value.isInfinite()) { suggestionsMultimap.put(SuggestionType.METRIC_REMOVE, null); return suggestionsMultimap; } } } catch (NamingException e) { e.printStackTrace(); } // If no suggestion is to be provided, return an empty string // (overwrite the possible existing suggestion). suggestionsMultimap.put(SuggestionType.NO_SUGGESTION, ""); return suggestionsMultimap; }
From source file:org.nuxeo.ecm.platform.io.test.TestIORemoteCopy.java
@Before public void setUp() throws Exception { System.setProperty("org.nuxeo.runtime.streaming.isServer", "false"); System.setProperty("org.nuxeo.runtime.server.port", "62475"); System.setProperty("org.nuxeo.runtime.server.host", "localhost"); System.setProperty("org.nuxeo.runtime.streaming.serverLocator", STREAM_SERVER_URL); super.setUp(); // the core bundle deployContrib("org.nuxeo.ecm.core", "OSGI-INF/CoreService.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "TypeService.xml"); deployContrib("org.nuxeo.ecm.core", "OSGI-INF/SecurityService.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "RepositoryService.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "test-CoreExtensions.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "CoreEventListenerService.xml"); // repo test case misc deployContrib("org.nuxeo.ecm.platform.io.core.tests", "DefaultPlatform.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "RepositoryManager.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "LifeCycleCoreExtensions.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "LifeCycleService.xml"); // specific files deployContrib("org.nuxeo.ecm.platform.io.core.tests", "io-test-framework.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "io-test-contrib.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "RemotingService.xml"); deployContrib("org.nuxeo.ecm.platform.io.core.tests", "JBossLoginConfig.xml"); // donnot : deployContrib("StreamingServer.xml"); deployBundle("org.nuxeo.ecm.relations.api"); deployBundle("org.nuxeo.ecm.relations"); deployBundle("org.nuxeo.ecm.relations.jena"); deployBundle("org.nuxeo.ecm.platform.comment.api"); deployBundle("org.nuxeo.ecm.platform.comment"); InitialContext ctx1 = new InitialContext(); System.err.println(ctx1.lookup("java:/comment-relations")); NamingEnumeration<NameClassPair> en = ctx1.list("/"); while (en.hasMore()) { Object o = en.nextElement(); System.err.println(o);//from ww w.j av a 2s. c om } deployContrib("org.nuxeo.ecm.platform.io.core.tests", "commentService-config-bundle.xml"); Map<String, Serializable> ctx = new HashMap<String, Serializable>(); ctx.put("username", SecurityConstants.ADMINISTRATOR); coreSession = CoreInstance.getInstance().open(localRepositoryName, ctx); ioService = Framework.getService(IOManager.class); }
From source file:Employee.java
@PostConstruct public void jndiInject(InvocationContext invocation) { Object target = invocation.getTarget(); Field[] fields = target.getClass().getDeclaredFields(); Method[] methods = target.getClass().getDeclaredMethods(); // find all @JndiInjected fields methods and set them try {/*from w ww . j a va 2 s . c o m*/ InitialContext ctx = new InitialContext(); for (Method method : methods) { JndiInjected inject = method.getAnnotation(JndiInjected.class); if (inject != null) { Object obj = ctx.lookup(inject.value()); method.setAccessible(true); method.invoke(target, obj); } } for (Field field : fields) { JndiInjected inject = field.getAnnotation(JndiInjected.class); if (inject != null) { Object obj = ctx.lookup(inject.value()); field.setAccessible(true); field.set(target, obj); } } invocation.proceed(); } catch (Exception ex) { throw new EJBException("Failed to execute @JndiInjected", ex); } }
From source file:org.jboss.test.security.test.SubjectContextUnitTestCase.java
public void testUnprotectedEjbMethod() throws Exception { log.debug("+++ testUnprotectedEjbMethod()"); SecurityAssociation.clear();//from w w w. j a va2 s . co m InitialContext ctx = new InitialContext(); Object obj = ctx.lookup("jacc/Secured"); obj = PortableRemoteObject.narrow(obj, SecuredServiceRemoteHome.class); SecuredServiceRemoteHome home = (SecuredServiceRemoteHome) obj; log.debug("Found SecuredServiceRemoteHome"); SecuredServiceRemote bean = home.create(); log.debug("Created SecuredServiceRemote"); Principal callerIdentity = new SimplePrincipal("guest"); Principal runAsIdentity = new SimplePrincipal("runAsUser"); HashSet expectedCallerRoles = new HashSet(); HashSet expectedRunAsRoles = new HashSet(); expectedRunAsRoles.add("identitySubstitutionCaller"); expectedRunAsRoles.add("extraRunAsRole"); CallerInfo info = new CallerInfo(callerIdentity, runAsIdentity, expectedCallerRoles, expectedRunAsRoles); bean.unprotectedEjbMethod(info); bean.remove(); }
From source file:org.tolven.rs.UserResources.java
protected LdapLocal getLdapBean() { if (ldapBean == null) { String jndiName = "java:app/gatekeeperEJB/LdapBean!org.tolven.gatekeeper.LdapLocal"; try {/*from w ww .j a v a2 s .c om*/ InitialContext ctx = new InitialContext(); ldapBean = (LdapLocal) ctx.lookup(jndiName); } catch (Exception ex) { throw new RuntimeException("Could not lookup " + jndiName); } } return ldapBean; }
From source file:com.dattack.naming.StandaloneJndiTest.java
@Test public void testBind() { try {//from ww w .j a v a 2 s . c o m final InitialContext context = new InitialContext(); final String name = getCompositeName("jdbc", "testBind"); final Object obj = new Integer(10); context.bind(name, obj); assertEquals(obj, context.lookup(name)); } catch (final NamingException e) { fail(e.getMessage()); } }