Embed Java applet through URL data
Asked Answered
I

2

11

I'm trying to explore URL data capabilities to embed in HTML Java applet.

The documentation, for HTML tags to instantiation a java applet 1, don't exclude this option but I don't seem to be able to to this.

I have different variations of HTML tags values using (object and applet) and what I think came close to my goal was this:

<object type="application/x-java-applet" width="100" height="100">
  <param name="archive" value="data:application/java-archive;base64,BASE64_OF_JAR"/>
  <param name="code" value="test.class"/>
  <h1>not working</h1>
</object>

This variation result in an IlegalArgumentException with text "name". I check this clicking on the Error Icon on the Browser. On The java console the whole stack trace is:

java.net.MalformedURLException: unknown protocol: data
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at sun.plugin.util.ProgressMonitorAdapter.setProgressFilter(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager.setupProgress(Unknown Source)
        at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

Does anyone have an idea about how to do this or if it's not possible?

PS: There's an example of how to embed an JNLP in HTML by Oracle here

Idiotic answered 17/9, 2012 at 11:37 Comment(8)
Have to admit I did not read the post carefully the other day & missed that last link. Intriguing that a JNLP can be base 64 encoded..Intrench
What happens if you swap data:application/java-archive with data:application/x-java-archive?Intrench
It's the same exception. The plugin handler doesn't seem to recognize the DATA URL, it would be nice to see the source code of the plugin :) The full exception: pastebin.com/ddsDSTQgIdiotic
Could you edit that stacktrace into the question? Also use code formatting on it. BTW - I was trying to set up a local test here that resulted in this question. SNAFU! ;)Intrench
well, you have now learnt that "doesn't exclude" doesn't imply "does include" :PAlo
BTW - can you give us the base 64 text of both a (very simple) applet class and the Jar?Intrench
A DummyApplet.class base64 pastebin.com/Jjmz5U4h; A DummyApplet.jar base64 pastebin.com/8fFDCQuF and the source code pastebin.com/3BaLijWj ThanksIdiotic
I think I found my answer in the source code javasourcecode.org/html/open-source/jdk/jdk-6u23/sun/plugin2/… no base64 references.Idiotic
I
5

The HTML4 specification for OBJECT element allows inline data embed through URL DATA and the Applet instantiation documentation from Oracle also allows this. The tests performed show the Java browser plugin (from Oracle), and the available source code from Java SE 6, shows that the implementation doesn't support it.

In this case, doesn't seem to matter if the browser support it, because the resource handling of resources reference in the Object/Applet HTML Element are performed by the browser plugin.

An alternative would be to be use applet deserialization, serialized through URL DATA, using the OBJECT attribute of APPLET element. As mentioned in the HTML4 specification, there is no active support for APPLET and OBJECT attribute, and JRE doesn't seem to support Object deserialization from URL DATA too.

In a nutshell, JRE doesn't support base64 deserialization in the CODE, OBJECT and ARCHIVE HTML attributes.

There is also a BUG regarding URL DATA support in JRE1.4.1 that wasn't fulfilled Bug ID: 4756961.

The results of my tests with JRE7 in a 64 bits Windows machine are the following:

  • Passing a JAR through URL DATA to ARCHIVE attribute results in an IllegalArgumentException in Applet2Manager.loadJarFiles();
  • Passing a class through URL DATA to CODE attribute results in a ClassNotFoundException in Applet2ClassLoader.findClass();
  • Passing a serialized applet through URL DATA to OBJECT attribute results in a FileNotFoundException in Plugin2ClassLoader.getResourceAsResource().
Idiotic answered 23/9, 2012 at 18:30 Comment(1)
excellent answer, well-researched with useful links. Wish I could upvote more than once.Canuck
I
2

Even if it is allowable by HTML standards, JREs typically do not understand base64 encoded data.

Intrench answered 18/9, 2012 at 1:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.