X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ee%2Fsrc%2Forg%2Fargeo%2Fcms%2Fintegration%2FCmsExceptionsChain.java;h=205699464f43aab954127acb2cb82faa211f676d;hb=1d6840195189cbdbf632ca2800b6179d3b6349df;hp=fb289c18e946de59dbe2c85a4d25bc76a81687bb;hpb=6832a0807e45e70c23b22598874807a3a9373475;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ee/src/org/argeo/cms/integration/CmsExceptionsChain.java b/org.argeo.cms.ee/src/org/argeo/cms/integration/CmsExceptionsChain.java index fb289c18e..205699464 100644 --- a/org.argeo.cms.ee/src/org/argeo/cms/integration/CmsExceptionsChain.java +++ b/org.argeo.cms.ee/src/org/argeo/cms/integration/CmsExceptionsChain.java @@ -2,29 +2,26 @@ package org.argeo.cms.integration; import java.io.IOException; import java.io.Writer; -import java.util.ArrayList; -import java.util.List; import javax.servlet.http.HttpServletResponse; import org.argeo.api.cms.CmsLog; +import org.argeo.util.ExceptionsChain; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; /** Serialisable wrapper of a {@link Throwable}. */ -public class CmsExceptionsChain { +public class CmsExceptionsChain extends ExceptionsChain { public final static CmsLog log = CmsLog.getLog(CmsExceptionsChain.class); - private List exceptions = new ArrayList<>(); - public CmsExceptionsChain() { super(); } public CmsExceptionsChain(Throwable exception) { - writeException(exception); + super(exception); if (log.isDebugEnabled()) log.error("Exception chain", exception); } @@ -56,77 +53,6 @@ public class CmsExceptionsChain { } } - /** recursive */ - protected void writeException(Throwable exception) { - SystemException systemException = new SystemException(exception); - exceptions.add(systemException); - Throwable cause = exception.getCause(); - if (cause != null) - writeException(cause); - } - - public List getExceptions() { - return exceptions; - } - - public void setExceptions(List exceptions) { - this.exceptions = exceptions; - } - - /** An exception in the chain. */ - public static class SystemException { - private String type; - private String message; - private List stackTrace; - - public SystemException() { - } - - public SystemException(Throwable exception) { - this.type = exception.getClass().getName(); - this.message = exception.getMessage(); - this.stackTrace = new ArrayList<>(); - StackTraceElement[] elems = exception.getStackTrace(); - for (int i = 0; i < elems.length; i++) - stackTrace.add("at " + elems[i].toString()); - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public List getStackTrace() { - return stackTrace; - } - - public void setStackTrace(List stackTrace) { - this.stackTrace = stackTrace; - } - - @Override - public String toString() { - return "System exception: " + type + ", " + message + ", " + stackTrace; - } - - } - - @Override - public String toString() { - return exceptions.toString(); - } - // public static void main(String[] args) throws Exception { // try { // try { @@ -139,9 +65,9 @@ public class CmsExceptionsChain { // throw new RuntimeException("Top exception", e); // } // } catch (Exception e) { -// CmsExceptionsChain vjeSystemErrors = new CmsExceptionsChain(e); +// CmsExceptionsChain systemErrors = new CmsExceptionsChain(e); // ObjectMapper objectMapper = new ObjectMapper(); -// System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(vjeSystemErrors)); +// System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(systemErrors)); // System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(e)); // e.printStackTrace(); // }