Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertx web - use shared BodyHandler instance #4314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ public void write(String name, byte[] data) {
generatedClass.produce(new GeneratedClassBuildItem(true, name, data));
}
};
Handler<RoutingContext> bodyHandler = recorder.createBodyHandler(httpConfiguration);

for (AnnotatedRouteHandlerBuildItem businessMethod : routeHandlerBusinessMethods) {
String handlerClass = generateHandler(businessMethod.getBean(), businessMethod.getMethod(), classOutput);
reflectiveClasses.produce(new ReflectiveClassBuildItem(false, false, handlerClass));
Handler<RoutingContext> routingHandler = recorder.createHandler(handlerClass);
for (AnnotationInstance routeAnnotation : businessMethod.getRoutes()) {
Route route = annotationProxy.builder(routeAnnotation, Route.class).build(classOutput);
Function<Router, io.vertx.ext.web.Route> routeFunction = recorder.createRouteFunction(route, httpConfiguration);
Function<Router, io.vertx.ext.web.Route> routeFunction = recorder.createRouteFunction(route, bodyHandler);
AnnotationValue typeValue = routeAnnotation.value("type");
HandlerType handlerType = HandlerType.NORMAL;
if (typeValue != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Handler<RoutingContext> createHandler(String handlerClassName) {
}

public Function<Router, io.vertx.ext.web.Route> createRouteFunction(Route routeAnnotation,
HttpConfiguration httpConfiguration) {
Handler<RoutingContext> bodyHandler) {
return new Function<Router, io.vertx.ext.web.Route>() {
@Override
public io.vertx.ext.web.Route apply(Router router) {
Expand Down Expand Up @@ -66,22 +66,24 @@ public io.vertx.ext.web.Route apply(Router router) {
route.consumes(consumes);
}
}

BodyHandler bodyHandler = BodyHandler.create();
Optional<MemorySize> maxBodySize = httpConfiguration.limits.maxBodySize;
if (maxBodySize.isPresent()) {
bodyHandler.setBodyLimit(maxBodySize.get().asLongValue());
}
final BodyConfig bodyConfig = httpConfiguration.body;
bodyHandler.setHandleFileUploads(bodyConfig.handleFileUploads);
bodyHandler.setUploadsDirectory(bodyConfig.uploadsDirectory);
bodyHandler.setDeleteUploadedFilesOnEnd(bodyConfig.deleteUploadedFilesOnEnd);
bodyHandler.setMergeFormAttributes(bodyConfig.mergeFormAttributes);
bodyHandler.setPreallocateBodyBuffer(bodyConfig.preallocateBodyBuffer);

route.handler(bodyHandler);
return route;
}
};
}

public Handler<RoutingContext> createBodyHandler(HttpConfiguration httpConfiguration) {
BodyHandler bodyHandler = BodyHandler.create();
Optional<MemorySize> maxBodySize = httpConfiguration.limits.maxBodySize;
if (maxBodySize.isPresent()) {
bodyHandler.setBodyLimit(maxBodySize.get().asLongValue());
}
final BodyConfig bodyConfig = httpConfiguration.body;
bodyHandler.setHandleFileUploads(bodyConfig.handleFileUploads);
bodyHandler.setUploadsDirectory(bodyConfig.uploadsDirectory);
bodyHandler.setDeleteUploadedFilesOnEnd(bodyConfig.deleteUploadedFilesOnEnd);
bodyHandler.setMergeFormAttributes(bodyConfig.mergeFormAttributes);
bodyHandler.setPreallocateBodyBuffer(bodyConfig.preallocateBodyBuffer);
return bodyHandler;
}
}