in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 79 80 81 82 83 84 < 85 > 86 87 88 89 90 91 .. 166 >> Next

Most of the problems regarding the security model and browser versioning were nuisances that could be worked around. However, we could not get past the long download time of the application. Since the users were widely dispersed and had varying degrees of network communications, this could be an unbearable wait.
The solution to this problem is Java Web Start. Java Web Start is Sun's implementation of the Java Network Launching Protocol (JNLP) and is packaged with JDK 1.4. Java Web Start essentially consists of a specialized configuration file (with the "jnlp" extension) associated with a special MIME type, combined with the Java class loader to allow deployment of Java class files over HTTP. Since the class loading and Java Runtime Environment are configured in accordance with the JNLP, the class files can be cached and downloaded as needed. This provides a solution for centrally managing Java applications and allowing clients to cache Java classes locally. When a patch or change is released, it is propagated automatically out to the clients without your having to download all of the classes again.
Furthermore, Java Web Start provides the ability to update the Java Runtime Environment versions as necessary to suit the applications being deployed. Also, the Java Security model is consistent and built into Java Web Start. The "sandbox" is in effect by default, and the user must grant permissions as appropriate. An interesting thing to note is that you get the security sandbox in a full application context (i.e., a main method) without having to use the indirection execution of an applet.
230 Item 26
Examining the JNLP file format provides a great deal of insight into the capabilities of Java Web Start. Listing 26.1 is an example file.
01 <?xml version="1.0" encoding="utf-8"?>
02 <!-- JNLP File for Analyst's Toolkit Demo Application -->
03 <jnlp
04 spec="1.0+"
05 codebase=""
06 href="toolkit.jnlp">
07 <information>
08 <title>Analyst's Toolkit</title>
09 <vendor>McDonald-Bradley, Inc.</vendor>
10 <homepage href="docs/help.html"/>
11 <description>Analyst's Toolkit Application</description>
12 <description kind="tooltip">The Analyst's Toolkit</description>
13 <icon href=""/>
14 <offline-allowed/>
15 </information>
16 <security>
17 <all-permissions/>
18 </security>
19 <resources>
20 <j2se version="1.4"/>
21 <j2se version="1.3"/>
22 <jar href="lib/toolkit.jar"/>
23 </resources>
24 <application-desc main-class="Toolkit"/>
25 </jnlp>
Listing 26.1 toolkit.jnlp
This file shows the configuration of the Java Web Start software. There are four different subsections in the JNLP file: information, security, resources, and application.
The information element provides the display information for the user to view the application before having to run it. It provides descriptions, icons, vendor, and title. However, there is one more interesting tag in the information element: <offline-allowed/>. This means that the Web Start application can be run without being connected to the network! This is another advantage over applets.
The security element defines the permissions needed to run this application. If the <all permissions> tag is not used, then the application runs within the sandbox by default (as it would if the user chose not to grant permissions). Note that if the <all-permissions> tag is used, then all JAR files must be signed.
When Applets Go Bad 231
The resources element specifies how the system should download resources like JAR files and native libraries. Also, it specifies the version of the JRE that is required to run the application, as well as the preference order by which compatible ones should be used. For instance, in the example above, both the JRE 1.4 and 1.3 are allowed as compatible JREs, and JRE 1.2 is not. It prefers JRE 1.4 but will settle for JRE 1.3. The native libraries can be specified in terms of the operating systems with which they are compatible. Also, all resources can be specified as to whether they should be downloaded in an eager or lazy mode—that is, whether they should be downloaded immediately or as allowable.
Figure 26.2 is an example of what happens when a client requests a Java Web Start application.
The question becomes how to check on whether or not JNLP is installed. The way to handle this is to use a client-side script to ask the browser whether it can handle the application/x-java-jnlp-file MIME type. Listing 26.2 is the example provided by Sun in the Java Web Start developer's kit ( /javawebstart/docs/developersguide.html):
Download and Install Java Web Start
Launch MIME plug-in for JNLP (Web Start)
232 Item 26
01 <SCRIPT LANGUAGE="Javascript">
02 var javawslnstalled = 0;
03 isIE = "false";
05 if (navigator.mimeTypes && navigator.mimeTypes .length) {
06 x = navigator.mimeTypes['application/x-java- jnlp-file'];
Previous << 1 .. 79 80 81 82 83 84 < 85 > 86 87 88 89 90 91 .. 166 >> Next