@Override public void start() { setUpInitialData(); Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.get("/products/:productID").handler(this::handleGetProduct); router.put("/products/:productID").handler(this::handleAddProduct); router.get("/products").handler(this::handleListProducts); vertx.createHttpServer().requestHandler(router).listen(8080); }
@Validate public void start() throws Exception { setUpInitialData(); TcclSwitch.executeWithTCCLSwitch(() -> { Router router = Router.router(vertx); router.route().handler(BodyHandler.create()); router.get("/products/:productID").handler(this::handleGetProduct); router.put("/products/:productID").handler(this::handleAddProduct); router.get("/products").handler(this::handleListProducts); router.get("/assets/*").handler(StaticHandler.create("assets", this.getClass().getClassLoader())); LOGGER.info("Creating HTTP server for vert.x web application"); HttpServer server = vertx.createHttpServer(); server.requestHandler(router).listen(8081); }); }
router.route().handler(BodyHandler.create());
Router router = Router.router(vertx); router.route().handler(BodyHandler.create());
router.route().handler(BodyHandler.create());
router.route().handler(BodyHandler.create());
router.route().handler(BodyHandler.create().setUploadsDirectory("uploads"));
router.route().handler(BodyHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(BodyHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(BodyHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(BodyHandler.create());
@Override public void setUp() throws Exception { super.setUp(); router.route().handler(BodyHandler.create()); }
@Override public void setUp() throws Exception { super.setUp(); // Make sure a catch-all BodyHandler will not prevent websocket connection router.route().handler(BodyHandler.create()); SockJSProtocolTest.installTestApplications(router, vertx); }
@Test public void testBodyHandlerCreateTrueWorks() throws Exception { router.clear(); router.route().handler(BodyHandler.create(true)); testFormURLEncoded(); }
@Override public void setUp() throws Exception { // Use two servers so we test with HTTP request/response with load balanced SockJSSession access numServers = 2; preSockJSHandlerSetup = router -> { router.route().handler(BodyHandler.create()); // simulate an async handler router.route().handler(rtx -> rtx.vertx().executeBlocking(f -> f.complete(true), r -> rtx.next())); }; super.setUp(); }
@Test public void testFormMultipartFormDataMergeAttributes() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setMergeFormAttributes(true)); testFormMultipartFormData(true); }
@Test public void testBodyLimitWithHandleFileUploadsFalse() throws Exception { router.clear(); BodyHandler bodyHandler = BodyHandler.create(false).setBodyLimit(2048); router.route().handler(bodyHandler); Buffer fileData = TestUtils.randomBuffer(4096); router.route().handler(rc -> { rc.response().end(); }); sendFileUploadRequest(fileData, 413, "Request Entity Too Large"); }
@Test public void testFileUploadTooBig() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(20000)); Buffer fileData = TestUtils.randomBuffer(50000); router.route().handler(rc -> fail("Should not be called")); sendFileUploadRequest(fileData, 413, "Request Entity Too Large"); }
@Test public void testBodyTooBig() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(5000)); Buffer buff = TestUtils.randomBuffer(10000); router.route().handler(rc -> fail("Should not be called")); testRequest(HttpMethod.POST, "/", req -> { req.setChunked(true); req.write(buff); }, 413, "Request Entity Too Large", null); }
@Test public void testBodyTooBig2() throws Exception { router.clear(); router.route().handler(BodyHandler.create().setBodyLimit(500)); Buffer buff = TestUtils.randomBuffer(1000); router.route().handler(rc -> fail("Should not be called")); testRequest(HttpMethod.POST, "/", req -> { req.setChunked(true); req.write(buff); }, 413, "Request Entity Too Large", null); }