Changeset 3b915f27791d92c0f752284b6d87c01a6bc02c22
- Timestamp:
- 04/18/08 09:34:36
(3 months ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1208504076 +0200
- git-parent:
[f85a0d828cf011ce0d843fb436e994aa4930594e]
- git-author:
- Christopher Jung <bktheg@web.de> 1208504076 +0200
- Message:
Bessere Fehlerbehandlung am Anfang und Ende einer Request
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r9ee106f |
r3b915f2 |
|
| 81 | 81 | this.request = request; |
|---|
| 82 | 82 | this.response = response; |
|---|
| 83 | | |
|---|
| 84 | | revalidate(); |
|---|
| 85 | 83 | } |
|---|
| 86 | 84 | |
|---|
| re409332 |
r3b915f2 |
|
| 22 | 22 | import java.io.PrintWriter; |
|---|
| 23 | 23 | import java.util.Date; |
|---|
| | 24 | import java.util.Iterator; |
|---|
| | 25 | import java.util.Map; |
|---|
| 24 | 26 | |
|---|
| | 27 | import javax.servlet.Filter; |
|---|
| 25 | 28 | import javax.servlet.FilterChain; |
|---|
| 26 | 29 | import javax.servlet.FilterConfig; |
|---|
| … | … | |
| 28 | 31 | import javax.servlet.ServletException; |
|---|
| 29 | 32 | import javax.servlet.ServletRequest; |
|---|
| 30 | | import javax.servlet.Filter; |
|---|
| 31 | 33 | import javax.servlet.ServletResponse; |
|---|
| 32 | 34 | import javax.servlet.http.HttpServlet; |
|---|
| … | … | |
| 58 | 60 | return; |
|---|
| 59 | 61 | } |
|---|
| 60 | | |
|---|
| | 62 | |
|---|
| 61 | 63 | HttpServletRequest httpRequest = (HttpServletRequest)req; |
|---|
| 62 | 64 | HttpServletResponse httpResponse = (HttpServletResponse)resp; |
|---|
| 63 | 65 | |
|---|
| 64 | | //Refferer verstecken, um Abgreifen der sessid zu vermeiden |
|---|
| 65 | | httpResponse.setHeader("Referer", "http://ds.drifting-souls.net"); |
|---|
| 66 | | |
|---|
| 67 | | Request request = new HttpRequest(httpRequest); |
|---|
| 68 | | Response response = new HttpResponse(httpResponse); |
|---|
| 69 | | |
|---|
| 70 | | final BasicContext context = new BasicContext(request, response); |
|---|
| 71 | | |
|---|
| 72 | | context.putVariable(HttpServlet.class, "response", httpResponse); |
|---|
| 73 | | context.putVariable(HttpServlet.class, "request", httpRequest); |
|---|
| 74 | | context.putVariable(HttpServlet.class, "context", this.context); |
|---|
| 75 | | context.putVariable(HttpServlet.class, "chain", chain); |
|---|
| 76 | | |
|---|
| 77 | 66 | try { |
|---|
| | 67 | // Refferer verstecken, um Abgreifen der sessid zu vermeiden |
|---|
| | 68 | httpResponse.setHeader("Referer", "http://ds.drifting-souls.net"); |
|---|
| | 69 | |
|---|
| | 70 | Request request = new HttpRequest(httpRequest); |
|---|
| | 71 | Response response = new HttpResponse(httpResponse); |
|---|
| | 72 | |
|---|
| | 73 | BasicContext context = null; |
|---|
| | 74 | |
|---|
| 78 | 75 | try { |
|---|
| 79 | | Pipeline pipeline = PipelineConfig.getPipelineForContext(context); |
|---|
| | 76 | context = new BasicContext(request, response); |
|---|
| | 77 | context.putVariable(HttpServlet.class, "response", httpResponse); |
|---|
| | 78 | context.putVariable(HttpServlet.class, "request", httpRequest); |
|---|
| | 79 | context.putVariable(HttpServlet.class, "context", this.context); |
|---|
| | 80 | context.putVariable(HttpServlet.class, "chain", chain); |
|---|
| 80 | 81 | |
|---|
| 81 | | if( pipeline != null ) { |
|---|
| 82 | | pipeline.execute(context); |
|---|
| | 82 | context.revalidate(); |
|---|
| | 83 | |
|---|
| | 84 | try { |
|---|
| | 85 | Pipeline pipeline = PipelineConfig.getPipelineForContext(context); |
|---|
| | 86 | |
|---|
| | 87 | if( pipeline != null ) { |
|---|
| | 88 | pipeline.execute(context); |
|---|
| | 89 | } |
|---|
| | 90 | else { |
|---|
| | 91 | throw new Exception("Unable to find a suitable rule for URL '"+context.getRequest().getRequestURL()+(context.getRequest().getQueryString() != null ? "?"+context.getRequest().getQueryString() : "")+"'"); |
|---|
| | 92 | } |
|---|
| | 93 | |
|---|
| | 94 | context.getResponse().send(); |
|---|
| 83 | 95 | } |
|---|
| 84 | | else { |
|---|
| 85 | | throw new Exception("Unable to find a suitable rule for URL '"+context.getRequest().getRequestURL()+(context.getRequest().getQueryString() != null ? "?"+context.getRequest().getQueryString() : "")+"'"); |
|---|
| | 96 | catch( Throwable e ) { |
|---|
| | 97 | context.rollback(); |
|---|
| | 98 | |
|---|
| | 99 | mailThrowable(httpRequest, context, e); |
|---|
| | 100 | |
|---|
| | 101 | e.printStackTrace(); |
|---|
| | 102 | httpResponse.setContentType("text/html"); |
|---|
| | 103 | PrintWriter writer = httpResponse.getWriter(); |
|---|
| | 104 | writer.append("<html><head><title>Drifting Souls Server Framework</title></head>"); |
|---|
| | 105 | writer.append("<body>"); |
|---|
| | 106 | writer.append("<table border=\"0\"><tr><td>\n"); |
|---|
| | 107 | writer.append("<div align=\"center\">\n"); |
|---|
| | 108 | writer.append("<h1>Drifting Souls Server Framework</h1>"); |
|---|
| | 109 | writer.append("Unhandled Exception "+e.getClass().getName()+" during pipeline execution detected<br />\n"); |
|---|
| | 110 | writer.append("Reason: "+e.getMessage()+"</div>\n"); |
|---|
| | 111 | writer.append("<hr style=\"height:1px; border:0px; background-color:#606060; color:#606060\" />"); |
|---|
| | 112 | StackTraceElement[] st = e.getStackTrace(); |
|---|
| | 113 | for( int i=0; i < st.length; i++ ) { |
|---|
| | 114 | writer.append(st[i].toString()+"<br />\n"); |
|---|
| | 115 | } |
|---|
| | 116 | writer.append("</td></tr></table></body></html>"); |
|---|
| 86 | 117 | } |
|---|
| 87 | | |
|---|
| 88 | | context.getResponse().send(); |
|---|
| 89 | 118 | } |
|---|
| 90 | | catch( Throwable e ) { |
|---|
| 91 | | context.rollback(); |
|---|
| 92 | | |
|---|
| 93 | | StringBuilder msg = new StringBuilder(100); |
|---|
| 94 | | msg.append("Time: "+new Date()+"\n"); |
|---|
| 95 | | msg.append("URI: "+httpRequest.getRequestURI()+"\n"); |
|---|
| 96 | | msg.append("QUERY_STRING: "+httpRequest.getQueryString()+"\n"); |
|---|
| 97 | | msg.append("Session: "+httpRequest.getParameter("sess")+"\n"); |
|---|
| 98 | | msg.append("User: "+(context != null && context.getActiveUser() != null ? context.getActiveUser().getId() : "none")+"\n"); |
|---|
| 99 | | Common.mailThrowable(e, "Framework Exception", msg.toString()); |
|---|
| 100 | | |
|---|
| 101 | | e.printStackTrace(); |
|---|
| 102 | | httpResponse.setContentType("text/html"); |
|---|
| 103 | | PrintWriter writer = httpResponse.getWriter(); |
|---|
| 104 | | writer.append("<html><head><title>Drifting Souls Server Framework</title></head>"); |
|---|
| 105 | | writer.append("<body>"); |
|---|
| 106 | | writer.append("<table border=\"0\"><tr><td>\n"); |
|---|
| 107 | | writer.append("<div align=\"center\">\n"); |
|---|
| 108 | | writer.append("<h1>Drifting Souls Server Framework</h1>"); |
|---|
| 109 | | writer.append("Unhandled Exception "+e.getClass().getName()+" during pipeline execution detected<br />\n"); |
|---|
| 110 | | writer.append("Reason: "+e.getMessage()+"</div>\n"); |
|---|
| 111 | | writer.append("<hr style=\"height:1px; border:0px; background-color:#606060; color:#606060\" />"); |
|---|
| 112 | | StackTraceElement[] st = e.getStackTrace(); |
|---|
| 113 | | for( int i=0; i < st.length; i++ ) { |
|---|
| 114 | | writer.append(st[i].toString()+"<br />\n"); |
|---|
| | 119 | finally { |
|---|
| | 120 | if( context != null ) { |
|---|
| | 121 | context.free(); |
|---|
| 115 | 122 | } |
|---|
| 116 | | writer.append("</td></tr></table></body></html>"); |
|---|
| 117 | 123 | } |
|---|
| 118 | 124 | } |
|---|
| 119 | | finally { |
|---|
| 120 | | context.free(); |
|---|
| | 125 | catch( Throwable e ) { |
|---|
| | 126 | mailThrowable(httpRequest, null, e); |
|---|
| 121 | 127 | } |
|---|
| | 128 | } |
|---|
| | 129 | |
|---|
| | 130 | private void mailThrowable(HttpServletRequest httpRequest, BasicContext context, Throwable e) { |
|---|
| | 131 | StringBuilder msg = new StringBuilder(100); |
|---|
| | 132 | msg.append("Time: "+new Date()+"\n"); |
|---|
| | 133 | msg.append("URI: "+httpRequest.getRequestURI()+"\n"); |
|---|
| | 134 | msg.append("PARAMS:\n"); |
|---|
| | 135 | for( Iterator iter=httpRequest.getParameterMap().entrySet().iterator(); iter.hasNext(); ) { |
|---|
| | 136 | Map.Entry entry = (Map.Entry)iter.next(); |
|---|
| | 137 | msg.append("\t* "+entry.getKey()+" = "+entry.getValue()+"\n"); |
|---|
| | 138 | } |
|---|
| | 139 | |
|---|
| | 140 | msg.append("QUERY_STRING: "+httpRequest.getQueryString()+"\n"); |
|---|
| | 141 | msg.append("Session: "+httpRequest.getParameter("sess")+"\n"); |
|---|
| | 142 | |
|---|
| | 143 | if( context != null ) { |
|---|
| | 144 | msg.append("User: "+(context.getActiveUser() != null ? context.getActiveUser().getId() : "none")+"\n"); |
|---|
| | 145 | } |
|---|
| | 146 | |
|---|
| | 147 | Common.mailThrowable(e, (context == null ? "Fatal " : "")+"Framework Exception", msg.toString()); |
|---|
| 122 | 148 | } |
|---|
| 123 | 149 | |
|---|