# HG changeset patch # User Jiri Vanek # Date 1372420957 -7200 # Node ID be23db7861a6371608b64e5dfc4d86179a481bca # Parent b1b17bb14ab056a85926f3454e7a2055c372e9cf JNLP file is now re-downloading only if is local and have href. Real couse of PR1473 diff -r b1b17bb14ab0 -r be23db7861a6 ChangeLog --- a/ChangeLog Thu Jun 20 15:26:14 2013 +0200 +++ b/ChangeLog Fri Jun 28 14:02:37 2013 +0200 @@ -1,3 +1,21 @@ +2013-06-24 Jiri Vanek + + JNLP file is now re-downloading only if is local and have href + * /netx/net/sourceforge/jnlp/Launcher.java: (launch) api cleared + from (fromSource). (fromUrl) removed always re-downloading code and + replaced by conditional. (launchBackground), (toFile), (BgRunner) + removed. + * netx/net/sourceforge/jnlp/runtime/Boot.java: following new (launch) + * tests/reproducers/simple/GeneratedId/srcs/GeneratedId.java: just + arguments reprinting application + * tests/reproducers/simple/GeneratedId/testcases/GeneratedIdTest.java + various tests based on href/no href x local/remote jnlp files + * tests/reproducers/simple/GeneratedId/resources/GeneratedId.jnlp: base + simple jnlp with someId argument + * tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java: reprinting + the get/head correctly and with echo + * NEWS: mentioned PR1473 + 2013-06-20 Jiri Vanek Made it work with OpenJDK build 25 diff -r b1b17bb14ab0 -r be23db7861a6 NEWS --- a/NEWS Thu Jun 20 15:26:14 2013 +0200 +++ b/NEWS Fri Jun 28 14:02:37 2013 +0200 @@ -11,6 +11,7 @@ New in release 1.4.1 (2013-XX-YY): * NetX - PR1465 - java.io.FileNotFoundException while trying to download a JAR file + - PR1473 - javaws should not depend on name of local file * Plugin - PR854: Resizing an applet several times causes 100% CPU load diff -r b1b17bb14ab0 -r be23db7861a6 netx/net/sourceforge/jnlp/Launcher.java --- a/netx/net/sourceforge/jnlp/Launcher.java Thu Jun 20 15:26:14 2013 +0200 +++ b/netx/net/sourceforge/jnlp/Launcher.java Fri Jun 28 14:02:37 2013 +0200 @@ -264,30 +264,18 @@ return tg.getApplication(); } - /** - * Launches a JNLP file by calling the launch method for the - * appropriate file type. - * - * @param location the URL of the JNLP file to launch - * @throws LaunchException if there was an exception - * @return the application instance - */ - public ApplicationInstance launch(URL location) throws LaunchException { - return launch(toFile(location)); - } /** * Launches a JNLP file by calling the launch method for the * appropriate file type. * * @param location the URL of the JNLP file to launch - * @param fromSource if true, the JNLP file will be re-read from the source * location to get the pristine version * @throws LaunchException if there was an exception * @return the application instance */ - public ApplicationInstance launch(URL location, boolean fromSource) throws LaunchException { - return launch(fromUrl(location, fromSource)); + public ApplicationInstance launch(URL location) throws LaunchException { + return launch(fromUrl(location)); } /** @@ -376,28 +364,7 @@ } } - /** - * Launches a JNLP file by calling the launch method for the - * appropriate file type in a different thread. - * - * @param file the JNLP file to launch - */ - public void launchBackground(JNLPFile file) { - BgRunner runner = new BgRunner(file, null); - new Thread(runner).start(); - } - - /** - * Launches the JNLP file at the specified location in the - * background by calling the launch method for its file type. - * - * @param location the location of the JNLP file - */ - public void launchBackground(URL location) { - BgRunner runner = new BgRunner(null, location); - new Thread(runner).start(); - } - + /** * Launches the JNLP file in a new JVM instance. The launched * application's output is sent to the system out and it's @@ -477,60 +444,38 @@ /** * Returns the JNLPFile for the URL, with error handling. */ - private JNLPFile fromUrl(URL location, boolean fromSource) throws LaunchException { + + private JNLPFile fromUrl(URL location) throws LaunchException { try { JNLPFile file = null; file = new JNLPFile(location, parserSettings.isStrict()); + + boolean isLocal = false; + boolean haveHref = false; + if ("file".equalsIgnoreCase(location.getProtocol()) && new File(location.getFile()).exists()) { + isLocal = true; + } + if (file.getSourceLocation() != null) { + haveHref = true; + } - if (fromSource) { - // Launches the jnlp file where this file originated. - if (file.getSourceLocation() != null) { - file = new JNLPFile(file.getSourceLocation(), parserSettings.isStrict()); - } + if (isLocal && haveHref) { + file = new JNLPFile(file.getSourceLocation(), parserSettings.isStrict()); } return file; } catch (Exception ex) { - if (ex instanceof LaunchException) + if (ex instanceof LaunchException) { throw (LaunchException) ex; // already sent to handler when first thrown - else + } else { // IO and Parse throw launchError(new LaunchException(null, ex, R("LSFatal"), R("LCReadError"), R("LCantRead"), R("LCantReadInfo"))); + } } } - - /** - * Returns the JNLPFile for the URL, with error handling. - */ - @Deprecated - private JNLPFile toFile(URL location) throws LaunchException { - try { - JNLPFile file = null; - - try { - file = new JNLPFile(location, (Version) null, true, updatePolicy); // strict - } catch (ParseException ex) { - file = new JNLPFile(location, (Version) null, false, updatePolicy); + - // only here if strict failed but lax did not fail - LaunchException lex = - launchWarning(new LaunchException(file, ex, R("LSMinor"), R("LCFileFormat"), R("LNotToSpec"), R("LNotToSpecInfo"))); - - if (lex != null) - throw lex; - } - - return file; - } catch (Exception ex) { - if (ex instanceof LaunchException) - throw (LaunchException) ex; // already sent to handler when first thrown - else - // IO and Parse - throw launchError(new LaunchException(null, ex, R("LSFatal"), R("LCReadError"), R("LCantRead"), R("LCantReadInfo"))); - } - } - - /** + /** * Launches a JNLP application. This method should be called * from a thread in the application's thread group. */ @@ -998,31 +943,6 @@ }; - /** - * This runnable is used by the launchBackground - * methods to launch a JNLP file from a separate thread. - */ - private class BgRunner implements Runnable { - private JNLPFile file; - private URL location; - - BgRunner(JNLPFile file, URL location) { - this.file = file; - this.location = location; - } - - public void run() { - try { - if (file != null) - launch(file); - if (location != null) - launch(location); - } catch (LaunchException ex) { - // launch method communicates error conditions to the - // handler if it exists, otherwise we don't care because - // there's nothing that can be done about the exception. - } - } - }; + } diff -r b1b17bb14ab0 -r be23db7861a6 netx/net/sourceforge/jnlp/runtime/Boot.java --- a/netx/net/sourceforge/jnlp/runtime/Boot.java Thu Jun 20 15:26:14 2013 +0200 +++ b/netx/net/sourceforge/jnlp/runtime/Boot.java Fri Jun 28 14:02:37 2013 +0200 @@ -208,7 +208,7 @@ Launcher launcher = new Launcher(false); launcher.setParserSettings(settings); launcher.setInformationToMerge(extra); - launcher.launch(getFileLocation(), true); + launcher.launch(getFileLocation()); } catch (LaunchException ex) { // default handler prints this } catch (Exception ex) { diff -r b1b17bb14ab0 -r be23db7861a6 tests/reproducers/simple/GeneratedId/resources/GeneratedId.jnlp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/reproducers/simple/GeneratedId/resources/GeneratedId.jnlp Fri Jun 28 14:02:37 2013 +0200 @@ -0,0 +1,51 @@ + + + + + + + Test Generated Id + IcedTea + + + + + + SomeId + + diff -r b1b17bb14ab0 -r be23db7861a6 tests/reproducers/simple/GeneratedId/srcs/GeneratedId.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/reproducers/simple/GeneratedId/srcs/GeneratedId.java Fri Jun 28 14:02:37 2013 +0200 @@ -0,0 +1,44 @@ +/* Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + + +public class GeneratedId { + static public void main(String[] args) { + for(int x = 0; x l = new ArrayList(3); + l.add(server.getJavawsLocation()); + l.add(ServerAccess.HEADLES_OPTION); + l.add(dest.getAbsolutePath()); + ProcessResult pr = ServerAccess.executeProcess(l); + Assert.assertTrue("Stdout should contain '" + okBase1 + "', but did not.", pr.stdout.contains(okBase1)); + } + + @Test + //do not have href + //is local + //should NOT be redownloaded + public void launchLocalChangedFileWithNoHref() throws Exception { + File dest = prepareChangedFileNoHref(); + List l = new ArrayList(3); + l.add(server.getJavawsLocation()); + l.add(ServerAccess.HEADLES_OPTION); + l.add(dest.getAbsolutePath()); + ProcessResult pr = ServerAccess.executeProcess(l); + Assert.assertTrue("Stdout should contain '" + okBase2 + "', but did not.", pr.stdout.contains(okBase2)); + } + + @Test + //do have href + //is local + //should be redownloaded (how to verify!?!) + public void launchLocalFileWithHref() throws Exception { + File dest = new File(server.getDir(), baseName1); + List l = new ArrayList(3); + l.add(server.getJavawsLocation()); + l.add(ServerAccess.HEADLES_OPTION); + l.add(dest.getAbsolutePath()); + ProcessResult pr = ServerAccess.executeProcess(l); + Assert.assertTrue("Stdout should contain '" + okBase1 + "', but did not.", pr.stdout.contains(okBase1)); + } + + @Test + //do not have href + //is local + //should NOT be redownloaded (how to verify!?!) + public void launchLocalFileNoHref() throws Exception { + File dest = prepareCopiedFileNoHref(); + List l = new ArrayList(3); + l.add(server.getJavawsLocation()); + l.add(ServerAccess.HEADLES_OPTION); + l.add(dest.getAbsolutePath()); + ProcessResult pr = ServerAccess.executeProcess(l); + Assert.assertTrue("Stdout should contain '" + okBase1 + "', but did not.", pr.stdout.contains(okBase1)); + } + + @Test + //remote + //have href + //should not be redownloaded (how to verify!?!) + //href is same file + public void launchRemoteFileWithHref() throws Exception { + ProcessResult pr = server.executeJavawsHeadless("/" + baseName1); + Assert.assertTrue("Stdout should contain '" + okBase1 + "', but did not.", pr.stdout.contains(okBase1)); + } + + //remote + //have href + //should NOT be redownloaded + //href is different file + @Test + public void launchRemoteChangedFileWithHref() throws Exception { + File f = prepareChangedFileWithHref(); + ProcessResult pr = server.executeJavawsHeadless("/" + f.getName()); + Assert.assertTrue("Stdout should contain '" + okBase2 + "', but did not.", pr.stdout.contains(okBase2)); + } + + @Test + //remote + //have not href + //should not be redownloaded (how to verify!?!) + public void launchRemoteFileWithNoHref() throws Exception { + File f = prepareCopiedFileNoHref(); + ProcessResult pr = server.executeJavawsHeadless("/" + f.getName()); + Assert.assertTrue("Stdout should contain '" + okBase1 + "', but did not.", pr.stdout.contains(okBase1)); + } + + //remote + //have not href + //should NOT be redownloaded + @Test + public void launchRemoteChangedFileWithNoHref() throws Exception { + File f = prepareChangedFileNoHref(); + ProcessResult pr = server.executeJavawsHeadless("/" + f.getName()); + Assert.assertTrue("Stdout should contain '" + okBase2 + "', but did not.", pr.stdout.contains(okBase2)); + } +} diff -r b1b17bb14ab0 -r be23db7861a6 tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java --- a/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java Thu Jun 20 15:26:14 2013 +0200 +++ b/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java Fri Jun 28 14:02:37 2013 +0200 @@ -114,8 +114,15 @@ o.writeBytes("HTTP/1.0 "+HttpURLConnection.HTTP_NOT_IMPLEMENTED+" Not Implemented\n"); continue; } - + + String request = "unknown"; if (isGetRequest || isHeadRequest ) { + if (isGetRequest){ + request = "GET"; + } + if (isHeadRequest){ + request = "HEAD"; + } StringTokenizer t = new StringTokenizer(s, " "); t.nextToken(); String op = t.nextToken(); @@ -123,11 +130,11 @@ if (p.startsWith(XSX)) { p = p.replace(XSX, "/"); } - ServerAccess.logNoReprint("Getting: " + p); + ServerAccess.logOutputReprint("Getting- " + request + ": " + p); p = URLDecoder.decode(p, "UTF-8"); p = p.replaceAll("\\?.*", ""); p = (".".concat((p.endsWith("/")) ? p.concat("index.html") : p)).replace('/', File.separatorChar); - ServerAccess.logNoReprint("Serving: " + p); + ServerAccess.logOutputReprint("Serving- " + request + ": " + p); File pp = new File(dir, p); int l = (int) pp.length(); byte[] b = new byte[l];