General developer forum

 
 
Picture of Luis de la Torre
Embed an applet served by pluginfile.php
 

Hi all,

I talked about this problem in a different thread several days ago. For a couple of days, I thought the problem was gone but then I realized it wasn't. I've been trying since then to solve it but at this point I'm giving up and I feel totally frustrated. So, if someone could please (pretty please with sugar on top tongueout), help me, I would be extremely grateful.

Here is the exact problem description.

I have a plugin that let teachers creating new activities which consist on any Java applets they want to upload. This is done using the filepicker in the mod_form.

Students can then access those activities and what they see is the applet, uploaded by the teacher, embedded into the view.php webpage of Moodle.

Java applets files are stored using Moodle API, i.e. in the moodledata folder. And they are served also using the API, i.e. using the pluginfile.php script.

Here is an example of the code I'm using:


$file_record = $DB->get_record('files', array('filename' => $ejsapp->applet_name.'.jar', 'component' => 'mod_ejsapp', 'filearea' => 'jarfile', 'itemid' => $ejsapp->id));
$app_codebase = $CFG->wwwroot . "/pluginfile.php/" . $file_record->contextid . "/" . $file_record->component . "/" . $file_record->filearea . "/" . $file_record->itemid . $file_record->filepath;
$fullpath = '/'.$file_record->contextid.'/mod_ejsapp/'.$file_record->filearea.'/'.$file_record->itemid.'/'.$file_record->filename;
$archive = $app_codebase . $file_record->filename;

$code = '<script "text/javascript">';
$code .= "var w = {$ejsapp->width}, h = {$ejsapp->height};";

$code .= "document.write('<embed id=\"{$ejsapp->applet_name}\"');
  document.write('type=\"application/x-java-applet;version=1.6\"');
  document.write('width=\"'+w+'\"');
  document.write('height=\"'+h+'\"');
  document.write('archive=\"$archive\"');
  document.write('code=\"{$ejsapp->class_file}\"');
  document.write('pluginspage=\"http://java.com/download/\"');";

$code .= '</script>';

$OUTPUT->heading($code);

Now, while this is working, and by that I mean the applet loads and it is shown embedded in the webpage, it can take even 4 or 5 minutes to do so!

Depending on the applet, it can actually only take a few seconds, which is the time it usually takes to load most embedded applets around there.

I even figured out why some applets load fast and some load so slow. However I failed to understand the reason of why this is happening.

Everytime the view.php webpage (containing the previous code) is loaded, pluginfile.php is called. Regardless the applet being used, pluginfile.php always receive something like:

/21/mod_ejsapp/jarfile/1/ejs_Gyroscope.jar

