Commit 320957fa authored by KT315's avatar KT315

Merge branch 'java-dummy' into 'master'

Java dummy

See merge request !3
parents d2a59687 04e20cc2
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.concurrent.ThreadLocalRandom;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class Dummy {
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(5000), 0);
server.createContext("/", new DummyHandler());
server.setExecutor(null);
server.start();
}
static class DummyHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
String response = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis dictum ligula, ut sagittis nisl malesuada nec. Fusce hendrerit leo augue, nec pretium dolor porta sodales. Sed consequat sed purus eu aliquet. Etiam laoreet nibh vel ex sodales, non egestas lorem tempor. Pellentesque placerat facilisis felis, nec bibendum metus finibus quis. Donec lobortis, sapien at tristique placerat, nibh libero volutpat eros, eget mollis nibh elit et enim. Vestibulum consequat ut lorem sed eleifend. Ut eu dolor ut lectus faucibus rhoncus. Nam vestibulum vitae massa vel congue. Nam ac odio lacus. Nam condimentum ante eget mollis vestibulum. Cras nisi sapien, tempor nec diam at, vulputate cursus odio. Maecenas vitae tellus efficitur arcu mollis ultrices id vitae ex. Suspendisse potenti. Duis nec vestibulum dui. Donec ultricies sit amet lorem eu feugiat. Ut pretium vitae lectus at tempor. Curabitur condimentum arcu varius nulla ultricies, id feugiat odio dictum. Vivamus sollicitudin consectetur nullam.";
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
try {
int sleep_duration = 100 + (5 - ThreadLocalRandom.current().nextInt(0, 10));
Thread.sleep(sleep_duration);
}
catch (InterruptedException e) {
System.out.println("Failed to sleep");
}
os.write(response.getBytes());
os.close();
}
}
}
$ javac Dummy.java
$ java Dummy
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment