Java Doc for SimpleMappingExceptionResolver.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » handler » 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 » spring framework 2.0.6 » org.springframework.web.servlet.handler 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.web.servlet.handler.SimpleMappingExceptionResolver

SimpleMappingExceptionResolver
public class SimpleMappingExceptionResolver implements HandlerExceptionResolver,Ordered(Code)
org.springframework.web.servlet.HandlerExceptionResolver implementation that allows for mapping exception class names to view names, either for a set of given handlers or for all handlers in the DispatcherServlet.

Error views are analogous to error page JSPs, but can be used with any kind of exception including any checked one, with fine-granular mappings for specific handlers.
author:
   Juergen Hoeller
since:
   22.11.2003
See Also:   org.springframework.web.servlet.DispatcherServlet



Field Summary
final public static  StringDEFAULT_EXCEPTION_ATTRIBUTE
     The default name of the exception attribute: "exception".
final protected  Loglogger
    


Method Summary
protected  voidapplyStatusCodeIfPossible(HttpServletRequest request, HttpServletResponse response, int statusCode)
     Apply the specified HTTP status code to the given response, if possible (that is, if not executing within an include request).
protected  StringbuildLogMessage(Exception ex, HttpServletRequest request)
     Build a log message for the given exception, occured during processing the given request.
protected  IntegerdetermineStatusCode(HttpServletRequest request, String viewName)
     Determine the HTTP status code to apply for the given error view.

The default implementation always returns the specified SimpleMappingExceptionResolver.setDefaultStatusCode "defaultStatusCode" , as a common status code for all error views.

protected  StringdetermineViewName(Exception ex, HttpServletRequest request)
     Determine the view name for the given exception, searching the SimpleMappingExceptionResolver.setExceptionMappings "exceptionMappings" , using the SimpleMappingExceptionResolver.setDefaultErrorView "defaultErrorView" as fallback.
protected  ModelAndViewdoResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
     Actually resolve the given exception that got thrown during on handler execution, returning a ModelAndView that represents a specific error page if appropriate.
protected  StringfindMatchingViewName(Properties exceptionMappings, Exception ex)
     Find a matching view name in the given exception mappings.
protected  intgetDepth(String exceptionMapping, Exception ex)
     Return the depth to the superclass matching.

0 means ex matches exactly.

protected  ModelAndViewgetModelAndView(String viewName, Exception ex, HttpServletRequest request)
     Return a ModelAndView for the given request, view name and exception.
protected  ModelAndViewgetModelAndView(String viewName, Exception ex)
     Return a ModelAndView for the given view name and exception.
public  intgetOrder()
    
protected  voidlogException(Exception ex, HttpServletRequest request)
     Log the given exception at warn level, provided that warn logging has been activated through the SimpleMappingExceptionResolver.setWarnLogCategory "warnLogCategory" property.

Calls SimpleMappingExceptionResolver.buildLogMessage in order to determine the concrete message to log.

