1 16 package org.directwebremoting.servlet; 17 18 import java.io.IOException ; 19 import java.io.PrintWriter ; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 24 import org.directwebremoting.extend.Handler; 25 import org.directwebremoting.util.Continuation; 26 import org.directwebremoting.util.Logger; 27 import org.directwebremoting.util.MimeConstants; 28 29 33 public class ExceptionHandler implements Handler 34 { 35 38 public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException 39 { 40 Continuation.rethrowIfContinuation(cause); 42 43 log.warn("Error: " + cause); 44 if (cause instanceof SecurityException && log.isDebugEnabled()) 45 { 46 log.debug("- User Agent: " + request.getHeader(HttpConstants.HEADER_USER_AGENT)); 47 log.debug("- Remote IP: " + request.getRemoteAddr()); 48 log.debug("- Request URL:" + request.getRequestURL()); 49 log.debug("- Query: " + request.getQueryString()); 50 log.debug("- Method: " + request.getMethod()); 51 } 52 53 response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); 59 response.setContentType(MimeConstants.MIME_HTML); 60 PrintWriter out = response.getWriter(); 61 out.println(cause.getMessage()); 62 63 log.warn("Sent 501", cause); 64 } 65 66 69 public void setException(Exception cause) 70 { 71 this.cause = cause; 72 } 73 74 77 private Exception cause; 78 79 82 private static final Logger log = Logger.getLogger(ExceptionHandler.class); 83 } 84 | Popular Tags |