Injecting_jndi_datasources

I know in standalone client cannot access java:comp/env which is used in my server application from my previous post, so I try another method as follow to test the server method
public void getEnvironment() throws Exception{
     try{
          System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
          /*System.setProperty(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
          System.setProperty(Context.SECURITY_PRINCIPAL, "weblogic");
          System.setProperty(Context.SECURITY_CREDENTIALS, "password");*/
          InitialContext ic = new InitialContext();
          ic.createSubcontext("java:");
          ic.createSubcontext("java:/comp");
          ic.createSubcontext("java:/comp/env");
          ic.createSubcontext("java:/comp/env/jdbc");               
          // Construcvt Datasource
          OracleConnectionPoolDataSource ds = new OracleConnectionPoolDataSource();          
          ds.setURL("jdbc:oracle:thin:@cdcehr29:14985");
          ds.setUser("als_app_ro_user");
          ds.setPassword("ai1pass");
          //Connection conn = ds.getConnection();
          ic.bind("java:/comp/env/jdbc/test", ds);
          System.out.println("see?");
          Context envIc = (Context) ic.lookup("java:/comp/env");
          envIc.bind("THIS_SERVICE_CD", "");
          envIc.bind("THIS_SERVICE_VER", "");
          envIc.bind("SERVICE_DATA_SOURCE_JNDI", "jdbc/test");
          envIc.bind("ALS_PROJECT_CD", "");
          envIc.bind("ALS_SYSTEM_CD", "");
          envIc.bind("EHR_CONFIG_DATA_SOURCE_JNDI", "");
          envIc.bind("SGR_PATH", "");
          envIc.bind("AUDIT_TABLE_NAME", "");
          envIc.bind("DEBUG_TABLE_NAME", "");
          InitialContext ic2 = new InitialContext();
          Context ctx = (Context)ic2.lookup("java:/comp/env");  // error
          //Context ctx = (Context)ic2.lookup("java:comp/env");
          System.out.println("see2?");
     }catch(NamingException ex){
          ex.printStackTrace();
     }catch(Exception ex){
          ex.printStackTrace();
}but when the code run to
Context ctx = (Context)ic2.lookup("java:/comp/env"); // error
error as following is thrown
>
javax.naming.NameNotFoundException: remaining name: /comp/env
     at weblogic.j2eeclient.SimpleContext.resolve(SimpleContext.java:35)
     at weblogic.j2eeclient.SimpleContext.resolve(SimpleContext.java:39)
     at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:59)
     at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:64)
     at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyContextWrapper.java:45)
     at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.java:130)
     at javax.naming.InitialContext.lookup(InitialContext.java:392)
     at jdbc.test.ConnectOracle.getEnvironment(ConnectOracle.java:84)
     at jdbc.test.ConnectOracle.main(ConnectOracle.java:178)
what is the reason?
I get this inspiration from a website [https://blogs.oracle.com/randystuph/entry/injecting_jndi_datasources_for_junit|https://blogs.oracle.com/randystuph/entry/injecting_jndi_datasources_for_junit]
which mention
>
Context initContext = new InitialContext();
Context webContext = (Context)initContext.lookup("java:/comp/env");
after create the initialcontext in @BeforeClass

seem the problem related to
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");because the following has no error when create the second InitialContext() and then called
Context webContext = (Context) initContext.lookup("java:/comp/env");
public void getEnvironment() throws Exception{
    try {
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
            System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
               /* if using these, will throw error
                * createSubcontext not allowed in a ReadOnlyContext;remaining name ''
                * when call initialContext.createSubcontext("java:/comp");
             System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
             System.setProperty(Context.URL_PKG_PREFIXES, "weblogic.jndi.factories:weblogic.corba.j2ee.naming.url");
            InitialContext initialContext = new InitialContext();
            initialContext.createSubcontext("java:");
            initialContext.createSubcontext("java:/comp");
            initialContext.createSubcontext("java:/comp/env");
            initialContext.createSubcontext("java:/comp/env/jdbc");
            Context initContext = new InitialContext();
            Context webContext = (Context) initContext.lookup("java:/comp/env");
            //DataSource dataSource = (DataSource) webContext.lookup("jdbc/mydatasourcename1");
            System.out.println("see");
        catch (NamingException ne) {
            System.err.println("Problem with the jndi name.");
            ne.printStackTrace();
}But the detail reason is still unknown, anyone could help?

Similar Messages

Maybe you are looking for

  • 80GB Classic not seen by Windows 8 or iTunes(11).

    Its only started happening in the last day or so, but I cannot get my iPod to be seen by either Windows or iTunes. Although when I connect via USB the iPod display tells me that it's connected but never actually appears in Windows on iTunes. I have b

  • Urgent help on logic:iterate

    Dear all, I have a problem on logic:iterate and structs. Suppose I have EmployeeListAction to get the employees data as below :- employees = EmployeeData.getEmployees(getDataSource(request)); request.setAttribute("employees", employees); In the Emplo

  • Clocking digital I/O using a hardware timer.

    I am using a DaqCARD-6062E to create a JTAG interface to a microcontroller. Using the delay VI's to create the clock and shift out bits serially takes a long time since I have to shift out 600 bits and the smallest delay I can use is 1ms (making the

  • IPod touch issues with iTunes

    1. how to you sync lyrics? I've done this settings<music<lyrics & podcast info on ,but no lyrics on m ipod 3&4 I tried to type the lyrics myself ,but nothing happened on the 3 and the 4 couldn't sync because of space 2. my ipod 4 says it has 4gbs of

  • Export?import error

    Hi all, i am using 10.2.0.1.0 on win 2003 server I wana do export & import for that i create the directory & give privileges to user scott but i got the error Grant create any directory to scott; CREATE OR REPLACE DIRECTORY ora AS 'C:\oracle\product\