Click to See Complete Forum and Search --> : Is it possible to call a DLL from a Servlet?


dellwo
September 5th, 2001, 08:24 AM
Hello, i've a big problem, because i need to know this very urgent...
I hope anyone can help me with this ;-)

I need to call a DLL from my Servlet.
I used System.loadLibrary("C:\\WINNT\\System\\mydll.dll").
This works fine if i use it in an java application. When i use it in my servlet i get an SecurityException. What do i have to do, that my servlet gets the permissions to can call the DLL??


Thanks christian

Norm
September 5th, 2001, 04:58 PM
You don't say what server you are using. That would probably be where you need to give permissions.
In a simple server written in Java I've written, you could pass a policy file on the commandline when the JVM is started or you could put it in the JVM's java.policy file.

Norm

dellwo
September 6th, 2001, 08:21 AM
hi, thx for your reply ;-)
I've posted already in different forums, but noone seems to know a solution for this problem...

I'm using the j2eeSDK1.3 vom SUN.
What about those policy-files?
I have 2 policy files, 'server.policy' and 'client.policy', in the ./lib/security folder
What do i have to add/change in this files, that my servlet can load DLL's?
Here is the code i use to call the DLL:

public class loadDLL
{
public void callHelloWorld()
{
displayHelloWorld();
}

private native void displayHelloWorld();

static
{
Runtime runner = Runtime.getRuntime();
runner.loadLibrary("C:\\WINNT\\System32\\test.dll");
}
}

I'm creating an instance of this class in my servlet and then i call the 'callHelloWorld()' method. This works in my java-program but not in the servlet.
Here is the exception I get when the servlet is trying to call the DLL:

java.lang.ExceptionInInitializerError: java.security.AccessControlException: access denied (java.lang.RuntimePermission loadLibrary.C:\WINNT\System32\test.dll)

Hope you can help me...

greetz christian...

Norm
September 6th, 2001, 10:14 PM
There is some doc in Sun's Tutorial on Security on how to use the policytool to grant permissions. Sorry, I don't have the URL for it.
I'm not familiar with the two policy files you mention.
I have \javasoft\jre\1.2\lib\java.security file (WIn98) which has references/pointers to a .java.policy file which is where I've placed my permissions using the policytool.

In looking at the permissions available to be granted in the policytool, I see a loadlibrary.<libraryname> target to use with RuntimePermission.
You get this entry in the .java.policy file:
grant {
permission java.lang.RuntimePermission "loadLibrary.C:\\WINNT\\System32\\test.dll";
};

I haven't tested it, so you may have to play with it some.

Norm