List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:edu.umn.msi.tropix.storage.service.impl.UploadTransferServiceContextFactory.java
/** * This method is nearly identical to TransferServiceHelper.createTransferContext(DataDescriptor, DataStagedCallback) but makes sure the resource objects do not expire until after the corresponding context has been terminated. * /*from w ww .j a v a2s . c o m*/ * @param dd * @param callback * @return * @throws RemoteException */ public static TransferServiceContextReference createTransferContext(final DataDescriptor dd, final DataStagedCallback callback) throws RemoteException { EndpointReferenceType epr = null; // new org.apache.axis.message.addressing.EndpointReferenceType(); - created object was never used final String homeName = "java:comp/env/services/cagrid/TransferServiceContext/home"; try { final Context initialContext = new InitialContext(); final TransferServiceContextResourceHome home = (TransferServiceContextResourceHome) initialContext .lookup(homeName); final ResourceKey resourceKey = home.createResource(); // Grab the newly created resource final TransferServiceContextResource thisResource = (TransferServiceContextResource) home .find(resourceKey); thisResource.setSecurityDescriptor(SecurityUtils.createCreatorOnlyResourceSecurityDescriptor()); LOG.debug("Calling stage on resource with callback " + callback); thisResource.stage(dd, callback); String transportURL = (String) MessageContext.getCurrentContext() .getProperty(org.apache.axis.MessageContext.TRANS_URL); transportURL = transportURL.substring(0, transportURL.lastIndexOf('/') + 1); transportURL += "TransferServiceContext"; epr = AddressingUtils.createEndpointReference(transportURL, resourceKey); storeReference(thisResource); } catch (final Exception e) { throw new RemoteException("Error looking up TransferServiceContext home:" + e.getMessage(), e); } // return the typed EPR final TransferServiceContextReference ref = new TransferServiceContextReference(); ref.setEndpointReference(epr); LOG.debug("Returning ref"); return ref; }
From source file:eu.europa.ec.fisheries.uvms.plugins.ais.service.AisService.java
@PostConstruct public void init() { try {/*from w w w .ja va2 s. c o m*/ Context ctx = new InitialContext(); AISConnectionFactoryImpl factory = (AISConnectionFactoryImpl) ctx .lookup("java:/eis/AISConnectionFactory"); if (factory != null) { LOG.debug("Factory lookup done! {}, {}", factory.toString(), factory.getClass()); connection = factory.getConnection(); if (startUp.isEnabled() && connection != null && !connection.isOpen()) { String host = startUp.getSetting("HOST"); int port = Integer.parseInt(startUp.getSetting("PORT")); String username = startUp.getSetting("USERNAME"); String password = startUp.getSetting("PASSWORD"); connection.open(host, port, username, password); } } } catch (NamingException | ResourceException e) { LOG.error("Exception: {}", e); } }
From source file:net.sf.jasperreports.data.jndi.JndiDataAdapterService.java
@Override public void contributeParameters(Map<String, Object> parameters) throws JRException { JndiDataAdapter jndiDataAdapter = getJndiDataAdapter(); if (jndiDataAdapter != null) { try {/*from ww w .j a v a 2 s.c om*/ Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx .lookup("java:comp/env/" + jndiDataAdapter.getDataSourceName()); connection = dataSource.getConnection(); } catch (Exception ex) { throw new JRException(ex); } parameters.put(JRParameter.REPORT_CONNECTION, connection); } }
From source file:m.dekmak.Database.java
public String getContextValue(String param) throws NamingException { // Get the base naming context Context env = (Context) new InitialContext().lookup("java:comp/env"); // Get a single value String dbhost = (String) env.lookup(param); return dbhost; }
From source file:de.griffel.confluence.plugins.plantuml.DatasourceHelper.java
/** * Returns DataSource for given data source name. * * @param name Name of data source as returned by listAvailableDataSources * @return DataSource if name exists, otherwise null *//*from w w w . j ava2 s.co m*/ public static DataSource getDatasource(String name) { final ClassLoader origCL = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(ComponentManager.class.getClassLoader()); final InitialContext jndiContext = new InitialContext(); return (javax.sql.DataSource) jndiContext.lookup(JDBC_CONTEXT + "/" + name); } catch (NamingException e) { log.debug("NamingException lookup", e); return null; } finally { Thread.currentThread().setContextClassLoader(origCL); } }
From source file:com.janrain.backplane.server.config.InitSystemProps.java
private void load(String paramName) { String result = System.getProperty(paramName); if (StringUtils.isBlank(result)) { try {// w w w .ja va2 s. co m javax.naming.Context initCtx = new InitialContext(); result = (String) initCtx.lookup("java:comp/env/" + paramName); System.setProperty(paramName, result); logger.info("Parameter " + paramName + " fetched from context and inserted as system property"); } catch (Exception e) { //continue logger.info("An error occurred trying to locate required parameter " + paramName + " => " + e.getMessage()); } } else { logger.info("Parameter " + paramName + " exists as a system property"); } }
From source file:com.manydesigns.portofino.model.database.JndiConnectionProvider.java
public DataSource getDataSource() throws Exception { InitialContext ic = new InitialContext(); return (DataSource) ic.lookup(jndiResource); }
From source file:com.duroty.task.InitServerTask.java
/** * Creates a new InitServerTask object./* w ww . j a va 2 s . c o m*/ * * @param poolSize DOCUMENT ME! * @throws NamingException * * @throws ClassNotFoundException DOCUMENT ME! * @throws NamingException DOCUMENT ME! * @throws IOException * @throws InstantiationException DOCUMENT ME! * @throws IllegalAccessException DOCUMENT ME! * @throws IOException DOCUMENT ME! */ public InitServerTask(String hibernateSessionFactory) throws NamingException, IOException { super(); ctx = new InitialContext(); this.hibernateSessionFactory = hibernateSessionFactory; String tempDir = System.getProperty("java.io.tmpdir"); if (!tempDir.endsWith(File.separator)) { tempDir = tempDir + File.separator; } FileUtilities.deleteMotLocks(new File(tempDir)); FileUtilities.deleteLuceneLocks(new File(tempDir)); }
From source file:com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean.java
protected Object createInstance() throws Exception { Properties properties = PropsUtil.getProperties(_propertyPrefix, true); String jndiName = properties.getProperty("jndi.name"); if (Validator.isNotNull(jndiName)) { try {/*from ww w. j a v a2 s .c o m*/ return JNDIUtil.lookup(new InitialContext(), jndiName); } catch (Exception e) { _log.error("Unable to lookup " + jndiName, e); } } DataSource dataSource = new ComboPooledDataSource(); Enumeration<String> enu = (Enumeration<String>) properties.propertyNames(); while (enu.hasMoreElements()) { String key = enu.nextElement(); String value = properties.getProperty(key); // Map org.apache.commons.dbcp.BasicDataSource to C3PO if (key.equalsIgnoreCase("driverClassName")) { key = "driverClass"; } else if (key.equalsIgnoreCase("url")) { key = "jdbcUrl"; } else if (key.equalsIgnoreCase("username")) { key = "user"; } BeanUtils.setProperty(dataSource, key, value); } if (_log.isDebugEnabled()) { SortedProperties sortedProperties = new SortedProperties(properties); _log.debug("Properties for prefix " + _propertyPrefix); sortedProperties.list(System.out); } return dataSource; }
From source file:com.dattack.naming.StandaloneJndiTest.java
@Test public void testCreateContext() { try {//from w w w . ja va 2 s. c om final InitialContext context = new InitialContext(); final String name = "testCreateContext"; final Context subcontext = context.createSubcontext(name); assertNotNull(subcontext); } catch (final NamingException e) { fail(e.getMessage()); } }