| 1 |
|
package org.trails.exception; |
| 2 |
|
|
| 3 |
|
import java.io.IOException; |
| 4 |
|
|
| 5 |
|
import org.apache.commons.logging.Log; |
| 6 |
|
import org.apache.commons.logging.LogFactory; |
| 7 |
|
import org.apache.tapestry.IPage; |
| 8 |
|
import org.apache.tapestry.IRequestCycle; |
| 9 |
|
import org.apache.tapestry.error.ExceptionPresenterImpl; |
| 10 |
|
import org.trails.exception.TrailsRuntimeException; |
| 11 |
|
import org.trails.page.PageResolver; |
| 12 |
|
import org.trails.page.PageType; |
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
0 |
public class ApplicationExceptionPresenterImpl extends ExceptionPresenterImpl { |
| 21 |
0 |
private static final Log log = LogFactory.getLog(ApplicationExceptionPresenterImpl.class); |
| 22 |
|
private PageResolver pageResolver; |
| 23 |
|
|
| 24 |
|
public void presentException(IRequestCycle cycle, Throwable throwable) { |
| 25 |
0 |
if (throwable.getCause() == null || !(throwable.getCause() instanceof TrailsRuntimeException)) { |
| 26 |
0 |
super.presentException(cycle, throwable); |
| 27 |
0 |
return; |
| 28 |
|
} |
| 29 |
0 |
TrailsRuntimeException trailsRuntimeException = (TrailsRuntimeException)throwable.getCause(); |
| 30 |
|
|
| 31 |
0 |
if (log.isWarnEnabled()) |
| 32 |
|
{ |
| 33 |
0 |
if (trailsRuntimeException.getEntityType() == null) |
| 34 |
|
{ |
| 35 |
0 |
log.warn("Trails specific exception happened while handling unknown entity, caused by: " + throwable.getCause().getMessage()); |
| 36 |
|
} else |
| 37 |
|
{ |
| 38 |
0 |
log.warn("Trails specific exception happened while handling entity type " + trailsRuntimeException.getEntityType().getName() + ", caused by: " + throwable.getCause().getMessage()); |
| 39 |
|
} |
| 40 |
|
} |
| 41 |
0 |
log.debug("The problem was caused by: ", throwable.getCause()); |
| 42 |
0 |
IPage page = pageResolver.resolvePage(cycle, trailsRuntimeException.getEntityType(), PageType.EXCEPTION); |
| 43 |
0 |
cycle.activate(page); |
| 44 |
|
try { |
| 45 |
0 |
cycle.getResponseBuilder().renderResponse(cycle); |
| 46 |
0 |
} catch (IOException e) { |
| 47 |
0 |
log.error("Couldn't render a Trails specific error page because of : ", e); |
| 48 |
0 |
super.presentException(cycle, throwable); |
| 49 |
|
} |
| 50 |
0 |
} |
| 51 |
|
|
| 52 |
|
public void setPageResolver(PageResolver pageResolver) { |
| 53 |
0 |
this.pageResolver = pageResolver; |
| 54 |
0 |
} |
| 55 |
|
} |