use of io.quarkus.runtime.configuration.MemorySize in project quarkus by quarkusio.
the class VertxHttpRecorder method createBodyHandler.
public Handler<RoutingContext> createBodyHandler() {
BodyHandler bodyHandler = BodyHandler.create();
Optional<MemorySize> maxBodySize = httpConfiguration.getValue().limits.maxBodySize;
if (maxBodySize.isPresent()) {
bodyHandler.setBodyLimit(maxBodySize.get().asLongValue());
}
final BodyConfig bodyConfig = httpConfiguration.getValue().body;
bodyHandler.setHandleFileUploads(bodyConfig.handleFileUploads);
bodyHandler.setUploadsDirectory(bodyConfig.uploadsDirectory);
bodyHandler.setDeleteUploadedFilesOnEnd(bodyConfig.deleteUploadedFilesOnEnd);
bodyHandler.setMergeFormAttributes(bodyConfig.mergeFormAttributes);
bodyHandler.setPreallocateBodyBuffer(bodyConfig.preallocateBodyBuffer);
return new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext event) {
if (!Context.isOnEventLoopThread()) {
((ConnectionBase) event.request().connection()).channel().eventLoop().execute(new Runnable() {
@Override
public void run() {
try {
// this can happen if blocking authentication is involved for get requests
if (!event.request().isEnded()) {
event.request().resume();
if (CAN_HAVE_BODY.contains(event.request().method())) {
bodyHandler.handle(event);
} else {
event.next();
}
} else {
event.next();
}
} catch (Throwable t) {
event.fail(t);
}
}
});
} else {
if (!event.request().isEnded()) {
event.request().resume();
}
if (CAN_HAVE_BODY.contains(event.request().method())) {
bodyHandler.handle(event);
} else {
event.next();
}
}
}
};
}
use of io.quarkus.runtime.configuration.MemorySize in project quarkus by quarkusio.
the class UndertowDeploymentRecorder method startUndertow.
public Handler<RoutingContext> startUndertow(ShutdownContext shutdown, ExecutorService executorService, DeploymentManager manager, List<HandlerWrapper> wrappers, ServletRuntimeConfig servletRuntimeConfig) throws Exception {
shutdown.addShutdownTask(new Runnable() {
@Override
public void run() {
try {
manager.stop();
} catch (ServletException e) {
log.error("Failed to stop deployment", e);
}
manager.undeploy();
}
});
HttpHandler main = manager.getDeployment().getHandler();
for (HandlerWrapper i : wrappers) {
main = i.wrap(main);
}
if (!manager.getDeployment().getDeploymentInfo().getContextPath().equals("/")) {
PathHandler pathHandler = new PathHandler().addPrefixPath(manager.getDeployment().getDeploymentInfo().getContextPath(), main);
main = pathHandler;
}
currentRoot = main;
DefaultExchangeHandler defaultHandler = new DefaultExchangeHandler(ROOT_HANDLER);
UndertowBufferAllocator allocator = new UndertowBufferAllocator(servletRuntimeConfig.directBuffers.orElse(DEFAULT_DIRECT_BUFFERS), (int) servletRuntimeConfig.bufferSize.orElse(new MemorySize(BigInteger.valueOf(DEFAULT_BUFFER_SIZE))).asLongValue());
UndertowOptionMap.Builder undertowOptions = UndertowOptionMap.builder();
undertowOptions.set(UndertowOptions.MAX_PARAMETERS, servletRuntimeConfig.maxParameters);
UndertowOptionMap undertowOptionMap = undertowOptions.getMap();
return new Handler<RoutingContext>() {
@Override
public void handle(RoutingContext event) {
if (!event.request().isEnded()) {
event.request().pause();
}
// we handle auth failure directly
event.remove(QuarkusHttpUser.AUTH_FAILURE_HANDLER);
VertxHttpExchange exchange = new VertxHttpExchange(event.request(), allocator, executorService, event, event.getBody());
exchange.setPushHandler(VertxHttpRecorder.getRootHandler());
Optional<MemorySize> maxBodySize = httpConfiguration.getValue().limits.maxBodySize;
if (maxBodySize.isPresent()) {
exchange.setMaxEntitySize(maxBodySize.get().asLongValue());
}
Duration readTimeout = httpConfiguration.getValue().readTimeout;
exchange.setReadTimeout(readTimeout.toMillis());
exchange.setUndertowOptions(undertowOptionMap);
// see https://github.com/quarkusio/quarkus/issues/7782
if (BlockingOperationControl.isBlockingAllowed()) {
defaultHandler.handle(exchange);
} else {
executorService.submit(new Runnable() {
@Override
public void run() {
defaultHandler.handle(exchange);
}
});
}
}
};
}
Aggregations