/** * Create a body handler setting if it should handle file uploads * * @param handleFileUploads true if files upload should be handled * @return the body handler */ static BodyHandler create(boolean handleFileUploads) { return new BodyHandlerImpl(handleFileUploads); }
@Override public void handle(RoutingContext context) { if (this.checkContentType(context)) { super.handle(context); } }
private BodyHandlerImpl(boolean handleFileUploads, String uploadDirectory) { this.handleFileUploads = handleFileUploads; setUploadsDirectory(uploadDirectory); }
@Override public void handle(RoutingContext context) { HttpServerRequest request = context.request(); if (request.headers().contains(HttpHeaders.UPGRADE, HttpHeaders.WEBSOCKET, true)) { context.next(); return; } // we need to keep state since we can be called again on reroute Boolean handled = context.get(BODY_HANDLED); if (handled == null || !handled) { long contentLength = isPreallocateBodyBuffer ? parseContentLengthHeader(request) : -1; BHandler handler = new BHandler(context, contentLength); request.handler(handler); request.endHandler(v -> handler.end()); context.put(BODY_HANDLED, true); } else { // on reroute we need to re-merge the form params if that was desired if (mergeFormAttributes && request.isExpectMultipart()) { request.params().addAll(request.formAttributes()); } context.next(); } }
@Override public void handle(RoutingContext context) { HttpServerRequest request = context.request(); if (request.headers().contains(HttpHeaders.UPGRADE, HttpHeaders.WEBSOCKET, true)) { context.next(); return; } // we need to keep state since we can be called again on reroute Boolean handled = context.get(BODY_HANDLED); if (handled == null || !handled) { long contentLength = isPreallocateBodyBuffer ? parseContentLengthHeader(request) : -1; BHandler handler = new BHandler(context, contentLength); request.handler(handler); request.endHandler(v -> handler.end()); context.put(BODY_HANDLED, true); } else { // on reroute we need to re-merge the form params if that was desired if (mergeFormAttributes && request.isExpectMultipart()) { request.params().addAll(request.formAttributes()); } context.next(); } }
/** * Create a body handler with defaults * * @return the body handler */ static BodyHandler create() { return new BodyHandlerImpl(); }
@Override public void handle(RoutingContext context) { if (this.checkContentType(context)) { super.handle(context); } }
private BodyHandlerImpl(boolean handleFileUploads, String uploadDirectory) { this.handleFileUploads = handleFileUploads; setUploadsDirectory(uploadDirectory); }
/** * Create a body handler and use the given upload directory. * * @param uploadDirectory the uploads directory * @return the body handler */ static BodyHandler create(String uploadDirectory) { return new BodyHandlerImpl(uploadDirectory); }
@Override public void handle(RoutingContext context) { if (this.checkContentType(context)) { super.handle(context); } }
/** * Create a body handler setting if it should handle file uploads * * @param handleFileUploads true if files upload should be handled * @return the body handler */ static BodyHandler create(boolean handleFileUploads) { return new BodyHandlerImpl(handleFileUploads); }
/** * Create a body handler and use the given upload directory. * * @param uploadDirectory the uploads directory * @return the body handler */ static BodyHandler create(String uploadDirectory) { return new BodyHandlerImpl(uploadDirectory); }
/** * Create a body handler with defaults * * @return the body handler */ static BodyHandler create() { return new BodyHandlerImpl(); }
private Router configureRoutes() { final Router router = Router.router(vertx); router.route().handler(new BodyHandlerImpl()); // status check to indicate when server is up router.get("/system/status").handler(routingContext -> routingContext.response() .putHeader(HttpUtil.CONTENT_TYPE, HttpUtil.CONTENT_TYPE_JSON) .end(HttpUtil.buildStatusResponse())); pluginManager.getPlugins().forEach(plugin -> plugin.configureRoutes(router)); return router; } }
@Before public void setUp() throws Exception { vertx = Vertx.vertx(); port = Utils.getFreePorts(1)[0]; accountRepository = createMock(AccountRepository.class); configRepository = createMock(ConfigurationManager.class); dispatcher = new VertxDispatcher(); dispatcher.setBodyHandler(new BodyHandlerImpl()); dispatcher.setHost(HOST); dispatcher.setPort(port.value); dispatcher.setVertx(vertx); dispatcher.setAccountRepository(accountRepository); dispatcher.setConfig(configRepository); dispatcher.setMaxUploadSize(50*1024*1024); dispatcher.init(); }