Advertisement
Guest User

Untitled

a guest
Mar 18th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. /**
  2.      * @param routingContext
  3.      * <p>
  4.      * Responsible for retrieving all todos from the list and send as encoded json to user
  5.      * </p>
  6.      */
  7.     private void getAllTodos(RoutingContext routingContext) {
  8.  
  9.         Map<Integer, String> todos = new HashMap<Integer, String>();
  10.  
  11.         JsonArray keys = awaitResult(r -> client.keys("*", r));
  12.  
  13.         for (Object k : keys) {
  14.             String key = (String) k;
  15.             String todomessage = awaitResult(h -> client.get(key, h));
  16.             todos.put(Integer.parseInt(key), todomessage);
  17.         }
  18.  
  19.         // Write the HTTP response
  20.         // The response is in JSON using the utf-8 encoding
  21.         // will return map of
  22.         routingContext.response().putHeader("content-type", "application/json; charset=utf-8")
  23.                 .end(Json.encodePrettily(todos.values()));
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement