1 23 24 package com.sun.enterprise.tools.guiframework.event.handlers; 25 26 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 27 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 28 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent; 29 30 import com.iplanet.jato.RequestContext; 31 import com.iplanet.jato.RequestManager; 32 import com.iplanet.jato.view.View; 33 import com.iplanet.jato.view.ViewBean; 34 import com.iplanet.jato.view.event.ChildContentDisplayEvent; 35 import com.iplanet.jato.view.event.JspDisplayEvent; 36 37 import java.util.EventObject ; 38 39 import javax.servlet.ServletRequest ; 40 41 42 45 public class ErrorHandler { 46 47 80 public void handleError(RequestContext reqCtx, HandlerContext handlerCtx) { 81 ErrorEvent errEvent = (ErrorEvent)handlerCtx.getEvent(); 82 83 ServletRequest request = 84 RequestManager.getRequestContext().getRequest(); 85 86 handlerCtx.setOutputValue(EXCEPTION, 87 errEvent.getException()); 88 89 handlerCtx.setOutputValue(EXCEPTION_MESSAGE, 90 errEvent.getExceptionMessage()); 91 92 handlerCtx.setOutputValue(EXCEPTION_CLASS_NAME, 93 errEvent.getExceptionClassName()); 94 95 View vw = errEvent.getView(); 96 handlerCtx.setOutputValue(EXCEPTION_VIEW, vw); 97 98 handlerCtx.setOutputValue(EXCEPTION_VIEW_NAME, 99 (vw == null) ? "(Null View)" : vw.getName()); 100 101 ViewDescriptor desc = errEvent.getViewDescriptor(); 102 handlerCtx.setOutputValue(EXCEPTION_VIEW_DESCRIPTOR, desc); 103 104 handlerCtx.setOutputValue(EXCEPTION_VIEW_DESCRIPTOR_NAME, 105 (desc == null) ? "(Null ViewDescriptor)" : desc.getName()); 106 107 vw = errEvent.getViewBean(); 108 handlerCtx.setOutputValue(EXCEPTION_VIEW_BEAN, vw); 109 110 handlerCtx.setOutputValue(EXCEPTION_VIEW_BEAN_NAME, 111 (vw == null) ? "(Null ViewBean)" : vw.getName()); 112 113 handlerCtx.setOutputValue(EXCEPTION_STACK_TRACE, 114 errEvent.getRegularTrace()); 115 116 handlerCtx.setOutputValue(EXCEPTION_CAUSE_VIEW, 117 errEvent.getCauseView()); 118 119 handlerCtx.setOutputValue(EXCEPTION_CAUSE_VIEW_DESCRIPTOR, 120 errEvent.getCauseViewDescriptor()); 121 122 handlerCtx.setOutputValue(EXCEPTION_CAUSE_MESSAGE, 123 errEvent.getCauseMessage()); 124 125 handlerCtx.setOutputValue(EXCEPTION_CAUSE_CLASS_NAME, 126 errEvent.getCauseClassName()); 127 128 handlerCtx.setOutputValue(EXCEPTION_CAUSE_FULL_TRACE, 129 errEvent.getFullTrace()); 130 131 java.util.Enumeration names = request.getParameterNames(); 133 String name = null; 134 String nvps = ""; 135 while (names.hasMoreElements()) { 136 name = names.nextElement().toString(); 137 nvps += "\t'"+name+"'='"+request.getParameter(name)+"'\n"; 138 } 139 handlerCtx.setOutputValue(REQUEST_PARAMETERS, nvps); 140 } 141 142 public void printTag(RequestContext reqCtx, HandlerContext handlerCtx) { 143 System.out.println("#######"); 144 System.out.println("The tag object = "+((JspDisplayEvent)handlerCtx.getEvent()).getSourceTag()); 145 System.out.println("#######"); 146 } 147 148 154 public String addErrorInfo(RequestContext reqCtx, HandlerContext handlerCtx) { 155 if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) { 156 return null; 157 } 158 ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent(); 159 ServletRequest request = 160 RequestManager.getRequestContext().getRequest(); 161 162 StringBuffer buf = new StringBuffer (dispEvent.getContent()); 164 buf.append("\n\n<!--\n\n"); 165 buf.append(" Exception Info:\n"); 166 buf.append("===================\n\n"); 167 buf.append(" Exception Type: "+ 168 request.getAttribute(EXCEPTION_CLASS_NAME)+"\n"); 169 buf.append(" Exception Message: "+ 170 request.getAttribute(EXCEPTION_MESSAGE)+"\n"); 171 buf.append(" Root Cause: "+ 172 request.getAttribute(EXCEPTION_CAUSE_CLASS_NAME)+"\n"); 173 buf.append(" Root Message: "+ 174 request.getAttribute(EXCEPTION_CAUSE_MESSAGE)+"\n\n"); 175 buf.append("===================\n\n"); 176 177 buf.append(" View Info:\n"); 178 buf.append("===================\n\n"); 179 buf.append(" ViewBean: "+ 180 request.getAttribute(EXCEPTION_VIEW_BEAN_NAME)+"\n"); 181 buf.append(" View: "+ 182 request.getAttribute(EXCEPTION_VIEW_NAME)+"\n"); 183 buf.append(" ViewDescriptor: "+ 184 request.getAttribute(EXCEPTION_VIEW_DESCRIPTOR_NAME)+"\n"); 185 buf.append("Request Parameters:\n"+ 186 request.getAttribute(REQUEST_PARAMETERS)+"\n\n"); 187 buf.append("==================\n\n"); 188 189 buf.append("Below are 2 stack traces to help diagnose the problem.\n"); 190 buf.append("The first is the traditional stack trace, the second is\n"); 191 buf.append("a full stack trace to the root cause.\n\n"); 192 buf.append(" Stack Trace:\n"); 193 buf.append("===================\n\n"); 194 buf.append(""+request.getAttribute(EXCEPTION_STACK_TRACE)+"\n\n"); 195 buf.append(" Full Trace:\n"); 196 buf.append("===================\n\n"); 197 buf.append(""+request.getAttribute(EXCEPTION_CAUSE_FULL_TRACE)+"\n\n"); 198 buf.append("===================\n\n"); 199 buf.append("-->\n\n"); 200 201 return buf.toString(); 202 } 203 204 205 206 210 211 214 public static final String EXCEPTION = 215 "EXCEPTION"; 216 217 220 public static final String EXCEPTION_MESSAGE = 221 "EXCEPTION_MESSAGE"; 222 223 226 public static final String EXCEPTION_CLASS_NAME = 227 "EXCEPTION_CLASS_NAME"; 228 229 233 public static final String EXCEPTION_VIEW = 234 "EXCEPTION_VIEW"; 235 236 240 public static final String EXCEPTION_VIEW_NAME = 241 "EXCEPTION_VIEW_NAME"; 242 243 247 public static final String EXCEPTION_VIEW_DESCRIPTOR = 248 "EXCEPTION_VIEW_DESCRIPTOR"; 249 250 254 public static final String EXCEPTION_VIEW_DESCRIPTOR_NAME = 255 "EXCEPTION_VIEW_DESCRIPTOR_NAME"; 256 257 261 public static final String EXCEPTION_VIEW_BEAN = 262 "EXCEPTION_VIEW_BEAN"; 263 264 268 public static final String EXCEPTION_VIEW_BEAN_NAME = 269 "EXCEPTION_VIEW_BEAN_NAME"; 270 271 274 public static final String EXCEPTION_STACK_TRACE = 275 "EXCEPTION_STACK_TRACE"; 276 277 280 public static final String EXCEPTION_CAUSE_VIEW = 281 "EXCEPTION_CAUSE_VIEW"; 282 283 286 public static final String EXCEPTION_CAUSE_VIEW_DESCRIPTOR = 287 "EXCEPTION_CAUSE_VIEW_DESCRIPTOR"; 288 289 293 public static final String EXCEPTION_CAUSE_MESSAGE = 294 "EXCEPTION_CAUSE_MESSAGE"; 295 296 300 public static final String EXCEPTION_CAUSE_CLASS_NAME = 301 "EXCEPTION_CAUSE_CLASS_NAME"; 302 303 306 public static final String EXCEPTION_CAUSE_FULL_TRACE = 307 "EXCEPTION_CAUSE_FULL_TRACE"; 308 309 312 public static final String REQUEST_PARAMETERS = "REQUEST_PARAMETERS"; 313 } 314 | Popular Tags |