Hot questions for Using Applets in liveconnect

Top Java Programmings / Applets / liveconnect

Question:

I have problem in passing some data from JavaScript to an applet. I think size of data is too big (18M characters in string) to pass it through LiveConnect.

I put code samples below:

JavaScript:

var bigData = generateSomeBigData(18000000); // string contaning 18 000 000 characters
applet.Execute(bigData); // no error

Applet:

public void Execute(String data) {
    this.doSomethingWithData(data);  // data is null
}

I didn't get any error or exceptions in java console or in javascript code. I've tried running applet with bigger heap, but it didn't help.

... <param name="java_arguments" value="-Xmx128m" /> ...

The only problem is I get null instead of string contaning data, it doesn't depend on browser (FF, Chrome).


Answer:

I solved this problem. I moved data generation to server site and I'm passing data to applet using one time self destructing link. Applet can download information, which is no more available, and return result.

Here you have an example:

Server:

String bigData = this.generateBigData(18000000);
String linkToData = this.getOneTimeLink(bigData);

JavaScript:

applet.Execute(linkToBigData);

Applet:

public void Execute(String link) {
    String data = this.downloadData(link);
    this.doSomethingWithData(data);  // data is not null ;)
}

EDIT 11 May 2015:

Maybe you need a small explanation to one time destructing link. I used it because it was another requirement to my project but it is not necessary to achieve solution.

Question:

Cannot call applet methods from javascript. A error appears on the log

-> liveconnect: Security Exception: JavaScript from http:url:port/application attempted to access a resource it has no rights to.

Manifest-Version: 1.0
Application-Name: application
Created-By: Apache Maven 3.0.4
Caller-Allowable-Codebase: *
Application-Library-Allowable-Codebase: *
Build-Jdk: 1.7.0_72
Permissions: all-permissions
Codebase: *

The java security setting is set to meddium

JRE Version 1.8.0_25-b17

Applet Signed by a trusted source, and the applet jar is downloaded from the same domain as the calling page.

If I try to call the applet method from firebug javascript console another error shows up: Error: Liveconnect call for Applet ID 4 is not allowed in this JVM instance

The applet TAG:

  <applet id="applet" code="applet.core.AppletBootstrap" codebase="/applet" archive="applet.jar" width="650" height="500" mayscript="mayscript">
<param name="cache_archive" value="applet.jar"/>
<param name="cache_version" value="2.4.17.2,2.4.17.2,2.4.17.2,2.4.17.2,2.4.17.2"/>
<param name="conversationId" value="e00ed781a56a4378a285d7839a9925bf"/>
<param name="userAgent" value="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36" />
<param name="java_status_events" value="true"/>
<param name="separate_jvm" value="true"/>
<param name="classloader_cache" value="false"/>
<param name="java_arguments" value="-Xmx128m -Djnlp.packEnabled=true "/>
</applet>

EDIT: @Seba JDK-8058697 is a OpenJDK bug related to this issue, unfortunately it is not accessible to me - You can see a duplicate of it: here

EDIT 2: Java 8 update 40 is working again


Answer:

Today I ran into this problem on Ubuntu 14.10, Firefox 35.0.1 & Oracle Java JRE 1.8.0_31. It is related in some way to JRE utility class in deploy.jar which doesn't work properly on Linux (NativeMixedCodeDialog). On Windows, when you try to access Liveconnect (which implies MIXED security mode) a dialog is shown by this class to kindly ask you for a confirmation. This, for some unknown reasons, doesn't happen on Linux.

You can easily try to check this, by running this command:

/usr/lib/jvm/java-8-oracle/jre/bin/java -cp /usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar com.sun.deploy.uitoolkit.ui.NativeMixedCodeDialog "Some Aplet" "Web Site:" "https://localhost" "Publisher:" "Some publisher" "Do not show this again for this app and web site."

My solution was to use Deployment Rule Set to force Java to trust my app. This might be a no-go for production use, but it let me develop further until this NativeMixedCodeDialog gets fixed.