Which is ok. Actually, if you copy the complete url that serves the file (http://localhost/pluginfile.php/21/mod_ejsapp/jarfile/1/ejs_Gyroscope.jar), you instantly get the option to download the applet, and this is done quickly.

Now, while for some applets the previous call to pluginfile.php is done only once (this are the cases in which the applet loads in jus a few seconds), for others pluginfile.php can be called 10 or 12 times, receiving something like:

/21/mod_ejsapp/jarfile/1/org/opensourcephysics/tools/DefaultState.out

or

/21/mod_ejsapp/jarfile/2/servo_pkg/images/Servo.jpg

or

/21/mod_ejsapp/jarfile/3/org/opensourcephysics/resources/Resources.properties

This are just random examples. Anyway, the thing is all those are files inside of some of the .jar files. I don't know how or why this happens but it seems to me that Moodle File API open the .jar files and sometimes (only for some applets) it decides that it needs to serve those files inside the .jar aswell as the .jar itself. When this happens, it seem those files can't be accessed (so they cant be served) and Moodle keeps trying. As I said, sometimes 12 calls to pluginfile.php (always receiving the same parameters) are done.

When looking at the apache logs, I can see messages like these ones:

[Wed Oct 17 20:14:25 2012] [error] [client 127.0.0.1] File does not exist: C:/Moodle/server/moodle/mod/ejsapp/DefaultState.out
[Wed Oct 17 20:14:25 2012] [error] [client 127.0.0.1] Default exception handler: Sorry, the requested file could not be found Debug: \r\nError code: filenotfound\n* line 467 of \\lib\\setuplib.php: moodle_exception thrown\n* line 1917 of \\lib\\filelib.php: call to print_error()\n* line 4221 of \\lib\\filelib.php: call to send_file_not_found()\n* line 38 of \\pluginfile.php: call to file_pluginfile()\n

Thats from the error.log file.

 

127.0.0.1 - - [17/Oct/2012:20:14:25 +0200] "HEAD /mod/ejsapp/DefaultState.out HTTP/1.1" 404 - "-" "Mozilla/4.0 (Windows XP 5.1) Java/1.7.0_07"
127.0.0.1 - - [17/Oct/2012:20:14:25 +0200] "HEAD /pluginfile.php/21/mod_ejsapp/jarfile/1/org/opensourcephysics/tools/DefaultState.out HTTP/1.1" 404 - "-" "Mozilla/4.0 (Windows XP 5.1) Java/1.7.0_07"

The last one is from the access.log file.

 

Well, I think thats all. I hope someone has an idea of what might be going on here.

Im sorry for the huge message with the tons of lines of code but, as I said, at this point I am totally lost and I really need help.

Thanks!

 
Average of ratings: -
Picture of Edmund Edgar
Re: Embed an applet served by pluginfile.php
 

Hi Luis.

It sounds like you need to narrow this problem down a bit. Is your problem with Moodle serving the original applet, or is it happening when the browser tries to load the applet that it's downloaded?

Test this by fetching the applet from Moodle from the command line with wget, rather than with your browser, and timing it and checking the server logs for requests.

 
Average of ratings: -
Picture of Luis de la Torre
Re: Embed an applet served by pluginfile.php
 

Hi Edmund,


Thanks a lot for your reply.

I never used wget before but I have just tried. However I couldn't perform this test. I tried: wget http://admin:admin@localhost/pluginffile.php/21/mod_ejsapp/jarfile/1/ejs_Gyroscope.jar

This didnt work. I was getting a http 303 message (i.e. the web server was redirecting me to a new page: the login/index.php page). Anyway, wget downloaded the index.php file, of course, but it is not able to interpret the pluginfile.php script and get the ejs_Gyroscope.jar file. So I guess this is not a valid test.

 
Average of ratings: -
Picture of sam marshall
Re: Embed an applet served by pluginfile.php
Group DevelopersGroup Particularly helpful MoodlersGroup Testers

The problem is with the applet tag/applet and is not related to Moodle. It is trying to load resource files from a 'plain' classpath as well as the classpath inside the jar.

I haven't heard of that happening before. It's possible that Java always does that and I never noticed, but that seems fairly unlikely (l hope).

If we make the assumption that Java doesn't always do that, then there are basically two possibilities here: (a) your applet tag is wrong... wait, you're using an <embed> tag, wtf? Wow, that's probably wronger than wrong.

Or (b) the applet is manually trying to bypass its classloader by examining the classloader URL and requesting files specifically. This doesn't seem very likely to me.

Try the following:

1) Change your code to use an <applet> tag or possibly <object>. This URL (that I just found in Google and know nothing about) https://eyeasme.com/Shayne/HTML5_APPLETS/ shows how to use <object> tag in HTML5. As this is HTML5, I don't know whether this actually works in IE7 or IE8, you should test; if it doesn't, I would recommend continuing to use the <applet> tag which is reliable (I wouldn't recommend using older forms of the <object> tag that were designed specifically for IE, etc). Anyway, definitely don't use <embed>.

2) Make sure the parameters for the tag are correct.

If that doesn't help, you should post again here - or in some Java forum - but with the actual HTML source of the applet/object tag, not the PHP code that generates it. That way somebody can take a look at the parameters for the tag and see if there is something you missed.

--sam

 
Average of ratings: -
Picture of Luis de la Torre
Re: Embed an applet served by pluginfile.php
 

Hi Sam,

Thanks for your reply.

Actually, before trying with the <embed> tag, I tried with the <applet> one and I had exactly the same problem. I thought the root of this problem could be that tag, since think it is deprecated. I googled a bit and it seemed to me that <embed> was the way to go.

Anyway, I'll try with <object> too.

Tomorrow I'll come back and I'll let you know if the problem is solved or, if not, I'll write the HTML source generated by my php. However, I think everything is fine there.

Again, thank you guys.

 
Average of ratings: -
Picture of Luis de la Torre
Re: Embed an applet served by pluginfile.php
 

Hi again,


At this point I have already tried the <embed>, <applet> and <object> tags. All of them present the same problem I described in my first post.

Here is an example of the html code generated by my php code:

<applet code="FallingBall_pkg.FallingBallApplet.class"
  codebase="http://localhost/pluginfile.php/25/mod_ejsapp/jarfile/5/"
  archive="ejs_FallingBall.jar"
  name="ejs_FallingBall"
  id="ejs_FallingBall"
  width="800"
  height="600">
