Author: mrdon
Date: Tue Apr 11 19:11:40 2006
New Revision: 393367

URL: http://svn.apache.org/viewcvs?rev=393367&view=rev
Log:
Adding an error page that will show a "problem report" whenever a configuration 
error has
occurred.  This implementation needs to be refactored so other areas, like 
validation configuration 
can take advantage of this feature.  Also fixing QuickStart for new Maven 2 
layout.

PR: WW-1282

Added:
    
incubator/webwork2/action/src/main/resources/org/apache/struts/action2/dispatcher/
    
incubator/webwork2/action/src/main/resources/org/apache/struts/action2/dispatcher/error.ftl
Modified:
    incubator/webwork2/action/src/main/java/org/apache/struts/action2/Main.java
    
incubator/webwork2/action/src/main/java/org/apache/struts/action2/dispatcher/DispatcherUtils.java
    
incubator/webwork2/action/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java

Modified: 
incubator/webwork2/action/src/main/java/org/apache/struts/action2/Main.java
URL: 
http://svn.apache.org/viewcvs/incubator/webwork2/action/src/main/java/org/apache/struts/action2/Main.java?rev=393367&r1=393366&r2=393367&view=diff
==============================================================================
--- incubator/webwork2/action/src/main/java/org/apache/struts/action2/Main.java 
(original)
+++ incubator/webwork2/action/src/main/java/org/apache/struts/action2/Main.java 
Tue Apr 11 19:11:40 2006
@@ -131,8 +131,8 @@
             command = "quickstart";
             String name = checkWebAppArgs(args);
             programArgs = new String[]{"/" + name,
-                    "webapps/" + name + "/src/webapp",
-                    "webapps/" + name + "/src/java"};
+                    "webapps/" + name + "/src/main/webapp",
+                    "webapps/" + name + "/src/main/java"};
         }
 
         if ("quickstart".equals(command)) {

Modified: 
incubator/webwork2/action/src/main/java/org/apache/struts/action2/dispatcher/DispatcherUtils.java
URL: 
http://svn.apache.org/viewcvs/incubator/webwork2/action/src/main/java/org/apache/struts/action2/dispatcher/DispatcherUtils.java?rev=393367&r1=393366&r2=393367&view=diff
==============================================================================
--- 
incubator/webwork2/action/src/main/java/org/apache/struts/action2/dispatcher/DispatcherUtils.java
 (original)
+++ 
incubator/webwork2/action/src/main/java/org/apache/struts/action2/dispatcher/DispatcherUtils.java
 Tue Apr 11 19:11:40 2006
@@ -37,13 +37,19 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import freemarker.template.Template;
+import org.apache.struts.action2.views.freemarker.FreemarkerManager;
+
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
@@ -252,7 +258,7 @@
             }
         } catch (ConfigurationException e) {
             LOG.error("Could not find action", e);
-            sendError(request, response, HttpServletResponse.SC_NOT_FOUND, e);
+            sendError(request, response, context, 
HttpServletResponse.SC_NOT_FOUND, e);
         } catch (Exception e) {
             String msg = "Could not execute action";
             LOG.error(msg, e);
@@ -458,19 +464,44 @@
      * @param code     the HttpServletResponse error code (see [EMAIL 
PROTECTED] javax.servlet.http.HttpServletResponse} for possible error codes).
      * @param e        the Exception that is reported.
      */
-    public void sendError(HttpServletRequest request, HttpServletResponse 
response, int code, Exception e) {
-        try {
-            // send a http error response to use the servlet defined error 
handler
-            // make the exception availible to the web.xml defined error page
-            request.setAttribute("javax.servlet.error.exception", e);
-
-            // for compatibility
-            request.setAttribute("javax.servlet.jsp.jspException", e);
-
-            // send the error response
-            response.sendError(code, e.getMessage());
-        } catch (IOException e1) {
-            // we're already sending an error, not much else we can do if more 
stuff breaks
+    public void sendError(HttpServletRequest request, HttpServletResponse 
response, 
+            ServletContext ctx, int code, Exception e) {
+        if (devMode) {
+            response.setContentType("text/html");
+            
+            try {
+                freemarker.template.Configuration config = 
FreemarkerManager.getInstance().getConfiguration(ctx);
+                Template template = 
config.getTemplate("/org/apache/struts/action2/dispatcher/error.ftl");
+                
+                List chain = new ArrayList();
+                Throwable cur = e;
+                chain.add(cur);
+                while ((cur = cur.getCause()) != null) {
+                    chain.add(cur);
+                }
+                
+                HashMap data = new HashMap();
+                data.put("exception", e);
+                data.put("chain", chain);
+                template.process(data, response.getWriter());
+                response.getWriter().close();
+            } catch (Exception exp) {
+                exp.printStackTrace();
+            }
+        } else {
+            try {
+                // send a http error response to use the servlet defined error 
handler
+                // make the exception availible to the web.xml defined error 
page
+                request.setAttribute("javax.servlet.error.exception", e);
+    
+                // for compatibility
+                request.setAttribute("javax.servlet.jsp.jspException", e);
+    
+                // send the error response
+                response.sendError(code, e.getMessage());
+            } catch (IOException e1) {
+                // we're already sending an error, not much else we can do if 
more stuff breaks
+            }
         }
     }
 

Modified: 
incubator/webwork2/action/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java
URL: 
http://svn.apache.org/viewcvs/incubator/webwork2/action/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java?rev=393367&r1=393366&r2=393367&view=diff
==============================================================================
--- 
incubator/webwork2/action/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java
 (original)
+++ 
incubator/webwork2/action/src/main/java/org/apache/struts/action2/interceptor/debugging/DebuggingInterceptor.java
 Tue Apr 11 19:11:40 2006
@@ -164,7 +164,7 @@
         }
         if (cont) {
             return inv.invoke();
-        } else {
+       } else {
             return null;
         }
     }