So straight to the point:

  1. Create a file named ruleset.xml
  2. Fill it with content according to this documentation, for ex.

    <?xml version="1.0" encoding="UTF-8"?>
    <ruleset version="1.0+">
      <rule>
        <id location="https://localhost/" />
        <action permission="run" version="SECURE" />
      </rule>
    </ruleset>
    
  3. Put this into jar

    jar cvf DeploymentRuleSet.jar ruleset.xml

  4. Sign this jar with certificate valid in cacerts, it might be self-signed certificate, but it needs to be found in java cacert file, not just trusted in control panel

    jarsigner -verbose -keystore ~/selfsigned.p12 -storetype pkcs12 DeploymentRuleSet.jar selfsigned

  5. Copy signed jar to /etc/.java/deployment/

  6. Possibly restart your browser everything should be working fine

Question:

While applet initializing when using isActive() method. It only return undefined. This problem only comes "Java 8 Update 91". Can anyone tel me the solution to fine applet loaded or not?

I have used the following code:

function isAppletActive(app) {
 var active = false; 
 try { active = app.isActive(); // IE check }
 catch(ex) { 
 try { active = app.isActive; // Firefox check }
   catch(ex1){ } } //alert(active); return active; 
}

Answer:

This is a bug in either Firefox (most likely) or Java 8_91. It appears that any premature call to the applet's method hoses the link to the applet permanently.

However, the applet support has a new feature for checking applet status, enabled by setting parameter <param name="java_status_events" value="true"/>. This in turn allows status to be checked while the applet is loading. If you enable this, and use it to prevent any applet method being called until the applet loads, it all works.

function isAppletActive(app) {
    // assuming `app` is the applet element...
    if(app.status==1) { return false; } // still loading
    if(app.status==2) { throw "Applet load failed"; }

    try { active = app.isActive(); } // IE check 
    catch(ex) { 
        try { active = app.isActive; } // Firefox check 
        catch(ex1) { /* NEVER swallow exceptions! */ } 
    } 
    //alert(active); 
    return active;
}

And just BTW, Firefox uses app.isActive(), not app.isActive, though who knows what it did in the past.

Question:

I have a Java web application. It was running fine until last week. We released a new version of our code and one of our applets is not getting launched anymore from our main java application. We did not change anything in the called applet, nor on the surrounding code.

The strange thing is, it looks like it's working on 64-bit pcs but not on 32-bit versions.

Used java version: 1.8.0_65. Used web browser: Internet Explorer 11

Java console log of pc where it is not working (32-bit):

cache: Reading Signers from xxxxxxxxxxxxxx.jar | C:\Temp\java_cache\6.0\39\123b7967-55895556-3.4.0.2-.idx
cache: Done readSigners(xxxxxxxxxxxxxx.jar)
network: Created version ID: 3.4.0.2
network: Created version ID: 3.4.0.2
network: Created version ID: 3.4.0.2
network: Created version ID: 3.4.0.2
security: Missing Application-Library-Allowable-Codebase manifest attribute for: xxxxxxxxxxxxxx .jar
security: Validate the certificate chain using CertPath API
basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 402489 us, pluginInit dt 2037296772 us, TotalTime: 2037699261 us
basic: Applet initialized
basic: Starting applet
basic: completed perf rollup
basic: Applet made visible
basic: Applet started
basic: Told clients applet is started
preloader: Stop progressCheck thread queue.size()=0

Java console log of pc where it is working fine (64-bit):

cache: Reading Signers from 3871 xxxxxxxxxxxxxx.jar | C:\Temp\java_cache\6.0\52\13969c74-2c189342-3.4.0.2-.idx
cache: Done readSigners(xxxxxxxxxxxxxx.jar)
network: Created version ID: 3.4.0.2
network: Created version ID: 3.4.0.2
network: Created version ID: 3.4.0.2
network: Created version ID: 3.4.0.2
security: Missing Application-Library-Allowable-Codebase manifest attribute for: xxxxxxxxxxxxxx.jar
security: Validate the certificate chain using CertPath API
basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 546952 us, pluginInit dt 55559621 us, TotalTime: 56106573 us
basic: Applet initialized
basic: Starting applet
basic: completed perf rollup
basic: Applet made visible
basic: Applet started
basic: Told clients applet is started
security: Grant liveconnect connect perm for xxxxxxxxxxxxxx: java.security.Permissions@2e9808 (
 ("java.lang.RuntimePermission" "accessClassInPackage.sun.audio")
 ("java.lang.RuntimePermission" "stopThread")
 ("com.sun.deploy.security.SecureCookiePermission" "origin.xxxxxxxxxxxxxx")
 ("java.net.SocketPermission" "localhost:0" "listen,resolve")
 ("java.util.PropertyPermission" "java.specification.version" "read")
 ("java.util.PropertyPermission" "path.separator" "read")
 ("java.util.PropertyPermission" "java.vm.vendor" "read")
 ("java.util.PropertyPermission" "os.version" "read")
 ("java.util.PropertyPermission" "browser.version" "read")
 ("java.util.PropertyPermission" "java.vendor.url" "read")
 ("java.util.PropertyPermission" "browser" "read")
 ("java.util.PropertyPermission" "browser.vendor" "read")
 ("java.util.PropertyPermission" "os.name" "read")
 ("java.util.PropertyPermission" "java.vm.specification.version" "read")
 ("java.util.PropertyPermission" "java.vm.name" "read")
 ("java.util.PropertyPermission" "javaws.*" "read,write")
 ("java.util.PropertyPermission" "javaplugin.vm.options" "read")
 ("java.util.PropertyPermission" "mrj.version" "read")
 ("java.util.PropertyPermission" "java.version" "read")
 ("java.util.PropertyPermission" "jnlp.*" "read,write")
 ("java.util.PropertyPermission" "javaplugin.version" "read")
 ("java.util.PropertyPermission" "os.arch" "read")
 ("java.util.PropertyPermission" "java.specification.vendor" "read")
 ("java.util.PropertyPermission" "java.vm.specification.name" "read")
 ("java.util.PropertyPermission" "file.separator" "read")
 ("java.util.PropertyPermission" "line.separator" "read")
 ("java.util.PropertyPermission" "java.vendor" "read")
 ("java.util.PropertyPermission" "java.specification.name" "read")
 ("java.util.PropertyPermission" "java.vm.specification.vendor" "read")
 ("java.util.PropertyPermission" "java.vm.version" "read")
 ("java.util.PropertyPermission" "javapi.*" "read,write")
 ("java.util.PropertyPermission" "java.class.version" "read")
 ("java.util.PropertyPermission" "http.agent" "read")
 ("java.net.URLPermission" "xxxxxxxxxxxxxx/-" "*:*")
 ("java.net.URLPermission" "xxxxxxxxxxxxxx" "*:*")
)

security: Javascript from a non secure page is accessing privileged code. Consider using HTTPS protocol when using Javascript -> Java liveconnect calls.
Starting processing threads

The manifest file of the applet also seems ok:

Manifest-Version: 1.0
Trusted-Library: true
Trusted-Only: true
Application-Name: xxxxxxxxxxxxxx
Built-By: xxxxx
Build-Jdk: 1.6.0_34
Permissions: all-permissions
Created-By: Eclipse
Caller-Allowable-Codebase: xxxxxxxxxxxxxx (long list, including the ip of the applet)
Archiver-Version: Subversion
Codebase: xxxxxxxxxxxxxx (long list, including the ip of the applet)

Can anyone help me with solving this issue?


Answer:

I found what caused the problem: the surrounding code was hanging in one of the javascript functions on the 32-bit PCs (due to a wrong file path). This caused the screen to freeze and the applet not to be executed.