How to embed an applet in cougaar

Todd Wright twright at bbn.com
Wed Nov 29 21:05:06 EST 2006


Ah, okay.  I think the Applet is optional, as I'll note below.  Either 
way, what you've proposed should work:

   1) Your Cougaar servlet writes an HTML page telling the browser
      the name of the Applet class and where to get the Applet jar.
      Note that the Applet runs inside the *browser* JVM, not the
      Cougaar/Tomcat JVM.  You can't literally "embed an applet in
      cougaar".

   2) The browser then connects back to your "/fileServer" servlet to
      download the Applet jar.  Presumably your "/fileServer" servlet
      is based on:
http://cougaar.org/cgi-bin/viewcvs.cgi/core/examples/org/cougaar/core/examples/servlet/FileServerServlet.java?rev=1.1&cvsroot=core&content-type=text/vnd.viewcvs-markup
      It'll look for the jar on the ConfigPath and will write the
      jar data on the servlet stream, back to the browser.

   3) The Applet loads in the browser, prompts the user for a file to
      upload, then posts the file content to the upload URL.  The
      Applet makes a URL connection to your Cougaar
      "/multiFileSelectServlet" and writes the file data.

   4) Your "/multiFileSelectServlet" will need to parse the "doPost(..)"
      response, which will likely be encoded as "multipart/form-data".
      You might want to use a multipart parsing library, such as the
      "MultipartParser" of:
         http://www.servlets.com/cos
      Or you can parse this yourself, since the format is well
      documented:
         http://www.faqs.org/rfcs/rfc1867.html

   5) The "/multiFileSelectServlet" servlet can save the file data
      to a local file or process it however you like.

As noted above, for most cases an Applet is not required.  There's HTML 
to do this, e.g.:
   <html><body>
   <form method="POST" enctype="multipart/form-data"
     action="http://localhost:8800/multiFileSelectServlet">
     Upload file:<br>
     <input name="message" type="file">
     <input type="submit" value="Send file to server">
   </form>
   </body></html>
If you save the above HTML as a "test.html" and load it in a browser, 
you'll see that your browser can popup a full-featured file selector. 
This will avoid the above steps (2) and (3).

If you still want to use the Applet, e.g. to use some advanced features 
provided by the "jupload" code, then try pointing your browser at:
   http://localhost:8800/fileServer?name="wjhk.jupload.jar"
and make sure it can access the jar file.  Maybe the URL is invalid. 
Also see your browser's Java console logs.  This is available in Firefox 
via a browser extension:
   https://update.mozilla.org/firefox/60/

Lastly, as noted above, the somewhat awkward part is implementing the 
"doPost(..)" method in your servlet.  The O'Reilly MultipartParser makes 
this easy.  See their website for examples.

Todd

Ajay Chitturi wrote:
> Hello all
> 
>  
> 
>  
> 
> My goal is to have users the ability to browse directories and multiple 
> files, in order to upload them to webtomcat running inside cougaar.
> 
>  
> 
> My approach was to use source forge, jupload 
> (http://sourceforge.net/projects/jupload/)
> 
> But that uses an applet.
> 
>  
> 
> I struggled to get embed an applet inside cougaar, here is my approach 
> (following code is inside a servlet , doGet method)
> 
>  
> 
>       out.println("<html>");
> 
>       out.println("<applet CODE=\"wjhk.jupload2.JUploadApplet.class\" "
> 
>           + "ARCHIVE=\"$"
> 
>           + getNodeIdentificationService().getMessageAddress().getAddress()
> 
>           + "/fileServer?name=\"wjhk.jupload.jar\" "
> 
>           + "WIDTH=\"640\" HEIGHT=\"300\">");
> 
>       out
> 
>           .println("<PARAM NAME = CODE VALUE = 
> \"wjhk.jupload2.JUploadApplet\" >");
> 
>       out.println("<PARAM NAME = ARCHIVE VALUE = \"$"
> 
>           + getNodeIdentificationService().getMessageAddress().getAddress()
> 
>           + "/fileServer?name=wjhk.jupload.jar\" >");
> 
>       out.println("<PARAM NAME=\"type\" "
> 
>           + "VALUE=\"application/x-java-applet;version=1.4\">");
> 
>       out.println("<PARAM NAME=\"scriptable\" VALUE=\"false\">");
> 
>       out.println("<PARAM NAME = \"postURL\" VALUE "
> 
>           + "=\"/multiFileSelectServlet?URLParam=URL+Parameter+Value\">");
> 
>       out.println("<PARAM NAME = \"nbFilesPerRequest\" VALUE =\"2\">");
> 
>       out.println("</applet>");
> 
>       out.println("</html>");
> 
>  
> 
>  
> 
> I tried to give the jar file as a URI in “ARCHIVE” as well
> 
> I placed the “wjhk.jupload.jar” in $CIP/sys, 
> $CIP/webtomcat/data/webapps, $CIP/webtomcat/data/webapps/ROOT and is 
> available to the configfinder as well.
> 
>  
> 
> All my attempts to embed the applet seem to be futile
> 
> Finally I end up with a classnotfound exception
> 
>  
> 
> java.lang.ClassNotFoundException: wjhk.jupload2.JUploadApplet
> 
>             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 sun.applet.AppletClassLoader.loadCode(Unknown Source)
> 
>             at sun.applet.AppletPanel.createApplet(Unknown Source)
> 
>             at sun.plugin.AppletViewer.createApplet(Unknown Source)
> 
>             at sun.applet.AppletPanel.runLoader(Unknown Source)
> 
>             at sun.applet.AppletPanel.run(Unknown Source)
> 
>             at java.lang.Thread.run(Unknown Source)
> 
> Caused by: java.io.IOException: open HTTP connection failed.
> 
>             at sun.applet.AppletClassLoader.getBytes(Unknown Source)
> 
>             at sun.applet.AppletClassLoader.access$100(Unknown Source)
> 
>             at sun.applet.AppletClassLoader$1.run(Unknown Source)
> 
>             at java.security.AccessController.doPrivileged(Native Method)
> 
>             ... 10 more
> 
>  
> 
> Please help me in embedding an applet within cougaar’s tomcat.
> 
>  
> 
>  
> 
> Thanks in advance
> 
>  
> 
> Ajay Chitturi
> 
> Software Engineer
> 
> Cougaar Software, Inc. 
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Cougaar-developers mailing list
> Cougaar-developers at cougaar.org
> http://cougaar.org/mailman/listinfo/cougaar-developers



More information about the Cougaar-developers mailing list