• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Weblogic - cannot instantiate weblogic.jndi.WLInitialContextFactory

 
Robert Sullivan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a java application that connects to a Weblogic server that currently works. We would like to run the application as an applet passing data to the browser for display. I have created a new class that subclasses Applet which calls the main() method that would be called if running as an application. I've signed the jar file and run it in IE 5.5 with the OBJECT tag using the JRE 1.3 plugin. The code runs fine up to the point of creating an InitialContext where it fails with a ClassNotFoundException on weblogic.jndi.WLInitialContextFactory. I can instantiate this class directly with no problem so the class can be found. I've put some debug println's in URLClassLoader and for every class the load follows the same pattern; load with no URL, load with the user/home URL, and load with a list of jars. For most every class the third time is a charm. With the InitialContext creation it only does the first two and then gives up not bothering with the jars. I tried extracting the Weblogic class to the desktop (Windows 2000) and it then found that file but failed on another Weblogic class. So we tried extracting all the jar classes to the desktop and it failed much sooner in the process never getting close to the InitialContext creation. Our goal is to be able to run as an application or an applet with the same jar files. The application using Swing and the applet using DHTML and Javascript widgets. As I said running the jars as an application works fine. What am I missing?
 
Mike Bwn
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya Robert,
Just a thought - youve probably checked it but.......
dont forget that if the weblogic server didnt create the applet (ie your connecting to a third party server) then it isnt trusted. you need to give your applet rights to connect, resolve, listen etc to that server address and port combination.
you do this through the java.policy file. Your app will run because by rights it has any permission it needs - unlike your applet. If you think this is the problem and require some help then post back to this page and i'll give you an example.
hope this helps
mike b
 
Robert Sullivan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That may be it. I am signing my applet with permission java.security.AllPermission; so I figured I could do just about anything. I am able to create directories and log files and write to them so I must have some permissions established.
I am getting the following error: java.security.AccessControlException: access denied (java.net.SocketPermission server.com resolve)
Here is my code:
public void testConnectWeblogic()
{
System.out.println("Opening weblogic connection...");
getInitialContext("t3://server.com:80");


}

static private InitialContext getInitialContext (String address)
{
InitialContext initialContext = null;
Hashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put (Context.PROVIDER_URL, address);
try
{
long before = System.currentTimeMillis();
initialContext = new InitialContext(env);
long after = System.currentTimeMillis();
// System.out.println("\n\t-WL- weblogic retrieve initial context time: " + (after - before) + " ms");
System.out.println( "-WL- weblogic retrieve initial context time: " + (after - before) + " ms");
}
catch (javax.naming.NamingException e)
{
//System.out.println (e.toString());
System.out.println("TRWLClientMessenger.getInitialContext()-->"+e);
e.printStackTrace();
}
catch(Exception cnfe)
{
System.out.println("cnfe error");
cnfe.printStackTrace();
}

System.out.println("CONTEXT: " + initialContext);
return (initialContext);
}
 
Robert Sullivan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem turned out to be two-fold; unsigned Weblogic classes and a call from JavaScript. Our application comes in two jar files; one for our in-house classes and a separate jar for 3rd-party classes - like Weblogic. I only signed our in-house jar because several of the 3rd-party classes were already signed. I tried to duplicate the instantiation of an InitialContext in a test class and it worked fine. Then it dawned on me that the Weblogic classes needed to be signed. So I moved them into the in-house jar and I hit a different problem - class not found - but at least there was no longer a SocketPermission error. I also noticed that I was initiating the connection logic from JavaScript. So I relocated the initiation of the connection logic to the Applet's init() method and it connected without a problem.
 
Mike Bwn
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got there in the end then!!!
nice one,
mike b
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic