use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class FixedLengthInputStream method startHttpServer.
/**
* Http Server
*/
HttpServer startHttpServer() throws IOException {
if (debug) {
Logger logger = Logger.getLogger("com.sun.net.httpserver");
Handler outHandler = new StreamHandler(System.out, new SimpleFormatter());
outHandler.setLevel(Level.FINEST);
logger.setLevel(Level.FINEST);
logger.addHandler(outHandler);
}
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
httpServer.createContext("/flis/", new MyHandler(POST_SIZE));
httpServer.start();
return httpServer;
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class Deadlock method main.
public static void main(String[] args) throws Exception {
Handler handler = new Handler();
InetSocketAddress addr = new InetSocketAddress(0);
HttpServer server = HttpServer.create(addr, 0);
HttpContext ctx = server.createContext("/test", handler);
BasicAuthenticator a = new BasicAuthenticator("foobar@test.realm") {
@Override
public boolean checkCredentials(String username, String pw) {
return "fred".equals(username) && pw.charAt(0) == 'x';
}
};
ctx.setAuthenticator(a);
ExecutorService executor = Executors.newCachedThreadPool();
server.setExecutor(executor);
server.start();
java.net.Authenticator.setDefault(new MyAuthenticator());
System.out.print("Deadlock: ");
for (int i = 0; i < 2; i++) {
Runner t = new Runner(server, i);
t.start();
t.join();
}
server.stop(2);
executor.shutdown();
if (error) {
throw new RuntimeException("test failed error");
}
if (count != 2) {
throw new RuntimeException("test failed count = " + count);
}
System.out.println("OK");
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class HttpOnly method test.
void test(String[] args) throws Exception {
HttpServer server = startHttpServer();
CookieHandler previousHandler = CookieHandler.getDefault();
try {
InetSocketAddress address = server.getAddress();
URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH);
populateCookieStore(uri);
doClient(uri);
} finally {
CookieHandler.setDefault(previousHandler);
server.stop(0);
}
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class InfiniteLoop method main.
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
server.createContext("/test/InfiniteLoop", new RespHandler());
server.start();
try {
InetSocketAddress address = server.getAddress();
URL url = new URL("http://localhost:" + address.getPort() + "/test/InfiniteLoop");
final Phaser phaser = new Phaser(2);
for (int i = 0; i < 10; i++) {
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
final InputStream is = uc.getInputStream();
final Thread thread = new Thread() {
public void run() {
try {
phaser.arriveAndAwaitAdvance();
while (is.read() != -1) Thread.sleep(50);
} catch (Exception x) {
x.printStackTrace();
}
}
};
thread.start();
phaser.arriveAndAwaitAdvance();
is.close();
System.out.println("returned from close");
thread.join();
}
} finally {
server.stop(0);
}
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class ChunkedEncodingTest method test.
public static void test() {
HttpServer server = null;
try {
serverDigest = MessageDigest.getInstance("MD5");
clientDigest = MessageDigest.getInstance("MD5");
server = startHttpServer();
int port = server.getAddress().getPort();
out.println("Server listening on port: " + port);
client("http://localhost:" + port + "/chunked/");
if (!MessageDigest.isEqual(clientMac, serverMac)) {
throw new RuntimeException("Data received is NOT equal to the data sent");
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (server != null)
server.stop(0);
}
}
Aggregations