public  ModelAndViewresolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
     Checks whether this resolver is supposed to apply (i.e.
public  voidsetDefaultErrorView(String defaultErrorView)
     Set the name of the default error view.
public  voidsetDefaultStatusCode(int defaultStatusCode)
     Set the default HTTP status code that this exception resolver will apply if it resolves an error view.

Note that this error code will only get applied in case of a top-level request.

public  voidsetExceptionAttribute(String exceptionAttribute)
     Set the name of the model attribute as which the exception should be exposed.
public  voidsetExceptionMappings(Properties mappings)
     Set the mappings between exception class names and error view names. The exception class name can be a substring, with no wildcard support at present.
public  voidsetMappedHandlerClasses(Class[] mappedHandlerClasses)
     Specify the set of classes that this exception resolver should apply to. The exception mappings and the default error view will only apply to handlers of the specified type; the specified types may be interfaces and superclasses of handlers as well.

If no handlers and handler classes are set, the exception mappings and the default error view will apply to all handlers.

public  voidsetMappedHandlers(Set mappedHandlers)
     Specify the set of handlers that this exception resolver should apply to. The exception mappings and the default error view will only apply to the specified handlers.

If no handlers and handler classes are set, the exception mappings and the default error view will apply to all handlers.

public  voidsetOrder(int order)
    
public  voidsetWarnLogCategory(String loggerName)
     Set the log category for warn logging.
protected  booleanshouldApplyTo(HttpServletRequest request, Object handler)
     Check whether this resolver is supposed to apply to the given handler.

Field Detail
DEFAULT_EXCEPTION_ATTRIBUTE
final public static String DEFAULT_EXCEPTION_ATTRIBUTE(Code)
The default name of the exception attribute: "exception".



logger
final protected Log logger(Code)
Logger available to subclasses





Method Detail
applyStatusCodeIfPossible
protected void applyStatusCodeIfPossible(HttpServletRequest request, HttpServletResponse response, int statusCode)(Code)
Apply the specified HTTP status code to the given response, if possible (that is, if not executing within an include request).
Parameters:
  request - current HTTP request
Parameters:
  response - current HTTP response
Parameters:
  statusCode - the status code to apply
See Also:   SimpleMappingExceptionResolver.determineStatusCode
See Also:   SimpleMappingExceptionResolver.setDefaultStatusCode
See Also:   javax.servlet.http.HttpServletResponse.setStatus



buildLogMessage
protected String buildLogMessage(Exception ex, HttpServletRequest request)(Code)
Build a log message for the given exception, occured during processing the given request.
Parameters:
  ex - the exception that got thrown during handler execution
Parameters:
  request - current HTTP request (useful for obtaining metadata) the log message to use



determineStatusCode
protected Integer determineStatusCode(HttpServletRequest request, String viewName)(Code)
Determine the HTTP status code to apply for the given error view.

The default implementation always returns the specified SimpleMappingExceptionResolver.setDefaultStatusCode "defaultStatusCode" , as a common status code for all error views. Override this in a custom subclass to determine a specific status code for the given view.
Parameters:
  request - current HTTP request
Parameters:
  viewName - the name of the error view the HTTP status code to use, or null for theservlet container's default (200 in case of a standard error view)
See Also:   SimpleMappingExceptionResolver.setDefaultStatusCode
See Also:   SimpleMappingExceptionResolver.applyStatusCodeIfPossible




determineViewName
protected String determineViewName(Exception ex, HttpServletRequest request)(Code)
Determine the view name for the given exception, searching the SimpleMappingExceptionResolver.setExceptionMappings "exceptionMappings" , using the SimpleMappingExceptionResolver.setDefaultErrorView "defaultErrorView" as fallback.
Parameters:
  ex - the exception that got thrown during handler execution
Parameters:
  request - current HTTP request (useful for obtaining metadata) the resolved view name, or null if none found



doResolveException
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)(Code)
Actually resolve the given exception that got thrown during on handler execution, returning a ModelAndView that represents a specific error page if appropriate.

May be overridden in subclasses, in order to apply specific exception checks. Note that this template method will be invoked after checking whether this resolved applies ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling.
Parameters:
  request - current HTTP request
Parameters:
  response - current HTTP response
Parameters:
  handler - the executed handler, or null if none chosen at thetime of the exception (for example, if multipart resolution failed)
Parameters:
  ex - the exception that got thrown during handler execution a corresponding ModelAndView to forward to, or null for default processing




findMatchingViewName
protected String findMatchingViewName(Properties exceptionMappings, Exception ex)(Code)
Find a matching view name in the given exception mappings.
Parameters:
  exceptionMappings - mappings between exception class names and error view names
Parameters:
  ex - the exception that got thrown during handler execution the view name, or null if none found
See Also:   SimpleMappingExceptionResolver.setExceptionMappings



getDepth
protected int getDepth(String exceptionMapping, Exception ex)(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.

Follows the same algorithm as org.springframework.transaction.interceptor.RollbackRuleAttribute .




getModelAndView
protected ModelAndView getModelAndView(String viewName, Exception ex, HttpServletRequest request)(Code)
Return a ModelAndView for the given request, view name and exception.

The default implementation delegates to SimpleMappingExceptionResolver.getModelAndView(String,Exception) .
Parameters:
  viewName - the name of the error view
Parameters:
  ex - the exception that got thrown during handler execution
Parameters:
  request - current HTTP request (useful for obtaining metadata) the ModelAndView instance




getModelAndView
protected ModelAndView getModelAndView(String viewName, Exception ex)(Code)
Return a ModelAndView for the given view name and exception.

The default implementation adds the specified exception attribute. Can be overridden in subclasses.
Parameters:
  viewName - the name of the error view
Parameters:
  ex - the exception that got thrown during handler execution the ModelAndView instance
See Also:   SimpleMappingExceptionResolver.setExceptionAttribute




getOrder
public int getOrder()(Code)



logException
protected void logException(Exception ex, HttpServletRequest request)(Code)
Log the given exception at warn level, provided that warn logging has been activated through the SimpleMappingExceptionResolver.setWarnLogCategory "warnLogCategory" property.

Calls SimpleMappingExceptionResolver.buildLogMessage in order to determine the concrete message to log. Always passes the full exception to the logger.
Parameters:
  ex - the exception that got thrown during handler execution
Parameters:
  request - current HTTP request (useful for obtaining metadata)
See Also:   SimpleMappingExceptionResolver.setWarnLogCategory
See Also:   SimpleMappingExceptionResolver.buildLogMessage
See Also:   org.apache.commons.logging.Log.warn(ObjectThrowable)




resolveException
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)(Code)
Checks whether this resolver is supposed to apply (i.e. the handler matches in case of "mappedHandlers" having been specified), then delegates to the SimpleMappingExceptionResolver.doResolveException template method.



setDefaultErrorView
public void setDefaultErrorView(String defaultErrorView)(Code)
Set the name of the default error view. This view will be returned if no specific mapping was found.

Default is none.




setDefaultStatusCode
public void setDefaultStatusCode(int defaultStatusCode)(Code)
Set the default HTTP status code that this exception resolver will apply if it resolves an error view.

Note that this error code will only get applied in case of a top-level request. It will not be set for an include request, since the HTTP status cannot be modified from within an include.

If not specified, no status code will be applied, either leaving this to the controller or view, or keeping the servlet engine's default of 200 (OK).
Parameters:
  defaultStatusCode - HTTP status code value, for example500 (SC_INTERNAL_SERVER_ERROR) or 404 (SC_NOT_FOUND)
See Also:   javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR
See Also:   javax.servlet.http.HttpServletResponse.SC_NOT_FOUND




setExceptionAttribute
public void setExceptionAttribute(String exceptionAttribute)(Code)
Set the name of the model attribute as which the exception should be exposed. Default is "exception".

This can be either set to a different attribute name or to null for not exposing an exception attribute at all.
See Also:   SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE




setExceptionMappings
public void setExceptionMappings(Properties mappings)(Code)
Set the mappings between exception class names and error view names. The exception class name can be a substring, with no wildcard support at present. A value of "ServletException" would match javax.servlet.ServletException and subclasses, for example.

NB: Consider carefully how specific the pattern is, and whether to include package information (which isn't mandatory). For example, "Exception" will match nearly anything, and will probably hide other rules. "java.lang.Exception" would be correct if "Exception" was meant to define a rule for all checked exceptions. With more unusual exception names such as "BaseBusinessException" there's no need to use a FQN.

Follows the same matching algorithm as RuleBasedTransactionAttribute and RollbackRuleAttribute.
Parameters:
  mappings - exception patterns (can also be fully qualified class names)as keys, and error view names as values
See Also:   org.springframework.transaction.interceptor.RuleBasedTransactionAttribute
See Also:   org.springframework.transaction.interceptor.RollbackRuleAttribute




setMappedHandlerClasses
public void setMappedHandlerClasses(Class[] mappedHandlerClasses)(Code)
Specify the set of classes that this exception resolver should apply to. The exception mappings and the default error view will only apply to handlers of the specified type; the specified types may be interfaces and superclasses of handlers as well.

If no handlers and handler classes are set, the exception mappings and the default error view will apply to all handlers. This means that a specified default error view will be used as fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be ignored in this case.




setMappedHandlers
public void setMappedHandlers(Set mappedHandlers)(Code)
Specify the set of handlers that this exception resolver should apply to. The exception mappings and the default error view will only apply to the specified handlers.

If no handlers and handler classes are set, the exception mappings and the default error view will apply to all handlers. This means that a specified default error view will be used as fallback for all exceptions; any further HandlerExceptionResolvers in the chain will be ignored in this case.




setOrder
public void setOrder(int order)(Code)



setWarnLogCategory
public void setWarnLogCategory(String loggerName)(Code)
Set the log category for warn logging. The name will be passed to the underlying logger implementation through Commons Logging, getting interpreted as log category according to the logger's configuration.

Default is no warn logging. Specify this setting to activate warn logging into a specific category. Alternatively, override the SimpleMappingExceptionResolver.logException method for custom logging.
See Also:   org.apache.commons.logging.LogFactory.getLog(String)
See Also:   org.apache.log4j.Logger.getLogger(String)
See Also:   java.util.logging.Logger.getLogger(String)




shouldApplyTo
protected boolean shouldApplyTo(HttpServletRequest request, Object handler)(Code)
Check whether this resolver is supposed to apply to the given handler.

The default implementation checks against the specified mapped handlers and handler classes, if any.
Parameters:
  request - current HTTP request
Parameters:
  handler - the executed handler, or null if none chosen at thetime of the exception (for example, if multipart resolution failed) whether this resolved should proceed with resolving the exceptionfor the given request and handler
See Also:   SimpleMappingExceptionResolver.setMappedHandlers
See Also:   SimpleMappingExceptionResolver.setMappedHandlerClasses




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.