[Openjnlp-devel] OpenJNLP patches for extraneous retrieval of launch URLs
Brought to you by:
kherr
From: Nathan M. <nm...@vi...> - 2002-11-26 18:41:53
|
Hello again, Following up on our recent conversations, here are some OpenJNLP patches to address the extraneous repeated retrieval of launch URLs. - JNLPParser.URLJNLPParser.openInputStream(): Return the InputStream from the connection recently opened, rather than launching a new connection. - JNLPParser.CachedJNLPParser.openInputStream(): avoid updating a resource that was just fetched. - CachedResource.update(): Do not query the resource for last modified time; instead, GET it with an If-Modified-Since request header. This addresses most of the extraneous GETs and HEADs of the launch URL. There is still one case that will require a bit more intricacy to address: OpenJNLP depends on finding an existing cache entry, even though it will not be used because it is out of date. If no such entry exists, it will be fetched, stored in the cache, and subsequently not used. This behavior cannot be stopped by supplying a <jnlp> element without an "href" attribute. I cannot guarantee that these changes do not violate some important assumptions about some cached or remote resources - but I don't think they do. Nathan Meyers nm...@vi... Index: src/org/nanode/jnlp/JNLPParser.java =================================================================== diff -u -r1.1.1.1 JNLPParser.java --- src/org/nanode/jnlp/JNLPParser.java 18 Nov 2002 12:04:18 -0000 1.1.1.1 +++ src/org/nanode/jnlp/JNLPParser.java 26 Nov 2002 18:18:06 -0000 @@ -490,7 +490,7 @@ throw new IOException("Bad MIME type: " + uc.getContentType()); } - return srcURL.openStream(); + return uc.getInputStream(); } } @@ -537,11 +537,15 @@ try { // if descriptor not cached yet, add it to cache - if (!cacheEntry.isResourceCached(ref) && !cacheEntry.addResource(ref)) { - throw new IOException("failed to add descriptor to cache for " + cacheEntry.getTitle()); + boolean doUpdate = true; + if (!cacheEntry.isResourceCached(ref)) { + doUpdate = false; + if (!cacheEntry.addResource(ref)) + throw new IOException("failed to add descriptor to cache for " + cacheEntry.getTitle()); } - if ((res = cacheEntry.getResource(ref, true)) == null) { + // Get the resource, updating it if we didn't just fetch it + if ((res = cacheEntry.getResource(ref, doUpdate)) == null) { throw new IOException("descriptor not in cache"); } } catch (Exception e) { Index: src/org/nanode/launcher/cache/CachedResource.java =================================================================== diff -u -r1.1.1.1 CachedResource.java --- src/org/nanode/launcher/cache/CachedResource.java 18 Nov 2002 12:04:18 -0000 1.1.1.1 +++ src/org/nanode/launcher/cache/CachedResource.java 26 Nov 2002 18:18:06 -0000 @@ -138,12 +138,6 @@ } public boolean update() { - long remoteLastModified = getRemoteLastModified(); - - if (remoteLastModified == 0L || remoteLastModified <= lastModified) { - return false; - } - // do a cache update synchronized (reference) { statistics.reset(); @@ -153,6 +147,11 @@ try { URLConnection uc = reference.getURL().openConnection(); + uc.setIfModifiedSince(lastModified); + if (uc instanceof HttpURLConnection + && ((HttpURLConnection) uc).getResponseCode() + == HttpURLConnection.HTTP_NOT_MODIFIED) + return false; lastModified = uc.getLastModified(); statistics.contentLength = uc.getContentLength(); @@ -182,7 +181,6 @@ } } - lastModified = remoteLastModified; } catch (Exception e) { System.err.println(e); statistics.aborted = true; |