aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-extensions/net
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2012-09-05 16:02:18 +0200
committerJiri Vanek <[email protected]>2012-09-05 16:02:18 +0200
commite5a1c62b36ce30b1b2fd2bb54f663ab553c247cd (patch)
tree79196fc0a499033230d27e2ef3d161ac13caa2a3 /tests/test-extensions/net
parentd770d3cb8aa41cbe3a860485bcb2c39a4f2cac40 (diff)
Fixing several errors which were causing incorrect behaviour causing correct reproduction of PR905
Diffstat (limited to 'tests/test-extensions/net')
-rw-r--r--tests/test-extensions/net/sourceforge/jnlp/LoggingBottleneck.java3
-rw-r--r--tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java18
-rw-r--r--tests/test-extensions/net/sourceforge/jnlp/ServerLauncher.java22
-rw-r--r--tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java5
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++) {