List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:gov.nih.nci.ess.safetyreporting.advquery.service.globus.resource.SafetyReportAdvancedQueryResourceBase.java
public SafetyReportAdvancedQueryResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/*from ww w. j a v a2 s. c o m*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/SafetyReportAdvancedQuery"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (SafetyReportAdvancedQueryResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:gov.nih.nci.ess.safetyreporting.notification.service.globus.resource.SafetyReportNotificationResourceBase.java
public SafetyReportNotificationResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/*from ww w .j a v a2 s .c o m*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/SafetyReportNotification"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (SafetyReportNotificationResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:gov.nih.nci.ess.safetyreporting.rules.service.globus.resource.SafetyReportRulesManagementResourceBase.java
public SafetyReportRulesManagementResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }//from w w w . j av a2 s . c om MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/SafetyReportRulesManagement"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (SafetyReportRulesManagementResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:gov.nih.nci.ess.safetyreporting.rdquery.service.globus.resource.SafetyReportDefinitionQueryResourceBase.java
public SafetyReportDefinitionQueryResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/*from ww w . j a v a 2s .co m*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/SafetyReportDefinitionQuery"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (SafetyReportDefinitionQueryResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:gov.nih.nci.ess.safetyreporting.ruleseval.service.globus.resource.SafetyReportRulesEvaluationResourceBase.java
public SafetyReportRulesEvaluationResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/*from w w w .j a va 2 s. c o m*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/SafetyReportRulesEvaluation"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (SafetyReportRulesEvaluationResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:gov.nih.nci.ess.safetyreporting.rdm.service.globus.resource.SafetyReportDefinitionManagementResourceBase.java
public SafetyReportDefinitionManagementResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/*w w w.j a v a2s .c o m*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/SafetyReportDefinitionManagement"; String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (SafetyReportDefinitionManagementResourceConfiguration) initialContext .lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:Util.java
/** * Lookup an object in the default initial context * // w ww . j a v a2s .com * @param name * the name to lookup * @param clazz * the expected type * @return the object * @throws Exception * for any error */ public static Object lookup(Name name, Class<?> clazz) throws Exception { InitialContext ctx = new InitialContext(); try { return lookup(ctx, name, clazz); } finally { ctx.close(); } }
From source file:com.boylesoftware.web.AbstractWebApplication.java
/** * Initialize the web-application. Called by the framework just before the * application is made available in the container. * * @throws UnavailableException If application cannot be initialized. * Throwing the exception makes the application fail to start. */// w ww .ja v a2s.co m void onRouterInit() throws UnavailableException { // get the log final Log log = LogFactory.getLog(AbstractWebApplication.class); log.debug("initializing the web-application"); // initialize the application boolean success = false; try { // create configuration log.debug("creating configuration"); this.configure(this.configProperties); // get the authenticator final ServletContext sc = this.servletContext; log.debug("creating authenticator"); this.services.setAuthenticationService(this.getAuthenticationService(sc, this)); // get validator factory log.debug("creating validator factory"); this.services.setValidatorFactory(this.getValidatorFactory(sc, this)); // get user locale finder log.debug("creating user locale finder"); this.services.setUserLocaleFinder(this.getUserLocaleFinder(sc, this)); // create entity manager factory log.debug("creating persistence manager factory"); this.services.setEntityManagerFactory(this.getEntityManagerFactory(sc, this)); // get JavaMail session from the JNDI log.debug("attempting to find JavaMail session in the JNDI"); try { final InitialContext jndi = new InitialContext(); try { this.services .setMailSession((Session) jndi.lookup(this.getConfigProperty(MAIL_SESSION_JNDI_NAME, String.class, ApplicationServices.DEFAULT_MAIL_SESSION_JNDI_NAME))); } catch (final NameNotFoundException e) { log.debug("no JavaMail session in the JNDI, JavaMail will" + " be unavailable", e); } } catch (final NamingException e) { log.error("Error accessing JNDI.", e); } // get the router configuration log.debug("creating routes configuration"); this.routerConfiguration = this.getRouterConfiguration(sc, this, this.services); // initialize custom application log.debug("initializing custom application"); this.init(); // get the executor service log.debug("creating request processing executor service"); this.executors = this.getExecutorService(sc, this); // done log.debug("initialized successfully"); success = true; } finally { if (!success) { log.debug("initialization error"); this.cleanup(); } } }
From source file:org.jboss.spring.support.SpringInjectionSupport.java
/** * @param jndiName the JNDI location of the Spring context relative to * 'java:' on JBoss AS5 and JBoss AS6 and 'java:jboss' on JBoss AS7 * @param expectedClass the expected type of the retrieved object * @return// ww w .j a v a2 s. co m */ private <T> T lookup(String jndiName, Class<T> expectedClass) { Object instance; try { InitialContext initialContext = new InitialContext(); instance = initialContext.lookup(jndiName); if (!(expectedClass.isAssignableFrom(instance.getClass()))) { throw new IllegalArgumentException("Cannot retrieve an " + expectedClass.getName() + " from " + jndiName + " - a " + instance.getClass().getName() + " found instead"); } } catch (NamingException e) { throw new IllegalStateException(e); } return expectedClass.cast(instance); }
From source file:com.googlecode.psiprobe.beans.ResourceResolverBean.java
public synchronized boolean resetResource(final Context context, String resourceName, ContainerWrapperBean containerWrapper) throws NamingException { if (context != null) { ((AbstractTomcatContainer) containerWrapper.getTomcatContainer()).bindToContext(context); }//from ww w . j a v a 2s.c o m try { javax.naming.Context ctx = (context != null) ? new InitialContext() : getGlobalNamingContext(); String jndiName = resolveJndiName(resourceName, (context == null)); Object o = ctx.lookup(jndiName); try { for (Iterator it = datasourceMappers.iterator(); it.hasNext();) { DatasourceAccessor accessor = (DatasourceAccessor) it.next(); if (accessor.reset(o)) { return true; } } return false; } catch (Throwable e) { // // make sure we always re-throw ThreadDeath // if (e instanceof ThreadDeath) { throw (ThreadDeath) e; } return false; } } finally { if (context != null) { ((AbstractTomcatContainer) containerWrapper.getTomcatContainer()).unbindFromContext(context); } } }