The JNLP specification defines four different kinds of download requests
that Java Web Start (or more generally, a JNLP Client) can make to
a server when requesting a resource:
- Basic Download Request: This is an ordinary URL request to a specific
file. The Last-Modified field of the response is used to determine
if an update is available on the server. The basic download request can be
used for all resource types.
- Version-based Download Request: This request type can be used for JAR files
and images, i.e., the following elements will generate a version-based download
request: <jar>, <nativelib>, and <icon>, when
the version attribute is included.
- Extension Download Request: This request type is an extension of the
version-based request type and is generated by either the <j2se>
or <extension> elements. In addition to the version information, it
also contains information about operating system, system architecture, and locale.
- Platform-version Download Request: This is simliar to the extension download request,
but used to request a particular version of the Java 2 SE Runtime Environment (J2RE). This request
is generated by Java Web Start, when a JNLP file has requested a particular version of the
J2RE that is not currently installed on the client system.
A request is initially processed by the JNLPDownloadServlet, and it extracts the
following information from the request:
- Path in WAR file,
- Name of requested file
- Version string (version-id parameter or platform-version-id parameter)
- Current version-id (current-version-id parameter)
- List of operation systems (os parameter)
- List of architectures (arch parameter)
- List of locales (locale parameter)
Consider example2, and assume that it is being hosted at
http://www.mytool.com/tool2/. If the following requests is made:
http://www.mytool.com/tool2/app/lib.jar&version-id=2.1. Then the
path of the resource would be, app/, the name would be lib.jar,
the version string would be 2.1, and the lists for os, architecture, and locales
would be empty.
A request to a directory, e.g., http://www.mytool.com/tool2/app/, will get appended
the default filename: launch.jnlp. Thus, it would be the same as http://www.mytool.com/tool2/app/launch.jnlp.
Handling a basic download request
A request for which no version-id is specified (neither version-id parameter or platform-version-id parameter is
specified in the request) is handled as a basic download request.
The request is first checked to see if it contains a double underscore (__) or is a request to
the version.xml file. If so, the request is rejected and a HTTP 404 error code is returned.
The JnlpDownloadServlet will then try to locate the resource with the given path and name in
the WAR file, and if found return it. If the resource is not found, a HTTP 404 error code is returned for the request.
If a match is found and it is a JNLP file, then it is preprocessed as described below
before returned.
Handling a version-based download request
The resource lookup for resources with a version-id is uniform across the version-based download protocol, the extension
download protocol, and the platform-version download request.
First, the JnlpDownloadServlet will build a database of all the resources that are located in the WAR file
directory that the URL request is accessing (based on the path in the request). The database is built by scanning
the version.xml file (if present), and the list of files in the directory that is using the naming convention
described above. The servlet caches the information internally. It only does a re-scan if the timestamp of the version.xml
file is more recent than at the last scan. Thus, if you add a file using the naming convention, make sure to touch the version.xml
file to force the servlet to do a re-scan.
Secondly, the servlet will scan through the entries in the database to find a match for the given request (the match
rules are described below). For a non-platform request, first the resource entries in the version.xml
file are scanned in the order they are specified, and then secondly the entries that are specified using the naming
convention. For a platform-version request, the platform entries in the version.xml file is scanned
in the order they are specified. If several entries matches the request, then the entry with the
highest version-id is returned. If multiple matches is found with the same highest version-id, then the first one
specified is returned.
The matching rules are as follows:
- The name of the resource must match the request
- The version-id of the resource must match the version string in the request
- For the os, arch, and locale lists the following rules are used:
- If an empty list is specified for the resource, then it is a match
- If a non-empty list is specified for the resource, then it is a match, if
at least one of the values specified for the resource is a prefix of
at least one of the values specified in the request.
The x-java-jnlp-version-id returned in the response is the version-id for the matching resource, except for a
platform request where it is taken from the <product-version-id> field in the version.xml file.
If a match is found and it is a JNLP file, then it is preprocessed as described below before returned.
Automatic JARDiff generation
The servlet will automatically generate and return incremental updates to JAR files, if possible. If
the current-version-id parameter is included in the request and the servlet can find both a
match on the current-version-id and the requested version (given the above matching rules) and
the request is for a JAR file (e.g., the target resource has the .jar extension), then a JARDiff
file will be generated by the servlet. The JARDiff file is returned as long as its size is less than
that of the requested version.
The JARDiff file is generated and stored in a temporary directory that is specific to the given Web
container. The servlet locates the temporary working directory using the javax.servlet.context.tempdir
context attribute.