X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Fintegration%2FCmsExceptionsChain.java;h=2ee1c30dd3d4b401e01d5490466b2cb18e0e849d;hb=c4e6e4221851cbd7e0978ea27e2ed1e29d65ffba;hp=d7a51b74a96f6770bdf8b82620aa3d2fee73f90e;hpb=cd49755b0b4d287d7bc3bb91e1eb6cb3dc70c561;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/integration/CmsExceptionsChain.java b/org.argeo.cms/src/org/argeo/cms/integration/CmsExceptionsChain.java index d7a51b74a..2ee1c30dd 100644 --- a/org.argeo.cms/src/org/argeo/cms/integration/CmsExceptionsChain.java +++ b/org.argeo.cms/src/org/argeo/cms/integration/CmsExceptionsChain.java @@ -5,6 +5,8 @@ import java.io.Writer; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.argeo.util.ExceptionsChain; import com.fasterxml.jackson.core.JsonGenerator; @@ -13,17 +15,21 @@ import com.fasterxml.jackson.databind.ObjectMapper; /** Serialisable wrapper of a {@link Throwable}. */ public class CmsExceptionsChain extends ExceptionsChain { + public final static Log log = LogFactory.getLog(CmsExceptionsChain.class); + public CmsExceptionsChain() { super(); } public CmsExceptionsChain(Throwable exception) { super(exception); + if (log.isDebugEnabled()) + log.error("Exception chain", exception); } public String toJsonString(ObjectMapper objectMapper) { try { - return objectMapper.writeValueAsString(this); + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); } catch (JsonProcessingException e) { throw new IllegalStateException("Cannot write system exceptions " + toString(), e); } @@ -31,7 +37,7 @@ public class CmsExceptionsChain extends ExceptionsChain { public void writeAsJson(ObjectMapper objectMapper, Writer writer) { try { - JsonGenerator jg = objectMapper.getFactory().createGenerator(writer); + JsonGenerator jg = objectMapper.writerWithDefaultPrettyPrinter().getFactory().createGenerator(writer); jg.writeObject(this); } catch (IOException e) { throw new IllegalStateException("Cannot write system exceptions " + toString(), e); @@ -48,27 +54,27 @@ public class CmsExceptionsChain extends ExceptionsChain { } } - public static void main(String[] args) throws Exception { - try { - try { - try { - testDeeper(); - } catch (Exception e) { - throw new Exception("Less deep exception", e); - } - } catch (Exception e) { - throw new RuntimeException("Top exception", e); - } - } catch (Exception e) { - CmsExceptionsChain vjeSystemErrors = new CmsExceptionsChain(e); - ObjectMapper objectMapper = new ObjectMapper(); - System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(vjeSystemErrors)); - e.printStackTrace(); - } - } - - static void testDeeper() throws Exception { - throw new IllegalStateException("Deep exception"); - } +// public static void main(String[] args) throws Exception { +// try { +// try { +// try { +// testDeeper(); +// } catch (Exception e) { +// throw new Exception("Less deep exception", e); +// } +// } catch (Exception e) { +// throw new RuntimeException("Top exception", e); +// } +// } catch (Exception e) { +// CmsExceptionsChain vjeSystemErrors = new CmsExceptionsChain(e); +// ObjectMapper objectMapper = new ObjectMapper(); +// System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(vjeSystemErrors)); +// e.printStackTrace(); +// } +// } +// +// static void testDeeper() throws Exception { +// throw new IllegalStateException("Deep exception"); +// } }