<param name="context_id" value="5"/>
<param name="user_id" value="2"/>
<param name="ejsapp_id" value="5"/>
<param name="language" value="en"/>
<param name="username" value="Admin User"/>
<param name="password" value="8560f4ae284f4930b22567fd7945f2b5"/>
<param name="moodle_upload_file" value="http://localhost/mod/ejsapp/upload_file.php"/>
</applet>
I can't see anything wrong there. I'll also try asking in a Java forum you suggested.
 
Average of ratings: -
Picture of Luis de la Torre
Re: Embed an applet served by pluginfile.php
 

Hi guys,

I know this is an old thread but I never really solved this issue sad

Can anybody clarify anything about this problem with the pluginfile.php script?

 
Average of ratings: -
Gareth J Barnard
Re: Embed an applet served by pluginfile.php
Group DevelopersGroup Particularly helpful Moodlers

Hi Luis,

Perhaps the 'codebase' is being confused by the php, so what if you remove it and specify the full path with pluginfile.php in the 'archive' attribute?

This is because I'm sure you are not using the 'pluginfile.php' as a URL within the jar file... http://stackoverflow.com/questions/5947063/how-to-specify-correctly-codebase-and-archive-in-java-applet

So it all depends on the folder stucture within the Jar file for the codebase attribute.  Given the value of the 'code' attribute, I'd leave codebase out.

Cheers,

Gareth

 
Average of ratings: -
Picture of Luis de la Torre
Re: Embed an applet served by pluginfile.php
 

Hi Gareth,

Thanks a lot for answering and for your suggestion! smile

I'm afraid I have also tried that in one of my many attempts, but it did not solve the problem. However, just to be sure I understood what you said, Im writing the html code of that attempt:

 

<applet code="FallingBall_pkg.FallingBallApplet.class"
  archive="http://localhost/pluginfile.php/25/mod_ejsapp/jarfile/5/ejs_FallingBall.jar"
  name="ejs_FallingBall"
  id="ejs_FallingBall"
  width="800"
  height="600">
<param name="context_id" value="5"/>
<param name="user_id" value="2"/>
<param name="ejsapp_id" value="5"/>
<param name="language" value="en"/>
<param name="username" value="Admin User"/>
<param name="password" value="8560f4ae284f4930b22567fd7945f2b5"/>
<param name="moodle_upload_file" value="http://localhost/mod/ejsapp/upload_file.php"/>
</applet>

I keep on getting these messages on my apache access.log file:

127.0.0.1 - - [27/Apr/2013:21:08:36 +0200] "HEAD /pluginfile.php/25/mod_ejsapp/jarfile/5/DefaultState.out HTTP/1.1" 404 - "-" "Mozilla/4.0 (Windows XP 5.1) Java/1.7.0_21"
127.0.0.1 - - [27/Apr/2013:21:08:39 +0200] "HEAD /pluginfile.php/25/mod_ejsapp/jarfile/5/DefaultState.out HTTP/1.1" 404 - "-" "Mozilla/4.0 (Windows XP 5.1) Java/1.7.0_21"
127.0.0.1 - - [27/Apr/2013:21:08:42 +0200] "HEAD /mod/ejsapp/DefaultState.out HTTP/1.1" 404 - "-" "Mozilla/4.0 (Windows XP 5.1) Java/1.7.0_21"
127.0.0.1 - - [27/Apr/2013:21:08:42 +0200] "HEAD /pluginfile.php/25/mod_ejsapp/jarfile/5/FallingBall_pkg/DefaultState.out HTTP/1.1" 404 - "-" "Mozilla/4.0 (Windows XP 5.1) Java/1.7.0_21"
127.0.0.1 - - [27/Apr/2013:21:08:48 +0200] "HEAD /mod/ejsapp/FallingBall_pkg/DefaultState.out HTTP/1.1" 404 - "-" "Mozilla/4.0 (Windows XP 5.1) Java/1.7.0_21"

And these on my apache error.log file:

