public static void main(final String[] args) { setPort(50845); externalStaticFileLocation("public"); // Static files new RecoController(); new UserController(); new TagController(); get( "/", (request, response) -> { response.redirect("/index.html"); return ""; }); before( (request, response) -> { HibernateUtil.getSession().beginTransaction(); }); after( (request, response) -> { HibernateUtil.getSession().getTransaction().commit(); HibernateUtil.closeSession(); }); exception( Exception.class, (e, request, response) -> { HibernateUtil.getSession().getTransaction().rollback(); HibernateUtil.closeSession(); response.status(500); }); }
@Override public void apply(final IAbstractService iAbstractService) { final IAdminService adminService = (IAdminService) iAbstractService; // Used to show all the admins by the Front-end UI get("/admins", (req, res) -> adminService.getAllUsers(), json()); // Used to create admin details (used at the Front-End UI) post( "/admin", (req, res) -> adminService.createUser( req.queryParams("email"), req.queryParams("id"), req.queryParams("fname"), req.queryParams("lname"), req.queryParams("password")), json()); after( (req, res) -> { res.type("application/json"); }); exception( IllegalArgumentException.class, (e, req, res) -> { res.status(400); res.body(toJson(new ResponseError(e))); }); }
private void setupExceptionHandling() { exception( Exception.class, (e, req, res) -> { log.error( String.format( "Exception for request: %s [%s]%n[%s]", req.requestMethod(), req.pathInfo(), req.body()), e); }); }