Skip to content

Commit

Permalink
Merge pull request #4314 from mkouba/issue-4294-vertx-body-handler
Browse files Browse the repository at this point in the history
Vertx web - use shared BodyHandler instance
  • Loading branch information
stuartwdouglas committed Oct 3, 2019
2 parents 07f68d7 + 69c306d commit 95aa4b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
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
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;
}
}

0 comments on commit 95aa4b8

Please sign in to comment.