diff options
Diffstat (limited to 'tests/test-extensions')
4 files changed, 39 insertions, 9 deletions
diff --git a/tests/test-extensions/net/sourceforge/jnlp/LoggingBottleneck.java b/tests/test-extensions/net/sourceforge/jnlp/LoggingBottleneck.java index 3f4de4b..54fa248 100644 --- a/tests/test-extensions/net/sourceforge/jnlp/LoggingBottleneck.java +++ b/tests/test-extensions/net/sourceforge/jnlp/LoggingBottleneck.java @@ -201,15 +201,18 @@ public class LoggingBottleneck { private void stdout(String idded) throws IOException { DEFAULT_STDOUT_WRITER.write(idded); DEFAULT_STDOUT_WRITER.newLine(); + DEFAULT_STDOUT_WRITER.flush(); } private void stderr(String idded) throws IOException { DEFAULT_STDERR_WRITER.write(idded); DEFAULT_STDERR_WRITER.newLine(); + DEFAULT_STDERR_WRITER.flush(); } private void stdeall(String idded) throws IOException { DEFAULT_STDLOGS_WRITER.write(idded); DEFAULT_STDLOGS_WRITER.newLine(); + DEFAULT_STDLOGS_WRITER.flush(); } } diff --git a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java index 6607e35..da5c265 100644 --- a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java +++ b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java @@ -585,16 +585,24 @@ public class ServerAccess { } /** - * Ctreate resource on http, on 'localhost' on port on which this instance is running + * Ctreate resource on http, on 'localhost' on port on which this cached instance is running * @param resource * @return * @throws MalformedURLException */ public URL getUrlUponThisInstance(String resource) throws MalformedURLException { - if (!resource.startsWith("/")) { - resource = "/" + resource; - } - return new URL("http", server.getServerName(), getPort(), resource); + getInstance(); + return getUrlUponInstance(server,resource); + } + + /** + * Ctreate resource on http, on 'localhost' on port on which this instance is running + * @param resource + * @return + * @throws MalformedURLException + */ + public static URL getUrlUponInstance(ServerLauncher instance,String resource) throws MalformedURLException { + return instance.getUrl(resource); } /** diff --git a/tests/test-extensions/net/sourceforge/jnlp/ServerLauncher.java b/tests/test-extensions/net/sourceforge/jnlp/ServerLauncher.java index 92634cc..30904b8 100644 --- a/tests/test-extensions/net/sourceforge/jnlp/ServerLauncher.java +++ b/tests/test-extensions/net/sourceforge/jnlp/ServerLauncher.java @@ -56,6 +56,7 @@ public class ServerLauncher implements Runnable { private boolean running; private final Integer port; private final File dir; + private ServerSocket serverSocket; public String getServerName() { return serverName; @@ -99,9 +100,9 @@ public class ServerLauncher implements Runnable { public void run() { running = true; try { - ServerSocket s = new ServerSocket(port); + serverSocket = new ServerSocket(port); while (running) { - new TinyHttpdImpl(s.accept(), dir, port); + new TinyHttpdImpl(serverSocket.accept(), dir, port); } } catch (Exception e) { e.printStackTrace(); @@ -111,10 +112,27 @@ public class ServerLauncher implements Runnable { } public URL getUrl(String resource) throws MalformedURLException { + if (resource == null) { + resource = ""; + } + if (resource.trim().length() > 0 && !resource.startsWith("/")) { + resource = "/" + resource; + } return new URL("http", getServerName(), getPort(), resource); } public URL getUrl() throws MalformedURLException { return getUrl(""); } + + public void stop() { + this.running = false; + if (serverSocket != null) { + try { + serverSocket.close(); + } catch (Exception ex) { + ServerAccess.logException(ex); + } + } + } } diff --git a/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java b/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java index 34870ab..207f142 100644 --- a/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java +++ b/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java @@ -99,8 +99,9 @@ class TinyHttpdImpl extends Thread { } ServerAccess.logNoReprint("Getting: " + p); p = URLDecoder.decode(p, "UTF-8"); - ServerAccess.logNoReprint("Serving: " + p); + p=p.replaceAll("\\?.*", ""); p = (".".concat((p.endsWith("/")) ? p.concat("index.html") : p)).replace('/', File.separatorChar); + ServerAccess.logNoReprint("Serving: " + p); File pp = new File(dir, p); int l = (int) pp.length(); byte[] b = new byte[l]; @@ -115,7 +116,7 @@ class TinyHttpdImpl extends Thread { } else if (p.toLowerCase().endsWith(".jar")) { content = ct + "application/x-jar\n"; } - o.writeBytes("HTTP/1.0 200 OK\nConten" + "t-Length:" + l + "\n" + content + "\n"); + o.writeBytes("HTTP/1.0 200 OK\nContent-Length:" + l + "\n" + content + "\n"); if (op.startsWith(XSX)) { byte[][] bb = splitArray(b, 10); for (int j = 0; j < bb.length; j++) { |