use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class FixedLengthResponseTestCase 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.HttpServerExchange in project undertow by undertow-io.
the class HttpContinueConduitWrappingHandlerBufferLeakTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
final HttpContinueReadHandler handler = new HttpContinueReadHandler(blockingHandler);
DefaultServer.setRootHandler(handler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
try {
if (exchange.getQueryParameters().containsKey("reject")) {
exchange.getRequestChannel();
exchange.setStatusCode(StatusCodes.EXPECTATION_FAILED);
exchange.getOutputStream().close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class HttpContinueConduitWrappingHandlerTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
final HttpContinueReadHandler handler = new HttpContinueReadHandler(blockingHandler);
DefaultServer.setRootHandler(handler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
try {
if (!accept) {
HttpContinue.rejectExchange(exchange);
return;
}
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.HttpServerExchange in project undertow by undertow-io.
the class LotsOfHeadersRequestTestCase method setup.
@BeforeClass
public static void setup() {
Assume.assumeFalse(DefaultServer.isH2upgrade());
final BlockingHandler blockingHandler = new BlockingHandler();
DefaultServer.setRootHandler(blockingHandler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
HeaderMap headers = exchange.getRequestHeaders();
for (HeaderValues header : headers) {
for (String val : header) {
exchange.getResponseHeaders().put(HttpString.tryFromString(header.getHeaderName().toString()), val);
}
}
}
});
}
use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.
the class AsyncWebSocketHttpServerExchange method sendData.
@Override
public IoFuture<Void> sendData(final ByteBuffer data) {
if (sender == null) {
this.sender = exchange.getResponseSender();
}
final FutureResult<Void> future = new FutureResult<>();
sender.send(data, new IoCallback() {
@Override
public void onComplete(final HttpServerExchange exchange, final Sender sender) {
future.setResult(null);
}
@Override
public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(exception);
future.setException(exception);
}
});
return future.getIoFuture();
}
Aggregations