001 package railo.runtime.listener; 002 003 import java.io.PrintStream; 004 import java.io.PrintWriter; 005 006 import railo.runtime.PageContext; 007 import railo.runtime.PageSource; 008 import railo.runtime.config.Config; 009 import railo.runtime.config.Constants; 010 import railo.runtime.dump.DumpData; 011 import railo.runtime.dump.DumpProperties; 012 import railo.runtime.engine.ThreadLocalPageContext; 013 import railo.runtime.err.ErrorPage; 014 import railo.runtime.exp.CatchBlock; 015 import railo.runtime.exp.PageException; 016 import railo.runtime.exp.PageExceptionImpl; 017 import railo.runtime.op.Duplicator; 018 import railo.runtime.type.Collection; 019 import railo.runtime.type.KeyImpl; 020 import railo.runtime.type.Struct; 021 import railo.runtime.type.util.KeyConstants; 022 023 public final class ModernAppListenerException extends PageException { 024 025 private static final Collection.Key ROOT_CAUSE = KeyImpl.intern("rootCause"); 026 private static final Collection.Key CAUSE = KeyImpl.intern("cause"); 027 private PageException rootCause; 028 private String eventName; 029 030 /** 031 * Constructor of the class 032 * @param pe 033 * @param eventName 034 */ 035 public ModernAppListenerException(PageException pe, String eventName) { 036 super(pe.getMessage()); 037 setStackTrace(pe.getStackTrace()); 038 this.rootCause=pe; 039 this.eventName=eventName; 040 } 041 042 @Override 043 public void addContext(PageSource pageSource, int line, int column, StackTraceElement ste) { 044 rootCause.addContext(pageSource, line, column,ste); 045 } 046 047 @Override 048 public Struct getAdditional() { 049 return rootCause.getAddional(); 050 } 051 052 @Override 053 public Struct getAddional() { 054 return rootCause.getAddional(); 055 } 056 057 public Struct getCatchBlock() { 058 return getCatchBlock(ThreadLocalPageContext.getConfig()); 059 } 060 061 @Override 062 public Struct getCatchBlock(PageContext pc) { 063 return getCatchBlock(pc.getConfig()); 064 } 065 066 @Override 067 public CatchBlock getCatchBlock(Config config) { 068 CatchBlock cb=rootCause.getCatchBlock(config); 069 Collection cause = (Collection) Duplicator.duplicate(cb,false); 070 //rtn.setEL("message", getMessage()); 071 if(!cb.containsKey(KeyConstants._detail))cb.setEL(KeyConstants._detail, "Exception throwed while invoking function ["+eventName+"] from "+Constants.APP_CFC); 072 cb.setEL(ROOT_CAUSE, cause); 073 cb.setEL(CAUSE, cause); 074 //cb.setEL("stacktrace", getStackTraceAsString()); 075 //rtn.setEL("tagcontext", new ArrayImpl()); 076 //rtn.setEL("type", getTypeAsString()); 077 cb.setEL(KeyConstants._name, eventName); 078 return cb; 079 } 080 081 @Override 082 public String getCustomTypeAsString() { 083 return rootCause.getCustomTypeAsString(); 084 } 085 086 @Override 087 public String getDetail() { 088 return rootCause.getDetail(); 089 } 090 091 @Override 092 public Struct getErrorBlock(PageContext pc, ErrorPage ep) { 093 return rootCause.getErrorBlock(pc, ep); 094 } 095 096 @Override 097 public String getErrorCode() { 098 return rootCause.getErrorCode(); 099 } 100 101 @Override 102 public String getExtendedInfo() { 103 return rootCause.getExtendedInfo(); 104 } 105 106 @Override 107 public String getStackTraceAsString() { 108 return rootCause.getStackTraceAsString(); 109 } 110 111 @Override 112 public int getTracePointer() { 113 return rootCause.getTracePointer(); 114 } 115 116 @Override 117 public String getTypeAsString() { 118 return rootCause.getTypeAsString(); 119 } 120 121 @Override 122 public void setDetail(String detail) { 123 rootCause.setDetail(detail); 124 } 125 126 @Override 127 public void setErrorCode(String errorCode) { 128 rootCause.setErrorCode(errorCode); 129 } 130 131 @Override 132 public void setExtendedInfo(String extendedInfo) { 133 rootCause.setExtendedInfo(extendedInfo); 134 } 135 136 @Override 137 public void setTracePointer(int tracePointer) { 138 rootCause.setTracePointer(tracePointer); 139 } 140 141 @Override 142 public boolean typeEqual(String type) { 143 return rootCause.equals(type); 144 } 145 146 @Override 147 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 148 return rootCause.toDumpData(pageContext,maxlevel,dp); 149 } 150 151 /** 152 * @return the eventName 153 */ 154 public String getEventName() { 155 return eventName; 156 } 157 158 public String getLine(Config config) { 159 return ((PageExceptionImpl)rootCause).getLine(config); 160 } 161 162 @Override 163 public Throwable getRootCause() { 164 return rootCause.getRootCause(); 165 } 166 167 @Override 168 public StackTraceElement[] getStackTrace() { 169 return rootCause.getStackTrace(); 170 } 171 172 @Override 173 public void printStackTrace() { 174 rootCause.printStackTrace(); 175 } 176 177 @Override 178 public void printStackTrace(PrintStream s) { 179 rootCause.printStackTrace(s); 180 } 181 182 @Override 183 public void printStackTrace(PrintWriter s) { 184 rootCause.printStackTrace(s); 185 } 186 187 public PageException getPageException() { 188 return rootCause; 189 } 190 191 }