4 Replies Latest reply: Dec 12, 2012 7:05 PM by errodr RSS

    JNDI Datasource Look Up Not Working From Applet

    errodr
      I have an applet that I am developing that will take a given jndi data source name, perform a look up and get the data source.

      When the following code is used in a stand alone java app, it works perfectly. Using (almost) the same code in an applet (running in JDeveloper applet viewer) results in the applet hanging when trying to perform the context look up, no exceptions thrown, just never returns.

      Code:
                  try {
                      //jbInit();
                      
                      env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
                      env.put(javax.naming.Context.PROVIDER_URL,"t3://localhost:7001");
                      
                      try {
                          Context ctx = new InitialContext(env);
                          javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/sandboxDS");
                          conn = ds.getConnection();
                      } catch(Exception e){
                          e.printStackTrace();
                      }
                      
                      if(conn != null){
                          System.out.println("Got connection...");
                          
                          String colDescQuery =
                              "select column1 from my_table where table_name = 'your_table' order by col_order_no";
                          Statement colDescStmt = conn.createStatement();
                          ResultSet colDescRS = colDescStmt.executeQuery(colDescQuery);
                          
                          while (colDescRS.next()) {
                              System.out.println(colDescRS.getString(1));
                          }                 
                          
                      } else {
                          System.out.println("No connection...");
                      }
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
      I am doing the lookup against Weblogic Server 10.3.5. Any help is appreciated!

      Thanks...
        • 1. Re: JNDI Datasource Look Up Not Working From Applet
          DrClap
          This applet -- it was downloaded from some server and is running in a browser on some other machine, right? But from what I can see in your code, you're telling it to look in the client machine for the JNDI server.
          env.put(javax.naming.Context.PROVIDER_URL,"t3://localhost:7001");
          That isn't going to work unless there is in fact a JNDI server listening at port 7001 on the client. And even then it would require the applet to be signed.
          • 2. Re: JNDI Datasource Look Up Not Working From Applet
            errodr
            Sorry, should have been more clear. The code is running within the JDeveloper applet viewer so signing not necessary at this point. I know I will have to sign for an actual deployment.

            Also, I do have a WLS instance on my local machine.

            I am having trouble figuring out why a stand alone application CAN find and use the data source but an applet cannot. Initially I thought that signing was necessary even when trying to run within the applet viewer, but I am able to make a JDBC connection and query without signing so I don't think that is the issue.
            • 3. Re: JNDI Datasource Look Up Not Working From Applet
              DrClap
              What about this property, then?
              env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
              Does the applet have that class in its classpath? I.e. in one of the jars in the "archive" attribute of the <applet> tag, or however you set things up?
              • 4. Re: JNDI Datasource Look Up Not Working From Applet
                errodr
                Yes, unfortunately that is not the issue. I have made sure that the applet does have that class in its classpath.

                It's driving me crazy...