Java 8 InitialContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 InitialContext class.

This code example shows how to use the following methods:
 */ 
 
public class JNDIUtil { 
   
  public static Context getInitialContext() throws NamingException {
    return new InitialContext();
  } 
 
  public static String lookup(Context ctx, String name) {
    if (ctx == null) {
      return null; 
    } 
    try { 
      Object lookup = ctx.lookup(name);
      return lookup == null ? null : lookup.toString(); 
    } catch (NamingException e) {
      return null; 
    } 
  } 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	public void testTransactions() throws Exception {
	    createRuntimeManager("humantask.bpmn"); 
	    RuntimeEngine runtimeEngine = getRuntimeEngine();
	    KieSession ksession = runtimeEngine.getKieSession();
		 
		UserTransaction ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
        ut.begin();
		ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
		ut.rollback();
 
		assertNull(ksession.getProcessInstance(processInstance.getId()));
	} 
	 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        createRuntimeManager("humantask.bpmn"); 
        RuntimeEngine runtimeEngine = getRuntimeEngine();
        KieSession ksession = runtimeEngine.getKieSession();
        TaskService taskService = runtimeEngine.getTaskService();
 
        UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
        ut.begin();
        ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
        ut.rollback();
 
        assertNull(ksession.getProcessInstance(processInstance.getId()));
        List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
        assertEquals(0, list.size());
    } 
 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:lookup
    public void init(ServletConfig config) throws ServletException
    { 
        super.init(config);
        try 
        { 
            InitialContext ic = new InitialContext();
            woggle = (Integer)ic.lookup("java:comp/env/woggle");
            envEntryGlobalScopeResult = "EnvEntry defined in context xml lookup result (java:comp/env/woggle): "+(woggle==4000?"<span class=\"pass\">PASS":"<span class=\"fail\">FAIL(expected 4000, got "+woggle+")")+"</span>";
            gargle = (Double)ic.lookup("java:comp/env/gargle");
            envEntryWebAppScopeResult = "EnvEntry defined in jetty-env.xml lookup result (java:comp/env/gargle): "+(gargle==100.0?"<span class=\"pass\">PASS":"<span class=\"fail\">FAIL(expected 100, got "+gargle+")")+"</span>";
            UserTransaction utx = (UserTransaction)ic.lookup("java:comp/UserTransaction");
            userTransactionResult = "UserTransaction lookup result (java:comp/UserTransaction): "+(utx!=null?"<span class=\"pass\">PASS":"<span class=\"fail\">FAIL")+"</span>";
            myMailSession = (Session)ic.lookup("java:comp/env/mail/Session");
            mailSessionResult = "Mail Session lookup result (java:comp/env/mail/Session): "+(myMailSession!=null?"<span class=\"pass\">PASS": "<span class=\"fail\">FAIL")+"</span>";
        } 
        catch (Exception e)
        { 
            throw new ServletException(e);
        } 
    } 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:lookup
	} 
 
	@Override 
	public Object locate(String jndiName) {
		InitialContext initialContext = buildInitialContext();
		Name name = parseName( jndiName, initialContext );
		try { 
			return initialContext.lookup( name );
		} 
		catch ( NamingException e ) {
			throw new JndiException( "Unable to lookup JNDI name [" + jndiName + "]", e );
		} 
		finally { 
			cleanUp( initialContext );
		} 
	} 
 
	private InitialContext buildInitialContext() {
		try { 
			return initialContextSettings.size() == 0 ? new InitialContext() : new InitialContext( initialContextSettings );

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:createSubcontext, destroySubcontext, getNameInNamespace, getNameParser, lookup
public class TestMailSessionReference 
{ 
    @Test
    public void testMailSessionReference () throws ExceptionInitialContext icontext = new InitialContext();
        MailSessionReference sref = new MailSessionReference();
        sref.setUser("janb");
        sref.setPassword("OBF:1xmk1w261z0f1w1c1xmq");
        Properties props = new Properties ();
        props.put("mail.smtp.host", "xxx");
        props.put("mail.debug", "true");
        sref.setProperties(props);
        NamingUtil.bind(icontext, "mail/Session", sref);
        Object x = icontext.lookup("mail/Session");
        assertNotNull(x); 
        assertTrue(x instanceof javax.mail.Session); 
        javax.mail.Session session = (javax.mail.Session)x;
        Properties sessionProps =  session.getProperties();
        assertEquals(props, sessionProps);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:bind, createSubcontext, lookup
        env1.put("make", "holden");
        env1.put("model", "commodore");
 
        Object car1 = new Object(); 
 
        InitialContext ic = new InitialContext(env1);
        ic.bind("car1", car1);
        assertNotNull(ic.lookup("car1"));
        assertEquals(car1, ic.lookup("car1"));
 
        Context carz = ic.createSubcontext("carz");
        assertNotNull(carz);
        Hashtable ht = carz.getEnvironment();
        assertNotNull(ht);
        assertEquals("holden", ht.get("make"));
        assertEquals("commodore", ht.get("model"));
 
        Hashtable<String,String> env2 = new Hashtable<String,String>();
        env2.put("flavour", "strawberry");
        InitialContext ic2 = new InitialContext(env2);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, lookup
   *           if a JNDI error occurs 
   */ 
  public static DataSource lookupDataSource(String dataSourceName) throws TasteException {
    Context context = null;
    try { 
      context = new InitialContext();
      return (DataSource) context.lookup("java:comp/env/" + dataSourceName);
    } catch (NamingException ne) {
      throw new TasteException(ne);
    } finally { 
      if (context != null) {
        try { 
          context.close();
        } catch (NamingException ne) {
          log.warn("Error while closing Context; continuing...", ne);
        } 
      } 
    } 
  } 
   
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
    // addInfo("Getting initial context."); 
    if (initialContextFactoryName != null) {
      Properties env = buildEnvProperties();
      jndi = new InitialContext(env);
    } else { 
      jndi = new InitialContext();
    } 
    return jndi;
  } 
   
  public Properties buildEnvProperties() {
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
    if (providerURL != null) {
      env.put(Context.PROVIDER_URL, providerURL);
    } else { 
      addWarn("You have set InitialContextFactoryName option but not the " 
          + "ProviderURL. This is likely to cause problems."); 
    } 
    if (urlPkgPrefixes != null) {
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getNameParser
     */ 
    protected void save (Object object) 
    throws NamingException
    { 
        __log.debug("SAVE {} in {}",this,_scope);
        InitialContext ic = new InitialContext();
        NameParser parser = ic.getNameParser("");
        Name prefix = NamingEntryUtil.getNameForScope(_scope);
       
        //bind the NamingEntry into the context 
        Name namingEntryName = NamingEntryUtil.makeNamingEntryName(parser, getJndiName());
        namingEntryName.addAll(0, prefix);
        _namingEntryNameString = namingEntryName.toString();
        NamingUtil.bind(ic, _namingEntryNameString, this);
                 
        //bind the object as well 
        Name objectName = parser.parse(getJndiName());
        objectName.addAll(0, prefix);
        _objectNameString = objectName.toString();
        NamingUtil.bind(ic, _objectNameString, object);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 InitialContext Methods: