001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.listener; 020 021import java.io.PrintStream; 022import java.io.PrintWriter; 023 024import lucee.runtime.PageContext; 025import lucee.runtime.PageSource; 026import lucee.runtime.config.Config; 027import lucee.runtime.config.Constants; 028import lucee.runtime.dump.DumpData; 029import lucee.runtime.dump.DumpProperties; 030import lucee.runtime.engine.ThreadLocalPageContext; 031import lucee.runtime.err.ErrorPage; 032import lucee.runtime.exp.CatchBlock; 033import lucee.runtime.exp.PageException; 034import lucee.runtime.exp.PageExceptionImpl; 035import lucee.runtime.op.Duplicator; 036import lucee.runtime.type.Collection; 037import lucee.runtime.type.KeyImpl; 038import lucee.runtime.type.Struct; 039import lucee.runtime.type.util.KeyConstants; 040 041public final class ModernAppListenerException extends PageException { 042 043 private static final Collection.Key ROOT_CAUSE = KeyImpl.intern("rootCause"); 044 private static final Collection.Key CAUSE = KeyImpl.intern("cause"); 045 private PageException rootCause; 046 private String eventName; 047 048 /** 049 * Constructor of the class 050 * @param pe 051 * @param eventName 052 */ 053 public ModernAppListenerException(PageException pe, String eventName) { 054 super(pe.getMessage()); 055 setStackTrace(pe.getStackTrace()); 056 this.rootCause=pe; 057 this.eventName=eventName; 058 } 059 060 @Override 061 public void addContext(PageSource pageSource, int line, int column, StackTraceElement ste) { 062 rootCause.addContext(pageSource, line, column,ste); 063 } 064 065 @Override 066 public Struct getAdditional() { 067 return rootCause.getAddional(); 068 } 069 070 @Override 071 public Struct getAddional() { 072 return rootCause.getAddional(); 073 } 074 075 public Struct getCatchBlock() { 076 return getCatchBlock(ThreadLocalPageContext.getConfig()); 077 } 078 079 @Override 080 public Struct getCatchBlock(PageContext pc) { 081 return getCatchBlock(pc.getConfig()); 082 } 083 084 @Override 085 public CatchBlock getCatchBlock(Config config) { 086 CatchBlock cb=rootCause.getCatchBlock(config); 087 Collection cause = (Collection) Duplicator.duplicate(cb,false); 088 //rtn.setEL("message", getMessage()); 089 if(!cb.containsKey(KeyConstants._detail))cb.setEL(KeyConstants._detail, "Exception throwed while invoking function ["+eventName+"] from "+Constants.APP_CFC); 090 cb.setEL(ROOT_CAUSE, cause); 091 cb.setEL(CAUSE, cause); 092 //cb.setEL("stacktrace", getStackTraceAsString()); 093 //rtn.setEL("tagcontext", new ArrayImpl()); 094 //rtn.setEL("type", getTypeAsString()); 095 cb.setEL(KeyConstants._name, eventName); 096 return cb; 097 } 098 099 @Override 100 public String getCustomTypeAsString() { 101 return rootCause.getCustomTypeAsString(); 102 } 103 104 @Override 105 public String getDetail() { 106 return rootCause.getDetail(); 107 } 108 109 @Override 110 public Struct getErrorBlock(PageContext pc, ErrorPage ep) { 111 return rootCause.getErrorBlock(pc, ep); 112 } 113 114 @Override 115 public String getErrorCode() { 116 return rootCause.getErrorCode(); 117 } 118 119 @Override 120 public String getExtendedInfo() { 121 return rootCause.getExtendedInfo(); 122 } 123 124 @Override 125 public String getStackTraceAsString() { 126 return rootCause.getStackTraceAsString(); 127 } 128 129 @Override 130 public int getTracePointer() { 131 return rootCause.getTracePointer(); 132 } 133 134 @Override 135 public String getTypeAsString() { 136 return rootCause.getTypeAsString(); 137 } 138 139 @Override 140 public void setDetail(String detail) { 141 rootCause.setDetail(detail); 142 } 143 144 @Override 145 public void setErrorCode(String errorCode) { 146 rootCause.setErrorCode(errorCode); 147 } 148 149 @Override 150 public void setExtendedInfo(String extendedInfo) { 151 rootCause.setExtendedInfo(extendedInfo); 152 } 153 154 @Override 155 public void setTracePointer(int tracePointer) { 156 rootCause.setTracePointer(tracePointer); 157 } 158 159 @Override 160 public boolean typeEqual(String type) { 161 return rootCause.equals(type); 162 } 163 164 @Override 165 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 166 return rootCause.toDumpData(pageContext,maxlevel,dp); 167 } 168 169 /** 170 * @return the eventName 171 */ 172 public String getEventName() { 173 return eventName; 174 } 175 176 public String getLine(Config config) { 177 return ((PageExceptionImpl)rootCause).getLine(config); 178 } 179 180 @Override 181 public Throwable getRootCause() { 182 return rootCause.getRootCause(); 183 } 184 185 @Override 186 public StackTraceElement[] getStackTrace() { 187 return rootCause.getStackTrace(); 188 } 189 190 @Override 191 public void printStackTrace() { 192 rootCause.printStackTrace(); 193 } 194 195 @Override 196 public void printStackTrace(PrintStream s) { 197 rootCause.printStackTrace(s); 198 } 199 200 @Override 201 public void printStackTrace(PrintWriter s) { 202 rootCause.printStackTrace(s); 203 } 204 205 public PageException getPageException() { 206 return rootCause; 207 } 208 209}