use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class HeadTestCase method setup.
@BeforeClass
public static void setup() {
DefaultServer.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (connection == null) {
connection = exchange.getConnection();
} else if (!DefaultServer.isAjp() && !DefaultServer.isProxy() && connection != exchange.getConnection()) {
Sender sender = exchange.getResponseSender();
sender.send("Connection not persistent");
return;
}
exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, message.length() + "");
final Sender sender = exchange.getResponseSender();
sender.send(message);
}
});
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class HttpContinueAcceptingHandlerTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
final HttpContinueAcceptingHandler handler = new HttpContinueAcceptingHandler(blockingHandler, new Predicate() {
@Override
public boolean resolve(HttpServerExchange value) {
return accept;
}
});
DefaultServer.setRootHandler(handler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
try {
byte[] buffer = new byte[1024];
final ByteArrayOutputStream b = new ByteArrayOutputStream();
int r = 0;
final OutputStream outputStream = exchange.getOutputStream();
final InputStream inputStream = exchange.getInputStream();
while ((r = inputStream.read(buffer)) > 0) {
b.write(buffer, 0, r);
}
outputStream.write(b.toByteArray());
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class LongURLTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
DefaultServer.setRootHandler(blockingHandler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
exchange.getResponseSender().send(exchange.getRelativePath());
}
});
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class LotsOfHeadersResponseTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
DefaultServer.setRootHandler(blockingHandler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
for (int i = 0; i < COUNT; ++i) {
exchange.getResponseHeaders().put(HttpString.tryFromString(HEADER + i), MESSAGE + i);
}
}
});
}
use of io.undertow.server.HttpHandler in project undertow by undertow-io.
the class LotsOfQueryParametersTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
DefaultServer.setRootHandler(blockingHandler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
for (Map.Entry<String, Deque<String>> entry : exchange.getQueryParameters().entrySet()) {
exchange.getResponseHeaders().put(HttpString.tryFromString(entry.getKey()), entry.getValue().getFirst());
}
}
});
}
Aggregations