Solved

bootstrapping big applet via https

Posted on 2001-08-07
19
587 Views
Last Modified: 2013-11-23
We have a very big applet on an https site. The task is to write a small applet which starts at once and tells the user to wait for the big applet and disappears when the big applet loaded.

My solution is to use two applets on the same page, the small one first, then the big one. The small one watches till the second one is loaded, and this worked very fine. Then suddenly this doesn't work any more: Both applets are waiting till the big one is loaded.

Does someone know about how several applets on the same page are initialized?
0
Comment
Question by:dnoelpp
  • 9
  • 9
19 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 6360253
Hi,

     Try the following code. I hope this would help you


import java.net.*;  // URL
import java.awt.*;  // Image, MediaTracker
import java.applet.Applet;

/** A simple class that loads an image over the net, waiting until
 * the image is loaded until continuing. Also lets you pass a string


 * <P>
 * Example:
 * <PRE>
 *   import ImageWait;
 *<P>
 *   public class Foo extends Applet {
 *     Image duke
 *<P>
 *     public void init () {
 *      ImageWait iw = new ImageWait(this);
 *      duke = iw.getImage("http://java.sun.com/lib/images/duke.gif");
 *      }
 *<P>
 *      public void paint(Graphics g) {
 *        g.drawImage(duke);
 *      }
 *   }
 * </PRE>

public class ImageWait {

  // The Applet on which the drawImage will be performed.
  Applet applet;
 
  //--------------------------------------------------------------

  /** Sets the applet to be associated with the MediaTracker,
   *  (which does the checking to see if the image is done loading).
   *
   * @param applet The applet in which the image will be drawn.
   */
   
  public ImageWait(Applet applet) {
    this.applet = applet;
  }
 
  //--------------------------------------------------------------

  private Image waitForLoading(Image image, String urlString) {
    MediaTracker tracker = new MediaTracker(applet);
    tracker.addImage(image, 0);
    try {
      tracker.waitForID(0);
    } catch (InterruptedException i) {
    } catch (Exception e) {    
      System.out.println("[ImageWait.waitForLoading], exception " +
                e.getMessage());
      e.printStackTrace();
    }
    if (tracker.isErrorID(0)) {
      System.out.println("Error loading image " + urlString);
      return(null);
    }
    return(image);
  }
 
  //--------------------------------------------------------------

  /** Loads the specified image, <B>waiting until the image is done
   *  loading before continuing.</B> Passing a string lets you
   *  skip embedding the try/catch in the new URL... call in the Applet.
   *
   * @param urlString A String representing the URL of the image.
   * @return The image specified (or null if URL can't be found).
   */
  public Image getImage(String urlString) {
    URL url = null;
    Image image = null;
   
    try {
      url = new URL(urlString);
    } catch (MalformedURLException e) {
      System.out.println("Malformed URL: " + urlString);
      return(null);
    }
    image = applet.getImage(url);
    return(waitForLoading(image, urlString));
  }

  /** Loads the specified image, <B>waiting until the image is done
   *  loading before continuing.</B>
   *
   * @param url A URL object for the image.
   * @return The image specified (or null if URL can't be found).
   */
  public Image getImage(URL url) {
    Image image = applet.getImage(url);
    return(waitForLoading(image, url.toExternalForm()));
  }
 
  /** Loads the specified image, <B>waiting until the image is done
   *  loading before continuing.</B>
   *
   * @param url A URL object for the directory of the image.
   * @param relativePathname A String of the filename of the image in
   *        the directory.
   * @return The image specified (or null if URL can't be found).
   */
  public Image getImage(URL url, String relativePathname) {
    Image image = applet.getImage(url, relativePathname);
    return(waitForLoading(image, url.toExternalForm() + relativePathname));
  }

  //--------------------------------------------------------------
}

:-)

bye

Mohan
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6362672
No, that's not a solution! I am not waiting for an image being loaded. Please read my question more carefully. Thanks.
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6362906
did you suddenly put your applets in a cab or jar?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 3

