diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/concurrentdetection/ConcurrentModificationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/concurrentdetection/ConcurrentModificationController.java
index 9b95e874d..1192995c2 100644
--- a/libreplan-webapp/src/main/java/org/libreplan/web/common/concurrentdetection/ConcurrentModificationController.java
+++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/concurrentdetection/ConcurrentModificationController.java
@@ -48,8 +48,12 @@ public class ConcurrentModificationController extends GenericForwardComposer {
.info(
"an OptimistLockingFailureException caused a disruption to an user",
exception);
- Executions.sendRedirect("/common/concurrent_modification.zul?back="
- + backURL);
+ if (Executions.getCurrent() != null) {
+ Executions.sendRedirect("/common/concurrent_modification.zul?back="
+ + backURL);
+ } else {
+ LOG.warn("Impossible to do redirect due to OptimisticLockingFailureException because of Executions.getCurrent() is null");
+ }
}
private static String getBackURL() {
diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/common/api/ConcurrentModificationErrorDTO.java b/libreplan-webapp/src/main/java/org/libreplan/ws/common/api/ConcurrentModificationErrorDTO.java
new file mode 100644
index 000000000..dccf88a07
--- /dev/null
+++ b/libreplan-webapp/src/main/java/org/libreplan/ws/common/api/ConcurrentModificationErrorDTO.java
@@ -0,0 +1,49 @@
+/*
+ * This file is part of LibrePlan
+ *
+ * Copyright (C) 2012 Igalia, S.L.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package org.libreplan.ws.common.api;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * DTO for representing any concurrent modification exception in the web
+ * services.
+ *
+ * @author Manuel Rego Casasnovas
+ */
+@XmlRootElement(name = "concurrent-modification-error")
+public class ConcurrentModificationErrorDTO {
+
+ @XmlAttribute(name = "message")
+ public String message;
+
+ @XmlElement(name = "stack-trace")
+ public String stackTrace;
+
+ public ConcurrentModificationErrorDTO() {
+ }
+
+ public ConcurrentModificationErrorDTO(String message, String stackTrace) {
+ this.message = message;
+ this.stackTrace = stackTrace;
+ }
+
+}
diff --git a/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/HibernateOptimisticLockingFailureExceptionMapper.java b/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/HibernateOptimisticLockingFailureExceptionMapper.java
new file mode 100644
index 000000000..a47d8b738
--- /dev/null
+++ b/libreplan-webapp/src/main/java/org/libreplan/ws/common/impl/HibernateOptimisticLockingFailureExceptionMapper.java
@@ -0,0 +1,48 @@
+/*
+ * This file is part of LibrePlan
+ *
+ * Copyright (C) 2012 Igalia, S.L.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package org.libreplan.ws.common.impl;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import org.libreplan.ws.common.api.ConcurrentModificationErrorDTO;
+import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;
+import org.springframework.stereotype.Component;
+
+/**
+ * Exception mapper for {@link HibernateOptimisticLockingFailureExceptionMapper}
+ *
+ * @author Manuel Rego Casasnovas
+ */
+@Provider
+@Component("hibernateOptimisticLockingFailureException")
+public class HibernateOptimisticLockingFailureExceptionMapper implements
+ ExceptionMapper {
+
+ public Response toResponse(HibernateOptimisticLockingFailureException e) {
+ return Response
+ .status(Response.Status.INTERNAL_SERVER_ERROR)
+ .entity(new ConcurrentModificationErrorDTO(
+ e.getMessage(), Util.getStackTrace(e)))
+ .type("application/xml").build();
+ }
+
+}
\ No newline at end of file
diff --git a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml
index b04e89a33..f55c52312 100644
--- a/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml
+++ b/libreplan-webapp/src/main/resources/libreplan-webapp-spring-config.xml
@@ -78,6 +78,7 @@
+