[Sat Apr 27 21:08:36 2013] [error] [client 127.0.0.1] Default exception handler: Sorry, the requested file could not be found Debug: \r\nError code: filenotfound\n* line 467 of \\lib\\setuplib.php: moodle_exception thrown\n* line 1954 of \\lib\\filelib.php: call to print_error()\n* line 4250 of \\lib\\filelib.php: call to send_file_not_found()\n* line 38 of \\pluginfile.php: call to file_pluginfile()\n
[Sat Apr 27 21:08:39 2013] [error] [client 127.0.0.1] Default exception handler: Sorry, the requested file could not be found Debug: \r\nError code: filenotfound\n* line 467 of \\lib\\setuplib.php: moodle_exception thrown\n* line 1954 of \\lib\\filelib.php: call to print_error()\n* line 4250 of \\lib\\filelib.php: call to send_file_not_found()\n* line 38 of \\pluginfile.php: call to file_pluginfile()\n
[Sat Apr 27 21:08:42 2013] [error] [client 127.0.0.1] File does not exist: C:/Moodle/server/moodle/mod/ejsapp/DefaultState.out

(Both of them continues... these messages and errors are repeated more times; I just copied some of them).

Of course, the applet still takes to much time to be load...

It look like as if, for some reason, apache was trying to access this DefaultState.out file (which is inside of this particular applet... in other applets the requested file changes)
 
Average of ratings: -
Gareth J Barnard
Re: Embed an applet served by pluginfile.php
Group DevelopersGroup Particularly helpful Moodlers

Dear Luis,

From a Java point of view I think you have the solution.  However, looking at the debug of lines 1954 and 4250 of 'filelib.php' it could be that the jar file mime type is not allowed.  To check this, try seeing if the URL 'http://localhost/pluginfile.php/25/mod_ejsapp/jarfile/5/ejs_FallingBall.jar' works and serves the file.  At least, any error may point in the right direction.  Also examine the line numbers in your Moodle version's filelib.php.

Cheers,

Gareth

 
Average of ratings: -
Picture of Luis de la Torre
Re: Embed an applet served by pluginfile.php
 

Yup, using the URL "http://localhost/pluginfile.php/25/mod_ejsapp/jarfile/5/ejs_FallingBall.jar" in my web-browser works. It inmediatly opens a window to accept the download of the jar file.

No messages appear in the error.log file and, in the access.log file only this one is written:

127.0.0.1 - - [28/Apr/2013:13:09:17 +0200] "GET /pluginfile.php/25/mod_ejsapp/jarfile/5/ejs_FallingBall.jar HTTP/1.1" 200 1184763 "-" "Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0"

Which is ok.

The difference to the case in which I am embedding the applet is that HEAD is used instead of GET. I think that might be related to the problem: somehow, it seems HEAD method is not working perfectly fine for serving jar files, while GET does, of course.

Regarding lines 1954 and 4250 in my filelib.php file, these are them:

1951 function send_file_not_found() {
1952     global $CFG, $COURSE;
1953     send_header_404();
1954     print_error('filenotfound', 'error', $CFG->wwwroot.'/course/view.php?id='.$COURSE->id); //this is not displayed on IIS??
1955 }

4250 send_file_not_found();

But it seems to me these errors happen because, for some reason, the HEAD method is looking inside the applet and trying to serve some of the files that are in there (such as DefaullState.out in this example), rather than just serving the whole .jar file without caring about what's inside of it (just like the GET method seems to do).

 
Average of ratings: -
Walking on the snow towards Lago Nero...
Re: Embed an applet served by pluginfile.php
Group DevelopersGroup Particularly helpful Moodlers

Hi Luis,
it's Java and not Apache that searches for those files outside the jar archive.
Have you already tried:

<param name="codebase_lookup" value="false" />

and to add an index to your jar archive by issueing jar [-]i path/to/your.jar?

HTH,
Matteo

 
Average of ratings: -
Picture of Luis de la Torre
Re: Embed an applet served by pluginfile.php
 

Anyway, I have just created an issue about this topic in the Moodle Tracker.

If you would like to see this problem solved, please vote for it! smile

https://tracker.moodle.org/browse/MDL-39391

 
Average of ratings: -
Gareth J Barnard
Re: Embed an applet served by pluginfile.php
Group DevelopersGroup Particularly helpful Moodlers

Dear Luis,

Thanks for the additional information.  I think it is now a matter of working back from line 4250 up the call stack to determine what is happening and given the 'HEAD' information, what is being requested to determine why 'filelib.php' is sending a file not found.

Cheers,

Gareth

 
Average of ratings: -
Picture of Luis de la Torre
Re: Embed an applet served by pluginfile.php
 

Thank YOU for trying to help, Gareth smile

I hope I can see this issue solved sometime. It has been (and still is) quite frustating for me, I swear!

And not being able to properly embed applets (uploaded with the file API) in your Moodle webpages (well, you can, but they may take a lot of time to load) is definetely something that should be solved, in my opinion.

 
Average of ratings: -