Wrap concurrent modification exceptions in the web services inside a proper DTO
FEA: ItEr77S04BugFixing
This commit is contained in:
parent
dfe39ab7cb
commit
2d9af66f15
4 changed files with 104 additions and 2 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <rego@igalia.com>
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <rego@igalia.com>
|
||||
*/
|
||||
@Provider
|
||||
@Component("hibernateOptimisticLockingFailureException")
|
||||
public class HibernateOptimisticLockingFailureExceptionMapper implements
|
||||
ExceptionMapper<HibernateOptimisticLockingFailureException> {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -78,6 +78,7 @@
|
|||
<ref bean="runtimeExceptionMapper" />
|
||||
<ref bean="instanceNotFoundExceptionMapper" />
|
||||
<ref bean="incompatibleTypeExceptionMapper" />
|
||||
<ref bean="hibernateOptimisticLockingFailureException" />
|
||||
</jaxrs:providers>
|
||||
<!-- FIXME: in root pom.xml, enable CXF logging on development and
|
||||
disable it in production.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue