wrap calls in db session

This commit is contained in:
Athou
2014-08-15 15:20:21 +02:00
parent 823cb03f9b
commit 8a57be3e63
2 changed files with 14 additions and 4 deletions

View File

@@ -27,10 +27,15 @@ public class CustomCssServlet extends HttpServlet {
private final UserService userService;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void doGet(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/css");
final Optional<User> user = userService.login(req.getSession());
final Optional<User> user = new UnitOfWork<Optional<User>>(sessionFactory) {
@Override
protected Optional<User> runInSession() throws Exception {
return userService.login(req.getSession());
}
}.run();
if (!user.isPresent()) {
return;
}

View File

@@ -43,11 +43,16 @@ public class NextUnreadServlet extends HttpServlet {
private final CommaFeedConfiguration config;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void doGet(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String categoryId = req.getParameter(PARAM_CATEGORYID);
String orderParam = req.getParameter(PARAM_READINGORDER);
final Optional<User> user = userService.login(req.getSession());
final Optional<User> user = new UnitOfWork<Optional<User>>(sessionFactory) {
@Override
protected Optional<User> runInSession() throws Exception {
return userService.login(req.getSession());
}
}.run();
if (!user.isPresent()) {
resp.sendRedirect(resp.encodeRedirectURL(config.getApplicationSettings().getPublicUrl()));
return;