From d0c7dabbb1c32dd187699ba034ad45474ec633c3 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 21 Mar 2013 12:49:08 +0200 Subject: [PATCH] Fixed locking problem with serviceException (#10569) Change-Id: I363ac3508f558769a79098572cb268cadfc4b1e2 --- .../src/com/vaadin/server/VaadinPortlet.java | 46 +++++++++++-------- .../src/com/vaadin/server/VaadinServlet.java | 45 +++++++++++------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 75d72be03b..9dd8a4c94b 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -611,25 +611,35 @@ public class VaadinPortlet extends GenericPortlet implements Constants, Throwable e) throws IOException, PortletException { // TODO Check that this error handler is working when running inside a // portlet - - // if this was an UIDL request, response UIDL back to client - ErrorHandler errorHandler = ErrorEvent.findErrorHandler(vaadinSession); - if (getRequestType(request) == RequestType.UIDL) { - SystemMessages ci = getService().getSystemMessages( - ServletPortletHelper.findLocale(null, vaadinSession, - request), request); - criticalNotification(request, response, - ci.getInternalErrorCaption(), ci.getInternalErrorMessage(), - null, ci.getInternalErrorURL()); - if (errorHandler != null) { - errorHandler.error(new ErrorEvent(e)); - } - } else { - if (errorHandler != null) { - errorHandler.error(new ErrorEvent(e)); + if (vaadinSession != null) { + vaadinSession.lock(); + } + try { + // if this was an UIDL request, response UIDL back to client + ErrorHandler errorHandler = ErrorEvent + .findErrorHandler(vaadinSession); + if (getRequestType(request) == RequestType.UIDL) { + SystemMessages ci = getService().getSystemMessages( + ServletPortletHelper.findLocale(null, vaadinSession, + request), request); + criticalNotification(request, response, + ci.getInternalErrorCaption(), + ci.getInternalErrorMessage(), null, + ci.getInternalErrorURL()); + if (errorHandler != null) { + errorHandler.error(new ErrorEvent(e)); + } } else { - // Re-throw other exceptions - throw new PortletException(e); + if (errorHandler != null) { + errorHandler.error(new ErrorEvent(e)); + } else { + // Re-throw other exceptions + throw new PortletException(e); + } + } + } finally { + if (vaadinSession != null) { + vaadinSession.unlock(); } } } diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 46fe3da5c6..bd379f94bc 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -512,26 +512,37 @@ public class VaadinServlet extends HttpServlet implements Constants { private void handleServiceException(VaadinServletRequest request, VaadinServletResponse response, VaadinSession vaadinSession, Throwable e) throws IOException, ServletException { - ErrorHandler errorHandler = ErrorEvent.findErrorHandler(vaadinSession); + if (vaadinSession != null) { + vaadinSession.lock(); + } + try { + ErrorHandler errorHandler = ErrorEvent + .findErrorHandler(vaadinSession); + + // if this was an UIDL request, response UIDL back to client + if (getRequestType(request) == RequestType.UIDL) { + SystemMessages ci = getService().getSystemMessages( + ServletPortletHelper.findLocale(null, vaadinSession, + request), request); + criticalNotification(request, response, + ci.getInternalErrorCaption(), + ci.getInternalErrorMessage(), null, + ci.getInternalErrorURL()); + if (errorHandler != null) { + errorHandler.error(new ErrorEvent(e)); + } + } else { + if (errorHandler != null) { + errorHandler.error(new ErrorEvent(e)); + } - // if this was an UIDL request, response UIDL back to client - if (getRequestType(request) == RequestType.UIDL) { - SystemMessages ci = getService().getSystemMessages( - ServletPortletHelper.findLocale(null, vaadinSession, - request), request); - criticalNotification(request, response, - ci.getInternalErrorCaption(), ci.getInternalErrorMessage(), - null, ci.getInternalErrorURL()); - if (errorHandler != null) { - errorHandler.error(new ErrorEvent(e)); + // Re-throw other exceptions + throw new ServletException(e); } - } else { - if (errorHandler != null) { - errorHandler.error(new ErrorEvent(e)); + } finally { + if (vaadinSession != null) { + vaadinSession.unlock(); } - - // Re-throw other exceptions - throw new ServletException(e); } } -- 2.39.5