Author Comment

by:dnoelpp
ID: 6362953
Yes, but is this really the cause? Because the waiting applet is in a different .jar file than the big applet.
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6362969
Anyway, I have found this solution:

Replace the first applet with JavaScript animation. This animation is stopped when it discovers the applet got loaded. How to discover it? It watches the status bar. Hahahaha! That simple! :-)

Or am I mistaken? Please give your comment, there are still some points to be given for you!
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6363269
yes, the cause is that you put your applets in a cab file. the browser wait for the cab(s) to download, and than starts the applets.

how big is your applet?


your java script can 'discover' that the applet is loaded by checking the applet isReady() method.


0
 
LVL 4

Accepted Solution

by:
omry_y earned 100 total points
ID: 6363481
oops.
the method is applet.isActive(), not applet.isReady().
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6363486
Yes, it could be... Even if both applets have different .jar files. The small .jar file is about 2 kB big, the big one I still don't know, but about 1 MB. The problem is that the applet isn't just used in an intranet (that's why https), but it will be used by a very small clientele outside the customer's company. They will be told that they have to wait for about ten minutes first time, and then later perhaps only one minute. The applets are Swing applets, that's an additional twist because of the installation need of the JRE.

A possibility would have been to bundle JSSE into the small applet and use an URLClassloader to bootstrap the big applet. But the applet is used in a context of an authorizing manager which works with cookies. Without these cookies no file can be retrieved by the https connection...

And isReady() is cross-browser?
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6363536
1.you depend on the browser cache for it?
its not really trust worthy..

isActive (not isReady) is a method in java.applet.Applet, so its cross browser.
an applet is ready after the init (or start, I dont remember exactly) is called.
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6363578
Okay, isActive() is an java.applet.Applet method. So no help to call it from Javascript. :-( I know, Netscape makes it possible to call applet methods from JavaScript, but Internet Explorer...?

As for the browser cache the idea is that the user get the feeling the computer is still working while it is loading the big applet. So, if the big applet is already in the cache, it doesn't matter what the small applet is doing, because the big applet started up very soon.
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6363623
this is how you call an applet in explorer, it should also work for netscape, but I am not sure.

document.applets("AppletName").isActive()


say.. how much is your company willing to pay for a solution that will cache the applet in the user hard disk permenently, show the user a download progress report while updating, and that will allow you to update the applet for the user at a granularity of a single file (class file, gif, whatever)?
I am asking becasue I have developed such a solution for my company, and maybe, just maybe, we will be interested in selling it.

if you want to have a look, you can see it at
http://212.150.35.81/mapapplet/index.html

to un-install, go to explorer java home directory, (probably in c:\winnt\java or c:\windows\java)
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6363629
and delete the com directory.
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6363644
The problem is https. Say, your applet is using an URL instance to bootstrap other applets, isn't it. This doesn't work for us. We can only load data via the browser. (for example with showDocument()).
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6363679
why use https in the first place?
can`t you put the applet on a regular http server?
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6363705
This is a project requirement. Everything what belongs to the project is homed within an authorization manager. Each request is done within https and some cookies set by the authorization manager. To use URL we would need to integrate part of JSSE into the bootstrapper and secondly retrieve the cookies (they could passed in as parameters by the JSP page hosting the applet) and thirdly pass them to the URL. This is too much of an effort just for a small bootstrapper. Keep in mind, we have a limited clientele and they can be instructed very well not to run away when the applet loads. Thanks for your offer.
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6364031
okay.
so, did the isActive thing worked?
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6364058
I didn't try it out. Since watching the status bar effectively worked... It's on my todo list to experiment with it later, because this will mean that JavaScript code can call applet methods... I think, this doesn't work with IE.
0
 
LVL 4

Expert Comment

by:omry_y
ID: 6364112
it does work with IE for sure.
(tested)
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6364153
Thanks for the comments.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question