Added: 
incubator/webwork2/action/src/main/resources/org/apache/struts/action2/dispatcher/error.ftl
URL: 
http://svn.apache.org/viewcvs/incubator/webwork2/action/src/main/resources/org/apache/struts/action2/dispatcher/error.ftl?rev=393367&view=auto
==============================================================================
--- 
incubator/webwork2/action/src/main/resources/org/apache/struts/action2/dispatcher/error.ftl
 (added)
+++ 
incubator/webwork2/action/src/main/resources/org/apache/struts/action2/dispatcher/error.ftl
 Tue Apr 11 19:11:40 2006
@@ -0,0 +1,97 @@
+<html>
+<head>
+    <title>Struts Action Framework Problem Report</title>
+</head>
+<body>
+    <h2>Struts Action Framework Problem Report</h2>
+    <p>
+    The Struts Action Framework has detected a problem in your configuration:
+    </p>
+
+<#assign msgs = [] />
+<#list chain as ex>
+    <#if ex.message?exists>
+        <#assign msgs = [ex.message] + msgs/>
+    </#if>    
+</#list>
+<div id="exception-info">
+<table>
+    <tr>
+        <td><strong>Messages</strong>:</td>
+        <td>
+            <#if (msgs?size > 1)>
+            <ol>
+                <#list msgs as mgs>
+                    <li>${msg}</li>
+                </#list>
+            </ol>
+            <#else>
+            ${msgs[0]}
+            </#if>
+        </td>
+    </tr>
+    <#if exception.location?exists>
+    <tr>
+        <td><strong>File</strong>:</td>
+        <td>${exception.location.URI}</td>
+    </tr>
+    <tr>
+        <td><strong>Line number</strong>:</td>
+        <td>${exception.location.lineNumber}</td>
+    </tr>
+    <tr>
+        <td><strong>Column number</strong>:</td>
+        <td>${exception.location.columnNumber}</td>
+    </tr>
+    </#if>
+    
+</table>
+</div>
+
+<#if exception.snippet?exists>
+    <#assign snippet = exception.getSnippet(2) />
+    <#if (snippet?size > 0)>
+        <div id="snippet">
+        <hr />
+            
+            <#list snippet as line>
+                <#if (line_index == 2)>
+                    <pre 
style="background:yellow">${(line[0..(exception.location.columnNumber-2)]?html)}<span
 
style="background:red">${(line[(exception.location.columnNumber-1)]?html)}</span>${(line[exception.location.columnNumber..]?html)}</pre>
+                <#else>
+                    <pre>${line?html}</pre>
+                </#if>    
+            </#list>
+        </div>
+    </#if>    
+</#if>
+
+<div id="stacktraces">
+<hr />
+<h3>Stacktraces</h3>
+<#list chain as ex>
+<div class="stacktrace" style="padding-left: ${ex_index * 2}em">
+    <strong>${ex}</strong>
+    <div>
+    <pre>
+    <#list ex.stackTrace as frame>
+    ${frame}
+    </#list>
+    </pre>
+    </div>
+</div>
+</#list>
+</div>
+
+<div class="footer">
+<hr />
+<p>
+You are seeing this page because development mode is enabled.  Development 
mode, or devMode, enables extra
+debugging behaviors and reports to assist developers.  To disable this mode, 
set:
+<pre>
+  struts.devMode=false
+</pre>
+in your <code>WEB-INF/classes/struts.properties</code> file.
+</p>
+</div>
+</body>
+</html>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to