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.dump.DumpData; 010 import railo.runtime.dump.DumpProperties; 011 import railo.runtime.engine.ThreadLocalPageContext; 012 import railo.runtime.err.ErrorPage; 013 import railo.runtime.exp.PageException; 014 import railo.runtime.exp.PageExceptionImpl; 015 import railo.runtime.type.Collection; 016 import railo.runtime.type.KeyImpl; 017 import railo.runtime.type.Struct; 018 019 public final class ModernAppListenerException extends PageException { 020 021 private static final Collection.Key ROOT_CAUSE = KeyImpl.intern("rootCause"); 022 private static final Collection.Key CAUSE = KeyImpl.intern("cause"); 023 private PageException rootCause; 024 private String eventName; 025 026 /** 027 * Constructor of the class 028 * @param pe 029 * @param eventName 030 */ 031 public ModernAppListenerException(PageException pe, String eventName) { 032 super(pe.getMessage()); 033 setStackTrace(pe.getStackTrace()); 034 this.rootCause=pe; 035 this.eventName=eventName; 036 } 037 038 /** 039 * 040 * @see railo.runtime.exp.IPageException#addContext(railo.runtime.PageSource, int, int) 041 */ 042 public void addContext(PageSource pageSource, int line, int column, StackTraceElement ste) { 043 rootCause.addContext(pageSource, line, column,ste); 044 } 045 046 /** 047 * 048 * @see railo.runtime.exp.IPageException#getAdditional() 049 */ 050 public Struct getAdditional() { 051 return rootCause.getAddional(); 052 } 053 public Struct getAddional() { 054 return rootCause.getAddional(); 055 } 056 057 /** 058 * @see railo.runtime.exp.IPageException#getCatchBlock() 059 */ 060 public Struct getCatchBlock() { 061 return getCatchBlock(ThreadLocalPageContext.get()); 062 } 063 064 /** 065 * @see railo.runtime.exp.IPageException#getCatchBlock(railo.runtime.PageContext) 066 */ 067 public Struct getCatchBlock(PageContext pc) { 068 069 Struct cb=rootCause.getCatchBlock(pc); 070 Collection cause = cb.duplicate(false); 071 //rtn.setEL("message", getMessage()); 072 if(!cb.containsKey(KeyImpl.DETAIL))cb.setEL(KeyImpl.DETAIL, "Exception throwed while invoking function ["+eventName+"] from Application.cfc"); 073 cb.setEL(ROOT_CAUSE, cause); 074 cb.setEL(CAUSE, cause); 075 //cb.setEL("stacktrace", getStackTraceAsString()); 076 //rtn.setEL("tagcontext", new ArrayImpl()); 077 //rtn.setEL("type", getTypeAsString()); 078 cb.setEL(KeyImpl.NAME, eventName); 079 080 081 082 return cb; 083 } 084 085 /** 086 * 087 * @see railo.runtime.exp.IPageException#getCustomTypeAsString() 088 */ 089 public String getCustomTypeAsString() { 090 return rootCause.getCustomTypeAsString(); 091 } 092 093 /** 094 * 095 * @see railo.runtime.exp.IPageException#getDetail() 096 */ 097 public String getDetail() { 098 return rootCause.getDetail(); 099 } 100 101 /** 102 * 103 * @see railo.runtime.exp.IPageException#getErrorBlock(railo.runtime.PageContext, railo.runtime.err.ErrorPage) 104 */ 105 public Struct getErrorBlock(PageContext pc, ErrorPage ep) { 106 return rootCause.getErrorBlock(pc, ep); 107 } 108 109 /** 110 * 111 * @see railo.runtime.exp.IPageException#getErrorCode() 112 */ 113 public String getErrorCode() { 114 return rootCause.getErrorCode(); 115 } 116 117 /** 118 * 119 * @see railo.runtime.exp.IPageException#getExtendedInfo() 120 */ 121 public String getExtendedInfo() { 122 return rootCause.getExtendedInfo(); 123 } 124 125 /* * 126 * 127 * @see railo.runtime.exp.IPageException#getLine() 128 * / 129 public String getLine() { 130 return rootCause.getLine(); 131 }*/ 132 133 /** 134 * 135 * @see railo.runtime.exp.IPageException#getStackTraceAsString() 136 */ 137 public String getStackTraceAsString() { 138 return rootCause.getStackTraceAsString(); 139 /*StringWriter sw=new StringWriter(); 140 PrintWriter pw=new PrintWriter(sw); 141 printStackTrace(pw); 142 pw.flush(); 143 return sw.toString();*/ 144 } 145 146 /** 147 * 148 * @see railo.runtime.exp.IPageException#getTracePointer() 149 */ 150 public int getTracePointer() { 151 return rootCause.getTracePointer(); 152 } 153 154 /** 155 * 156 * @see railo.runtime.exp.IPageException#getTypeAsString() 157 */ 158 public String getTypeAsString() { 159 return rootCause.getTypeAsString(); 160 } 161 162 /** 163 * 164 * @see railo.runtime.exp.IPageException#setDetail(java.lang.String) 165 */ 166 public void setDetail(String detail) { 167 rootCause.setDetail(detail); 168 } 169 170 /** 171 * 172 * @see railo.runtime.exp.IPageException#setErrorCode(java.lang.String) 173 */ 174 public void setErrorCode(String errorCode) { 175 rootCause.setErrorCode(errorCode); 176 } 177 178 /** 179 * 180 * @see railo.runtime.exp.IPageException#setExtendedInfo(java.lang.String) 181 */ 182 public void setExtendedInfo(String extendedInfo) { 183 rootCause.setExtendedInfo(extendedInfo); 184 } 185 186 /** 187 * 188 * @see railo.runtime.exp.IPageException#setTracePointer(int) 189 */ 190 public void setTracePointer(int tracePointer) { 191 rootCause.setTracePointer(tracePointer); 192 } 193 194 /** 195 * 196 * @see railo.runtime.exp.IPageException#typeEqual(java.lang.String) 197 */ 198 public boolean typeEqual(String type) { 199 return rootCause.equals(type); 200 } 201 202 /** 203 * @see railo.runtime.dump.Dumpable#toDumpData(railo.runtime.PageContext, int) 204 */ 205 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 206 return rootCause.toDumpData(pageContext,maxlevel,dp); 207 } 208 209 /** 210 * @return the eventName 211 */ 212 public String getEventName() { 213 return eventName; 214 } 215 216 /** 217 * 218 * @see railo.runtime.exp.PageExceptionImpl#getLine(railo.runtime.PageContext) 219 */ 220 public String getLine(Config config) { 221 return ((PageExceptionImpl)rootCause).getLine(config); 222 } 223 224 /** 225 * 226 * @see railo.runtime.exp.PageExceptionImpl#getRootCause() 227 */ 228 public Throwable getRootCause() { 229 return rootCause.getRootCause(); 230 } 231 232 /** 233 * 234 * @see railo.runtime.exp.PageExceptionImpl#getStackTrace() 235 */ 236 public StackTraceElement[] getStackTrace() { 237 return rootCause.getStackTrace(); 238 } 239 240 /** 241 * 242 * @see railo.runtime.exp.PageExceptionImpl#printStackTrace() 243 */ 244 public void printStackTrace() { 245 rootCause.printStackTrace(); 246 } 247 248 /** 249 * 250 * @see railo.runtime.exp.PageExceptionImpl#printStackTrace(java.io.PrintStream) 251 */ 252 public void printStackTrace(PrintStream s) { 253 rootCause.printStackTrace(s); 254 } 255 256 /** 257 * 258 * @see railo.runtime.exp.PageExceptionImpl#printStackTrace(java.io.PrintWriter) 259 */ 260 public void printStackTrace(PrintWriter s) { 261 rootCause.printStackTrace(s); 262 } 263 264 /** 265 * @see railo.runtime.exp.PageExceptionBox#getPageException() 266 */ 267 public PageException getPageException() { 268 return rootCause; 269 } 270 271 }