use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class UnmodifiableMaps method test.
void test(String[] args) throws Exception {
HttpServer server = startHttpServer();
try {
InetSocketAddress address = server.getAddress();
URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + "/foo");
doClient(uri);
} finally {
server.stop(0);
}
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class UnmodifiableMaps method startHttpServer.
// HTTP Server
HttpServer startHttpServer() throws IOException {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
httpServer.createContext("/foo", new SimpleHandler());
httpServer.start();
return httpServer;
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class BasicLongCredentials method main.
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
try {
Handler handler = new Handler();
HttpContext ctx = server.createContext("/test", handler);
BasicAuthenticator a = new BasicAuthenticator(REALM) {
public boolean checkCredentials(String username, String pw) {
return USERNAME.equals(username) && PASSWORD.equals(pw);
}
};
ctx.setAuthenticator(a);
server.start();
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL("http://localhost:" + server.getAddress().getPort() + "/test/");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
InputStream is = urlc.getInputStream();
int c = 0;
while (is.read() != -1) {
c++;
}
if (c != 0) {
throw new RuntimeException("Test failed c = " + c);
}
if (error) {
throw new RuntimeException("Test failed: error");
}
System.out.println("OK");
} finally {
server.stop(0);
}
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class HttpStreams method test.
void test() throws Exception {
HttpServer server = null;
try {
server = startHttpServer();
String baseUrl = "http://localhost:" + server.getAddress().getPort() + "/";
client(baseUrl + "chunked/");
client(baseUrl + "fixed/");
client(baseUrl + "error/");
client(baseUrl + "chunkedError/");
// Test with a response cache
ResponseCache ch = ResponseCache.getDefault();
ResponseCache.setDefault(new TrivialCacheHandler());
try {
client(baseUrl + "chunked/");
client(baseUrl + "fixed/");
client(baseUrl + "error/");
client(baseUrl + "chunkedError/");
} finally {
ResponseCache.setDefault(ch);
}
} finally {
if (server != null)
server.stop(0);
}
System.out.println("passed: " + pass + ", failed: " + fail);
if (fail > 0)
throw new RuntimeException("some tests failed check output");
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class NoCache method startHttpServer.
// HTTP Server
static HttpServer startHttpServer() throws IOException {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
httpServer.createContext("/NoCache/", new SimpleHandler());
httpServer.start();
return httpServer;
}
Aggregations