@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.put("/api/users/:id").handler(ctx -> { mongo.findOne("users", new JsonObject().put("_id", ctx.request().getParam("id")), null, lookup -> {
@Override public Route put(String path) { return router.put(path); }
@Override public Route put() { return router.put(); }
@Override public io.vertx.ext.web.Route put() { return delegate.put(); }
@Test public void testPut() throws Exception { router.put().handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.PUT, "/whatever", 200, "foo"); testRequest(HttpMethod.GET, "/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/whatever", 404, "Not Found"); testRequest(HttpMethod.DELETE, "/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/whatever", 404, "Not Found"); }
@Test public void testPutWithPathExact() throws Exception { router.put("/somepath/").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.PUT, "/somepath/", 200, "foo"); testRequest(HttpMethod.PUT, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.DELETE, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
@Test public void testPutWithPathBegin() throws Exception { router.put("/somepath/*").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.PUT, "/somepath/whatever", 200, "foo"); testRequest(HttpMethod.PUT, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.DELETE, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
/** * Add a route that matches a HTTP PUT request and the specified path * @param path URI paths that begin with this path will match * @return the route */ public io.vertx.rxjava.ext.web.Route put(String path) { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.put(path)); return ret; }
/** * Add a route that matches any HTTP PUT request * @return the route */ public io.vertx.rxjava.ext.web.Route put() { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.put()); return ret; }
/** * Add a route that matches any HTTP PUT request * @return the route */ public io.vertx.rxjava.ext.web.Route put() { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.put()); return ret; }
/** * Add a route that matches a HTTP PUT request and the specified path * @param path URI paths that begin with this path will match * @return the route */ public io.vertx.rxjava.ext.web.Route put(String path) { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.put(path)); return ret; }
@Override public io.vertx.ext.web.Route put(String path) { return delegate.put(getFullPath(path)); }
@Override public Router createRouter(Vertx vertx) { this.vertx = vertx; store = new RxStore(StoreFactory.createStore(vertx)); storagePath = vertx.getOrCreateContext().config() .getString(ConfigConstants.STORAGE_FILE_PATH); Router router = Router.router(vertx); router.get("/*").handler(this::onGet); router.put("/*").handler(this::onPut); router.post("/*").handler(this::onPost); router.delete("/*").handler(this::onDelete); return router; }
/** * Registers the routes. * * @param router the router * @param root the root */ private void registerRoutes(Router router, String root) { // Get all and query router.get(root).handler(this::all); // Get one router.get(root + "/:uuid").handler(this::one); // Unpublish router.delete(root + "/:uuid").handler(this::unpublish); // Publish router.route().handler(BodyHandler.create()); router.post(root).handler(this::publish); // Update router.put(root + "/:uuid").handler(this::update); }
@Test public void testPut() throws Exception { router.put().handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.PUT, "/whatever", 200, "foo"); testRequest(HttpMethod.GET, "/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/whatever", 404, "Not Found"); testRequest(HttpMethod.DELETE, "/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/whatever", 404, "Not Found"); }
/** * Registers the routes. * * @param router the router * @param root the root */ private void registerRoutes(Router router, String root) { // Get all and query router.get(root).handler(this::all); // Get one router.get(root + "/:uuid").handler(this::one); // Unpublish router.delete(root + "/:uuid").handler(this::unpublish); // Publish router.route().handler(BodyHandler.create()); router.post(root).handler(this::publish); // Update router.put(root + "/:uuid").handler(this::update); }
@Test public void testPutWithPathExact() throws Exception { router.put("/somepath/").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.PUT, "/somepath/", 200, "foo"); testRequest(HttpMethod.PUT, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.DELETE, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
@Test public void testPutWithPathBegin() throws Exception { router.put("/somepath/*").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.PUT, "/somepath/whatever", 200, "foo"); testRequest(HttpMethod.PUT, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.DELETE, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }