Java Doc for ExceptionMappingInterceptor.java in  » J2EE » webwork-2.2.6 » com » opensymphony » xwork » interceptor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » webwork 2.2.6 » com.opensymphony.xwork.interceptor 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor

ExceptionMappingInterceptor
public class ExceptionMappingInterceptor implements Interceptor(Code)
This interceptor forms the core functionality of the exception handling feature. Exception handling allows you to map an exception to a result code, just as if the action returned a result code instead of throwing an unexpected exception. When an exception is encountered, it is wrapped with an ExceptionHolder and pushed on the stack, providing easy access to the exception from within your result. Note: While you can configure exception mapping in your configuration file at any point, the configuration will not have any effect if this interceptor is not in the interceptor stack for your actions. It is recommended that you make this interceptor the first interceptor on the stack, ensuring that it has full access to catch any exception, even those caused by other interceptors.

Interceptor parameters:

  • logEnabled (optional) - Should exceptions also be logged? (boolean true|false)
  • logLevel (optional) - what log level should we use (trace, debug, info, warn, error, fatal)? - defaut is debug
  • logCategory (optional) - If provided we would use this category (eg. com.mycompany.app). Default is to use com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor.
The parameters above enables us to log all thrown exceptions with stacktace in our own logfile, and present a friendly webpage (with no stacktrace) to the end user.

Extending the interceptor:

If you want to add custom handling for publishing the Exception, you may override ExceptionMappingInterceptor.publishException(com.opensymphony.xwork.ActionInvocation,ExceptionHolder) . The default implementation pushes the given ExceptionHolder on value stack. A custom implementation could add additional logging etc.

Example code:

 
 <xwork>
 <include file="webwork-default.xml"/>
 <package name="default" extends="webwork-default">
 <global-results>
 <result name="error" type="freemarker">error.ftl</result>
 </global-results>
 <global-exception-mappings>
 <exception-mapping exception="java.lang.Exception" result="error"/>
 </global-exception-mappings>
 <action name="test">
 <interceptor-ref name="exception"/>
 <interceptor-ref name="basicStack"/>
 <exception-mapping exception="com.acme.CustomException" result="custom_error"/>
 <result name="custom_error">custom_error.ftl</result>
 <result name="success" type="freemarker">test.ftl</result>
 </action>
 </package>
 </xwork>
 
 

This second example will also log the exceptions using our own category com.mycompany.app.unhandled at WARN level.

 
 <xwork>
 <include file="webwork-default.xml"/>
 <package name="something" extends="webwork-default">
 <interceptors>
 <interceptor-stack name="exceptionmapping-stack">
 <interceptor-ref name="exception">
 <param name="logEnabled">true</param>
 <param name="logCategory">com.mycompany.app.unhandled</param>
 <param name="logLevel">WARN</param>	        		
 </interceptor-ref>	
 <interceptor-ref name="i18n"/>
 <interceptor-ref name="static-params"/>
 <interceptor-ref name="params"/>
 <interceptor-ref name="validation">
 <param name="excludeMethods">input,back,cancel,browse</param>
 </interceptor-ref>
 </interceptor-stack>
 </interceptors>
 <default-interceptor-ref name="exceptionmapping-stack"/>
 <global-results>
 <result name="unhandledException">/unhandled-exception.jsp</result>
 </global-results>
 <global-exception-mappings>
 <exception-mapping exception="java.lang.Exception" result="unhandledException"/>
 </global-exception-mappings>
 <action name="exceptionDemo" class="com.opensymphony.webwork.showcase.exceptionmapping.ExceptionMappingAction">
 <exception-mapping exception="com.opensymphony.webwork.showcase.exceptionmapping.ExceptionMappingException"
 result="damm"/>
 <result name="input">index.jsp</result>
 <result name="success">success.jsp</result>            
 <result name="damm">damm.jsp</result>
 </action>
 </package>
 </xwork>
 
 

author:
   Matthew E. Porter (matthew dot porter at metissian dot com)
author:
   Claus Ibsen


Field Summary
protected  LogcategoryLogger
    
final protected static  Loglog
    
protected  StringlogCategory
    
protected  booleanlogEnabled
    
protected  StringlogLevel
    


Method Summary
public  voiddestroy()
    
protected  voiddoLog(Log logger, Exception e)
     Performs the actual logging.
public  intgetDepth(String exceptionMapping, Throwable t)
     Return the depth to the superclass matching.
public  StringgetLogCategory()
    
public  StringgetLogLevel()
    
protected  voidhandleLogging(Exception e)
     Handles the logging of the exception.
public  voidinit()
    
public  Stringintercept(ActionInvocation invocation)
    
public  booleanisLogEnabled()
    
protected  voidpublishException(ActionInvocation invocation, ExceptionHolder exceptionHolder)
     Default implementation to handle ExceptionHolder publishing.
public  voidsetLogCategory(String logCatgory)
    
public  voidsetLogEnabled(boolean logEnabled)
    
public  voidsetLogLevel(String logLevel)
    

Field Detail
categoryLogger
protected Log categoryLogger(Code)



log
final protected static Log log(Code)



logCategory
protected String logCategory(Code)



logEnabled
protected boolean logEnabled(Code)



logLevel
protected String logLevel(Code)





Method Detail
destroy
public void destroy()(Code)



doLog
protected void doLog(Log logger, Exception e)(Code)
Performs the actual logging.
Parameters:
  logger - the provided logger to use.
Parameters:
  e - the exception to log.



getDepth
public int getDepth(String exceptionMapping, Throwable t)(Code)
Return the depth to the superclass matching. 0 means ex matches exactly. Returns -1 if there's no match. Otherwise, returns depth. Lowest depth wins.
Parameters:
  exceptionMapping - the mapping classname
Parameters:
  t - the cause the depth, if not found -1 is returned.



getLogCategory
public String getLogCategory()(Code)



getLogLevel
public String getLogLevel()(Code)



handleLogging
protected void handleLogging(Exception e)(Code)
Handles the logging of the exception.
Parameters:
  e - the exception to log.



init
public void init()(Code)



intercept
public String intercept(ActionInvocation invocation) throws Exception(Code)



isLogEnabled
public boolean isLogEnabled()(Code)



publishException
protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder)(Code)
Default implementation to handle ExceptionHolder publishing. Pushes given ExceptionHolder on the stack. Subclasses may override this to customize publishing.
Parameters:
  invocation - The invocation to publish Exception for.
Parameters:
  exceptionHolder - The exceptionHolder wrapping the Exception to publish.



setLogCategory
public void setLogCategory(String logCatgory)(Code)



setLogEnabled
public void setLogEnabled(boolean logEnabled)(Code)



setLogLevel
public void setLogLevel(String logLevel)(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.