private Response putAndGetResponse(Todo todo) {
   Response res;
   if (TodoDao.instance.getModel().containsKey(todo.getId())) {
     res = Response.noContent().build();
   } else {
     res = Response.created(uriInfo.getAbsolutePath()).build();
   }
   TodoDao.instance.getModel().put(todo.getId(), todo);
   return res;
 }
Пример #2
0
  @POST
  @Produces(MediaType.TEXT_HTML)
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  public void newTodo(
      @FormParam("id") String id,
      @FormParam("summary") String summary,
      @FormParam("description") String description,
      @Context HttpServletResponse servletResponse)
      throws IOException {
    Todo todo = new Todo(id, summary);
    if (description != null) {
      todo.setDescription(description);
    }
    TodoDao.instance.getModel().put(id, todo);

    servletResponse.sendRedirect("../create_todo.html");
  }