1. We just need to make sure to use the same event bus destination as the service that was published by .
    1. private void indexHandler(RoutingContext context) {
    2. dbService.fetchAllPages(reply -> {
    3. if (reply.succeeded()) {
    4. context.put("title", "Wiki home");
    5. context.put("pages", reply.result().getList());
    6. templateEngine.render(context.data(), "templates/index.ftl", ar -> {
    7. if (ar.succeeded()) {
    8. context.response().putHeader("Content-Type", "text/html");
    9. context.response().end(ar.result());
    10. } else {
    11. context.fail(ar.cause());
    12. }
    13. });
    14. } else {
    15. context.fail(reply.cause());
    16. }
    17. });
    18. }
    19. private void pageRenderingHandler(RoutingContext context) {
    20. String requestedPage = context.request().getParam("page");
    21. dbService.fetchPage(requestedPage, reply -> {
    22. if (reply.succeeded()) {
    23. JsonObject payLoad = reply.result();
    24. boolean found = payLoad.getBoolean("found");
    25. String rawContent = payLoad.getString("rawContent", EMPTY_PAGE_MARKDOWN);
    26. context.put("title", requestedPage);
    27. context.put("id", payLoad.getInteger("id", -1));
    28. context.put("content", Processor.process(rawContent));
    29. context.put("timestamp", new Date().toString());
    30. templateEngine.render(context.data(), "templates/page.ftl", ar -> {
    31. if (ar.succeeded()) {
    32. context.response().putHeader("Content-Type", "text/html");
    33. context.response().end(ar.result());
    34. } else {
    35. context.fail(ar.cause());
    36. }
    37. });
    38. } else {
    39. context.fail(reply.cause());
    40. }
    41. });
    42. }
    43. private void pageUpdateHandler(RoutingContext context) {
    44. String title = context.request().getParam("title");
    45. Handler<AsyncResult<Void>> handler = reply -> {
    46. if (reply.succeeded()) {
    47. context.response().setStatusCode(303);
    48. context.response().putHeader("Location", "/wiki/" + title);
    49. context.response().end();
    50. } else {
    51. context.fail(reply.cause());
    52. }
    53. String markdown = context.request().getParam("markdown");
    54. if ("yes".equals(context.request().getParam("newPage"))) {
    55. dbService.createPage(title, markdown, handler);
    56. } else {
    57. dbService.savePage(Integer.valueOf(context.request().getParam("id")), markdown, handler);
    58. }
    59. }
    60. private void pageCreateHandler(RoutingContext context) {
    61. String pageName = context.request().getParam("name");
    62. String location = "/wiki/" + pageName;
    63. if (pageName == null || pageName.isEmpty()) {
    64. location = "/";
    65. }
    66. context.response().setStatusCode(303);
    67. context.response().putHeader("Location", location);
    68. context.response().end();
    69. }
    70. private void pageDeletionHandler(RoutingContext context) {
    71. dbService.deletePage(Integer.valueOf(context.request().getParam("id")), reply -> {
    72. if (reply.succeeded()) {
    73. context.response().setStatusCode(303);
    74. context.response().putHeader("Location", "/");
    75. context.response().end();
    76. } else {
    77. context.fail(reply.cause());
    78. }
    79. });