Author: ajaquith
Date: Fri Jan 22 03:53:41 2010
New Revision: 901976
URL: http://svn.apache.org/viewvc?rev=901976&view=rev
Log:
Moved ErrorActionBean functions into MessageActionBean.
Removed:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ErrorActionBean.java
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java?rev=901976&r1=901975&r2=901976&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java
(original)
+++
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/GroupActionBean.java
Fri Jan 22 03:53:41 2010
@@ -360,7 +360,7 @@
LocalizableError error = (LocalizableError) fieldError;
if( "editgroup.illegalname".equals( error.getMessageKey()
) )
{
- return new ForwardResolution( ErrorActionBean.class );
+ return new ForwardResolution( MessageActionBean.class,
"error" );
}
}
}
@@ -380,7 +380,7 @@
}
catch( Exception e )
{
- return new RedirectResolution( ErrorActionBean.class ).flash(
this );
+ return new RedirectResolution( MessageActionBean.class,
"error" ).flash( this );
}
}
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java?rev=901976&r1=901975&r2=901976&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java
(original)
+++
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/MessageActionBean.java
Fri Jan 22 03:53:41 2010
@@ -21,36 +21,139 @@
package org.apache.wiki.action;
-import org.apache.wiki.ui.stripes.WikiRequestContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.PageContext;
import net.sourceforge.stripes.action.*;
+import net.sourceforge.stripes.validation.Validate;
+
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.log.Logger;
+import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.ui.stripes.WikiRequestContext;
+import org.apache.wiki.util.FileUtil;
@UrlBinding( "/Message.jsp" )
public class MessageActionBean extends AbstractActionBean
{
+ private static final Logger LOG = LoggerFactory.getLogger( "JSPWiki" );
+
private String m_message = null;
+ private Throwable m_realcause = null;
+
/**
- * Default event that forwards control to /Message.jsp.
+ * Event that forwards control to /Error.jsp. It also traps the cause of
the
+ * exception and logs the details.
*
* @return the forward resolution
*/
- @DefaultHandler
- @HandlesEvent( "message" )
- @WikiRequestContext( "message" )
- public Resolution view()
+ @HandlesEvent( "error" )
+ @WikiRequestContext( "error" )
+ public Resolution error()
{
- return new ForwardResolution( "/Message.jsp" );
+ WikiContext wikiContext = getContext();
+ HttpServletRequest request = wikiContext.getHttpRequest();
+ String msg = "An unknown error was caught by Error.jsp";
+ Exception exception = (Exception) request.getAttribute(
PageContext.EXCEPTION );
+
+ if( exception != null )
+ {
+ msg = exception.getMessage();
+ if( msg == null || msg.length() == 0 )
+ {
+ msg = "An unknown exception " + exception.getClass().getName()
+ " was caught.";
+ }
+ setMessage( msg );
+
+ // Get the actual cause of the exception.
+ // Note the cast; at least Tomcat has two classes called
+ // "JspException"
+ // imported in JSP pages.
+
+ if( exception instanceof javax.servlet.jsp.JspException )
+ {
+ LOG.debug( "IS JSPEXCEPTION" );
+ m_realcause = ((javax.servlet.jsp.JspException)
exception).getRootCause();
+ LOG.debug( "REALCAUSE=" + m_realcause );
+ }
+
+ if( m_realcause == null )
+ m_realcause = exception;
+ }
+ else
+ {
+ m_realcause = new Exception( "Unknown general exception" );
+ }
+
+ LOG.debug( "Error.jsp exception is: ", exception );
+ return new ForwardResolution( "/Error.jsp" );
}
+ /**
+ * Returns the message string for this MessageActionBean. When the
{...@code
+ * message} event executes, the message will be the value of request
+ * parameter {...@code message}. When the {...@code error} event method
executes,
+ * this method returns the appropriate Exception message.
+ *
+ * @return the message
+ */
public String getMessage()
{
return m_message;
}
+ /**
+ * If the {...@code error} event method is executed, returns the Exception
that
+ * caused the error.
+ *
+ * @return the Exception, or {...@code null}
+ */
+ public Throwable getRealCause()
+ {
+ return m_realcause;
+ }
+
+ /**
+ * If the {...@code error} event method is executed, returns the Class,
Method
+ * and line number that caused the error.
+ *
+ * @return the Exception, or {...@code null}
+ */
+ public String getThrowingMethod()
+ {
+ return m_realcause == null ? null : FileUtil.getThrowingMethod(
m_realcause );
+ }
+
+ /**
+ * Default event that forwards control to /Message.jsp.
+ *
+ * @return the forward resolution
+ */
+ @DefaultHandler
+ @HandlesEvent( "message" )
+ @WikiRequestContext( "message" )
+ public Resolution message()
+ {
+ return new ForwardResolution( "/Message.jsp" );
+ }
+
+ /**
+ * Sets the message for this MessageActionBean. If {...@code message} is
not
+ * {...@code null}, this method also puts the value into request scope
under
+ * the attribute name {...@code message}.
+ *
+ * @param message
+ */
+ @Validate( required = false )
public void setMessage( String message )
{
m_message = message;
+ if( m_message != null )
+ {
+ HttpServletRequest request = getContext().getRequest();
+ request.setAttribute( "message", m_message );
+ }
}
}