Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed Java applet through URL data

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

like image 309
user823959 Avatar asked Sep 17 '12 11:09

user823959


People also ask

Can a Java applet be executed from a Web browser?

A Java applet can be executed from a Web browser. The class name must be the same as the file name that contains the class. A file may contain several classes. Each class in the file is compiled into a separate bytecode file.

How an applet code will be embedded in a Java code?

Applet is embedded in an HTML page (in much the same way as images, audios, videos and other programs are embedded in an HTML file). To run an applet, you need to create a HTML file, which embeds the applet. Use a text editor to create the following HTML file and save it as " HelloApplet.

What is the code for embedding applet in HTML file?

The HTML <applet> tag specifies an applet. It is used for embedding a Java applet within an HTML document.


1 Answers

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().
like image 167
user823959 Avatar answered Sep 20 '22 06:09

user823959