Socket s = new Socket (loopback, server.getAddress().getPort());
s.setSoTimeout ((int) Utils.adjustTimeout(5000));
OutputStream os = s.getOutputStream();
os.write (cmd.getBytes());
InputStream is = s.getInputStream (); try {
ok = readAndCheck (is, "401 Unauthorized") &&
readAndCheck (is, "200 OK");
} catch (SocketTimeoutException e) {
System.out.println ("Did not received expected data");
ok = false;
} finally {
s.close();
server.stop(2);
}
if (requests != 1) { thrownew RuntimeException ("server handler did not receive the request");
} if (!ok) { thrownew RuntimeException ("did not get 200 OK");
}
System.out.println ("OK");
}
/* check for expected string and return true if found in stream */
staticboolean readAndCheck (InputStream is, String expected) throws IOException { int c; int count = 0; int expLen = expected.length();
expected = expected.toLowerCase();
while ((c=is.read()) != -1) {
c = Character.toLowerCase (c); if (c == expected.charAt (count)) {
count ++; if (count == expLen) { returntrue;
}
} else {
count = 0;
}
} returnfalse;
}
publicstaticvolatileboolean ok = false; staticvolatileint requests = 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.