Solved

bootstrapping big applet via https

Posted on 2001-08-07
19
577 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
allStar challenge 1 41
pairs challenge 5 44
wordmultiple challenge 12 90
Error with Java/Cache JDBC Classpath 2 20
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now