Java Code Examples for javax.naming.InitialContext#doLookup()

The following examples show how to use javax.naming.InitialContext#doLookup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractParseBpmPlatformXmlStep.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public URL lookupBpmPlatformXmlLocationFromJndi() {
  String jndi = "java:comp/env/" + BPM_PLATFORM_XML_LOCATION;

  try {
    String bpmPlatformXmlLocation = InitialContext.doLookup(jndi);

    URL fileLocation = checkValidBpmPlatformXmlResourceLocation(bpmPlatformXmlLocation);

    if (fileLocation != null) {
      LOG.foundConfigJndi(jndi, fileLocation.toString());
    }

    return fileLocation;
  }
  catch (NamingException e) {
    LOG.debugExceptionWhileGettingConfigFromJndi(jndi, e);
    return null;
  }
}
 
Example 2
Source File: GameRound.java    From liberty-bikes with Eclipse Public License 1.0 6 votes vote down vote up
private synchronized void getKeyStoreInfo() throws IOException {
    if (signingKey != null)
        return;
    try {
        // load up the keystore

        keyStore = InitialContext.doLookup("jwtKeyStore");
        keyStorePW = InitialContext.doLookup("jwtKeyStorePassword");
        keyStoreAlias = InitialContext.doLookup("jwtKeyStoreAlias");

        FileInputStream is = new FileInputStream(keyStore);

        KeyStore signingKeystore = KeyStore.getInstance(KeyStore.getDefaultType());
        signingKeystore.load(is, keyStorePW.toCharArray());
        signingKey = signingKeystore.getKey(keyStoreAlias, keyStorePW.toCharArray());
    } catch (Exception e) {
        throw new IOException(e);
    }

}
 
Example 3
Source File: ExecutorFacade.java    From HttpSessionReplacer with MIT License 6 votes vote down vote up
/**
 * Default constructor
 *
 * @param conf
 *          namespace for metrics
 */
public ExecutorFacade(SessionConfiguration conf) {
  ThreadFactory tf;
  count = new AtomicLong(0);
  this.namespace = conf.getNamespace();
  String threadFactoryJndi = conf.getAttribute(THREAD_JNDI, "java:comp/DefaultManagedThreadFactory");
  try {
    // Try to get JEE 6 managed thread factory,
    // and if not available, fall back to built-in default one.
    tf = InitialContext.doLookup(threadFactoryJndi);
  } catch (NamingException e) {
    logger.warn("Unable to use ManagedThreadFactory from JNDI {}, using built-in thread pool. Cause: '{}'. "
        + "Activate debug tracing for more information.", threadFactoryJndi, e.getMessage());
    logger.debug("Unable to use ManagedThreadFactory from JNDI, stack trace follows. ", e);
    tf = Executors.defaultThreadFactory();
  }
  baseThreadFactory = tf;
  int queueSize = Integer.parseInt(conf.getAttribute(WORK_QUEUE_SIZE, MAXIMUM_WORK_QUEUE_SIZE));
  ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(queueSize);
  executor = new ThreadPoolExecutor(CORE_THREADS_IN_POOL, MAXIMUM_THREADS_IN_POOL, THREAD_KEEPALIVE_TIME, SECONDS,
      workQueue, this, new ThreadPoolExecutor.CallerRunsPolicy());
  scheduledExecutor = new ScheduledThreadPoolExecutor(SCHEDULER_THREADS_IN_POOL, this, new DiscardAndLog());
}
 
Example 4
Source File: JndiTest.java    From jqm with Apache License 2.0 5 votes vote down vote up
@Test
public void testJndiServerName() throws Exception
{
    addAndStartEngine();

    String s = (String) InitialContext.doLookup("serverName");
    Assert.assertEquals("localhost", s);
}
 
