BeanShell in Applet

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

BeanShell in Applet

Bowo Prasetyo
Dear All,

I am trying to use BeanShell (bsh.Interpreter) in my Applet. It works
fine in my local browser. But when I moved the jar file into my
server, it won't work any more.

After a couple of days searching in Google, I could not find any
solution. Even strange, the same error occurs when I try to just copy
the working demo applet in BeanShell.org below:

http://www.beanshell.org/jbshdemo.html

I copy the html as well as jar file into my server below:

http://www.my-tool.com/code-tester/java-tester/TestApplet.html

These two sites have exactly the same html and jar file, and it works
in the BeanShell.org but broke in my server.

Below is the error message:

Could not init static:java.security.AccessControlException: access
denied (java.util.PropertyPermission debug read)
java.lang.SecurityException: Prohibited package name: java.lang
        at java.lang.ClassLoader.preDefineClass(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at sun.applet.AppletClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.applet.AppletClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at bsh.BshClassManager.plainClassForName(Unknown Source)
        at bsh.classpath.ClassManagerImpl.classForName(Unknown Source)
        at bsh.NameSpace.classForName(Unknown Source)
        at bsh.NameSpace.getImportedClassImpl(Unknown Source)
        at bsh.NameSpace.getClassImpl(Unknown Source)
        at bsh.NameSpace.getClass(Unknown Source)
        at bsh.Name.consumeNextObjectField(Unknown Source)
        at bsh.Name.toObject(Unknown Source)
        at bsh.Name.toObject(Unknown Source)
        at bsh.NameSpace.get(Unknown Source)
        at bsh.Interpreter.get(Unknown Source)
        at bsh.Interpreter.getu(Unknown Source)
        at bsh.Interpreter.<init>(Unknown Source)
        at bsh.Interpreter.<init>(Unknown Source)
        at bsh.Interpreter.<init>(Unknown Source)
        at bsh.Interpreter.<init>(Unknown Source)
        at bsh.util.JDemoApplet.init(Unknown Source)
        at sun.applet.AppletPanel.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)


Please give me advice to make BeanShell works in applet.

Best regards,
bowo

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: BeanShell in Applet

Daniel Martin-7
I already sent this privately, but I really should send this to the
list too:

"Bowo Prasetyo" <[hidden email]> writes:

> Please give me advice to make BeanShell works in applet.

Get a webhost that responds to files that aren't there correctly, with
a 404 "Not Found" result code.  Your current webhost responds to files
that aren't there by redirecting to an html page that has some text on
it explaining the error.  (Presumably; my Japanese isn't very good)
The HTTP response code the browser sees is a success.

Unfortunately, this means that it is impossible for java to know that
a file really isn't there.  Every request looks like a success - the
call to HttpURLConnection.openStream always returns successfully, and
never throws a FileNotFoundException, which it really needs to do.

The problem that you're encountering is caused because in its startup
bsh tries to resolve a bunch of unqualified names, and the way that
bsh resolves them is to first see if the name is the name of a class
in the "java.lang" package.  The first name it tries to resolve is
"bsh".  In your applet, this results in the applet attempting to load
the url
http://www.my-tool.com/code-tester/java-tester/java/lang/bsh.class

Now, if that url weren't found, there'd be no problem.  Unfortunately,
your webhost thinks that it is found (compare the headers returned by
wget -S -O/dev/null http://www.my-tool.com/code-tester/java-tester/java/lang/bsh.class
and
wget -S -O/dev/null http://www.beanshell.org/java/lang/bsh.class )

So then, you have the applet trying to create the java class
"java.lang.bsh" based on the contents of the error page.  If this
weren't stopped by the security exception, it would be stopped shortly
on a bad classfile format exception.

Until you get a webhost that can properly return a "Not Found" status
when appropriate, the only option I can think of is to set your
applet's "CODEBASE" property to some machine that will respond to not
found files properly.  For example, this should work:

<APPLET CODE="bsh.util.JDemoApplet"
   ARCHIVE="http://www.my-tool.com/code-tester/java-tester/bsh-20b4-13.jar"
   WIDTH="500" HEIGHT="250" CODEBASE="http://www.beanshell.org/">
</APPLET>

Of course, this still means that during applet startup, the applet is
going to be asking for a bunch of urls that don't exist on the
beanshell.org site, which might slow things down - you may want to use
a closer machine that is able to properly generate 404 codes when
stuff isn't there.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: BeanShell in Applet

Bowo Prasetyo
In reply to this post by Bowo Prasetyo
Hi Daniel,

Thank you very much for your clear explanation. This kind of error
reason is really beyond even my imagination.

Now the demo applet is working fine just by replacing its ARCHIVE and
CODEBASE as you suggested. Wonderful.

My headache in three days has disappeared by such a simple solution.. :)

Best regards,
bowo

On 22/06/07, Daniel Martin <[hidden email]> wrote:

> "Bowo Prasetyo" <[hidden email]> writes:
>
> > Please give me advice to make BeanShell works in applet.
>
> Get a webhost that responds to files that aren't there correctly, with
> a 404 "Not Found" result code.  Your current webhost responds to files
> that aren't there by redirecting to an html page that has some text on
> it explaining the error.  (Presumably; my Japanese isn't very good)
> The HTTP response code the browser sees is a success.
>
> Unfortunately, this means that it is impossible for java to know that
> a file really isn't there.  Every request looks like a success - the
> call to HttpURLConnection.openStream always returns successfully, and
> never throws a FileNotFoundException, which it really needs to do.
>
> The problem that you're encountering is caused because in its startup
> bsh tries to resolve a bunch of unqualified names, and the way that
> bsh resolves them is to first see if the name is the name of a class
> in the "java.lang" package.  The first name it tries to resolve is
> "bsh".  In your applet, this results in the applet attempting to load
> the url
> http://www.my-tool.com/code-tester/java-tester/java/lang/bsh.class
>
> Now, if that url weren't found, there'd be no problem.  Unfortunately,
> your webhost thinks that it is found (compare the headers returned by
> wget -S -O/dev/null http://www.my-tool.com/code-tester/java-tester/java/lang/bsh.class
> and
> wget -S -O/dev/null http://www.beanshell.org/java/lang/bsh.class )
>
> So then, you have the applet trying to create the java class
> "java.lang.bsh" based on the contents of the error page.  If this
> weren't stopped by the security exception, it would be stopped shortly
> on a bad classfile format exception.
>
> Until you get a webhost that can properly return a "Not Found" status
> when appropriate, the only option I can think of is to set your
> applet's "CODEBASE" property to some machine that will respond to not
> found files properly.  For example, this should work:
>
> <APPLET CODE="bsh.util.JDemoApplet"
>    ARCHIVE="http://www.my-tool.com/code-tester/java-tester/bsh-20b4-13.jar"
>    WIDTH="500" HEIGHT="250" CODEBASE="http://www.beanshell.org/">
> </APPLET>
>
> Of course, this still means that during applet startup, the applet is
> going to be asking for a bunch of urls that don't exist on the
> beanshell.org site, which might slow things down - you may want to use
> a closer machine that is able to properly generate 404 codes when
> stuff isn't there.
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users