Example 5
Source File: PolicyManagementDAOUtil.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) {
    try {
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.doLookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}
 
Example 6
Source File: CertificateMgtDaoTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private static void initializeDatabase(String configFilePath) throws IOException, XMLStreamException, NamingException {

        InputStream in;
        in = FileUtils.openInputStream(new File(configFilePath));
        StAXOMBuilder builder = new StAXOMBuilder(in);
        String dataSource = builder.getDocumentElement().getFirstChildWithName(new QName("DataSourceName"))
                .getText();
        OMElement databaseElement = builder.getDocumentElement()
                .getFirstChildWithName(new QName("Database"));
        String databaseURL = databaseElement.getFirstChildWithName(new QName("URL")).getText();
        String databaseUser = databaseElement.getFirstChildWithName(new QName("Username")).getText();
        String databasePass = databaseElement.getFirstChildWithName(new QName("Password")).getText();
        String databaseDriver = databaseElement.getFirstChildWithName(new QName("Driver")).getText();

        BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setDriverClassName(databaseDriver);
        basicDataSource.setUrl(databaseURL);
        basicDataSource.setUsername(databaseUser);
        basicDataSource.setPassword(databasePass);

        // Create initial context
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.naming.java.javaURLContextFactory");
        System.setProperty(Context.URL_PKG_PREFIXES,
                "org.apache.naming");
        try {
            InitialContext.doLookup("java:/comp/env/jdbc/WSO2AM_DB");
        } catch (NamingException e) {
            InitialContext ic = new InitialContext();
            ic.createSubcontext("java:");
            ic.createSubcontext("java:/comp");
            ic.createSubcontext("java:/comp/env");
            ic.createSubcontext("java:/comp/env/jdbc");

            ic.bind("java:/comp/env/jdbc/WSO2AM_DB", basicDataSource);
        }
    }
 
Example 7
Source File: NotificationDAOUtil.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static DataSource lookupDataSource(String dataSourceName,
                                          final Hashtable<Object, Object> jndiProperties) {
	try {
		if (jndiProperties == null || jndiProperties.isEmpty()) {
			return (DataSource) InitialContext.doLookup(dataSourceName);
		}
		final InitialContext context = new InitialContext(jndiProperties);
		return (DataSource) context.lookup(dataSourceName);
	} catch (Exception e) {
		throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
	}
}
 
Example 8
Source File: DeviceManagementDAOUtil.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static DataSource lookupDataSource(String dataSourceName,
                                          final Hashtable<Object, Object> jndiProperties) {
    try {
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.lookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}
 
Example 9
Source File: CertificateManagementDAOUtil.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) {
    try {
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.doLookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}
 
Example 10
Source File: CertificateManagementDAOUtil.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) {
    try {
        if (jndiProperties == null || jndiProperties.isEmpty()) {
            return (DataSource) InitialContext.doLookup(dataSourceName);
        }
        final InitialContext context = new InitialContext(jndiProperties);
        return (DataSource) context.doLookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}
 
Example 11
Source File: DbUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
public static DataSource getProarcSource() throws NamingException {
    DataSource source = InitialContext.doLookup("java:/comp/env/jdbc/proarc");
    if (source == null) {
        throw new IllegalStateException("Cannot find 'jdbc/proarc' resource!");
    }
    return source;
}
 
Example 12
Source File: GreeterResource.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@GET
public String hello(@QueryParam("name") String name, @Context HttpServletRequest request) throws NamingException {
    HttpSession session = request.getSession();
    GreeterService greeter = (GreeterService) session.getAttribute(GreeterService.class.getName());
    if (greeter == null) {
        greeter = InitialContext.doLookup("java:module/" + GreeterService.class.getSimpleName());
        session.setAttribute(GreeterService.class.getName(), greeter);
    }

    return simpleService.yay() + greeter.hello(name);
}
 
Example 13
Source File: GameMap.java    From liberty-bikes with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param map -1=random, 0=empty, >0=specific map
 */
public static GameMap create(int map) {
    try {
        int mapOverride = InitialContext.doLookup("round/map");
        if (mapOverride >= 0 && mapOverride <= NUM_MAPS) {
            map = mapOverride;
            System.out.println("Overriding map selection to map #" + map);
        }
    } catch (Exception ignore) {
    }

    switch (map) {
        case -1:
            return create(r.nextInt(NUM_MAPS) + 1);
        case 0:
            return new EmptyMap();
        case 1:
            return new OriginalMap();
        case 2:
            return new CrossSlice();
        case 3:
            return new FakeBlock();
        case 4:
            return new Smile();
        case 5:
            return new HulkSmash();
        default:
            throw new IllegalArgumentException("Illegal map number: " + map);
    }
}
 
Example 14
Source File: GameRound.java    From liberty-bikes with Eclipse Public License 1.0 5 votes vote down vote up
private ManagedScheduledExecutorService executor() {
    try {
        return InitialContext.doLookup("java:comp/DefaultManagedScheduledExecutorService");
    } catch (NamingException e) {
        log("Unable to obtain ManagedScheduledExecutorService");
        e.printStackTrace();
        return null;
    }
}
 
Example 15
Source File: ManagedTransaction.java    From requery with Apache License 2.0 5 votes vote down vote up
private UserTransaction getUserTransaction() {
    if (userTransaction == null) {
        try {
            userTransaction = InitialContext.doLookup("java:comp/UserTransaction");
        } catch (NamingException e) {
            throw new TransactionException(e);
        }
    }
    return userTransaction;
}
 
Example 16
Source File: ExecuteSqlWorkItemHandler.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
public ExecuteSqlWorkItemHandler(String dataSourceName) {
    try {
        this.ds = InitialContext.doLookup(dataSourceName);
    } catch (NamingException e) {
        throw new RuntimeException("Unable to look up data source: " + dataSourceName + " - " + e.getMessage());
    }
}
 
Example 17
Source File: DatabaseUtil.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static DataSource lookupDataSource(String dataSourceName) {
    try {
        return (DataSource) InitialContext.doLookup(dataSourceName);
    } catch (Exception e) {
        throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
    }
}
 
Example 18
Source File: PersistentPlayerDB.java    From liberty-bikes with Eclipse Public License 1.0 4 votes vote down vote up
public PersistentPlayerDB() throws NamingException {
    ds = InitialContext.doLookup("java:comp/DefaultDataSource");
}
 
Example 19
Source File: HeatProcessor.java    From development with Apache License 2.0 4 votes vote down vote up
/**
 * Protected method for unit test purposes.
 */
protected APPTemplateService getTemplateService() throws NamingException {
    return InitialContext.doLookup(APPTemplateService.JNDI_NAME);
}
 
Example 20
Source File: TestProcessEngineJndiBinding_JBOSS.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
@Test
public void testDefaultProcessEngineBindingCreated() {
  
  try {
    ProcessEngine processEngine = InitialContext.doLookup("java:global/camunda-bpm-platform/process-engine/default");
    Assert.assertNotNull("Process engine must not be null", processEngine);
    
  } catch(Exception e) {
    Assert.fail("Process Engine not bound in JNDI.");
    
  }
      
}