|
From: Roberto C. <rob...@in...> - 2006-07-12 12:42:53
|
Any thought about including this resolver in any spring versions?
Tx
/roberto
>>> Hi.
>>> I wrote a slightly different version of SimpleMappingExceptionResolver
>>> which puts the exception in the http session instead of in the model. In
>>> this way it is possible to use a redirect instead of a view and still be
>>> able to access the exception to be shown to the user.
>>> Using a redirect is usually better than a view since the flow of the
>>> application after a redirect follows the normal execution of the program.
>>> What do you think?
>>> /Roberto
>>>
>>
>> --------------------------------------------------------------------------------
>>
>>
>>> package org.springframework.web.servlet.handler;
>>>
>>> import javax.servlet.http.HttpServletRequest;
>>> import javax.servlet.http.HttpSession;
>>>
>>> import org.springframework.web.servlet.ModelAndView;
>>>
>>> /**
>>> * Exception resolver that allows for mapping exception class names to view
>>> * names as the SimpleMappingExceptionResolver. This resolver puts the
>>> thrown
>>> * exception in the HTTP session so that it can be retrieve later by a
>>> * controller. Using this approach permits to use a redirect view when
>>> handling
>>> * the exception while stil having access to the originating exception.
>>> *
>>> * @author Roberto Cosenza
>>> */
>>>
>>> public class SessionExceptionResolver extends
>>> SimpleMappingExceptionResolver {
>>>
>>> public final static String DEFAULT_LATEST_EXCEPTION_KEY =
>>> "SimpleMappingExceptionResolver.LATEST_EXCEPTION_KEY";
>>> private boolean forceSession = false;
>>> private String exceptionSessionKey = DEFAULT_LATEST_EXCEPTION_KEY;
>>>
>>> protected ModelAndView getModelAndView(String viewName, Exception ex,
>>> HttpServletRequest request) {
>>> logger.trace("getModelAndView");
>>> HttpSession session = request.getSession(forceSession);
>>> if (session != null) {
>>> session.setAttribute(getExceptionSessionKey(), ex);
>>> }
>>> return new ModelAndView(viewName);
>>> }
>>>
>>> /**
>>> * Tells if the session must be created if not already existing
>>> *
>>> * @return default is false
>>> */
>>> public boolean isForceSession() {
>>> return forceSession;
>>> }
>>>
>>> public void setForceSession(boolean forceSession) {
>>> this.forceSession = forceSession;
>>> }
>>>
>>> public String getExceptionSessionKey() {
>>> return exceptionSessionKey;
>>> }
>>>
>>> public void setExceptionSessionKey(String excepionSessionKey) {
>>> this.exceptionSessionKey = excepionSessionKey;
>>> }
>>> }
>>>
>>
>> --------------------------------------------------------------------------------
>>
>>
>>> Using Tomcat but need to do more? Need to support web services, security?
>>> Get stuff done quickly with pre-integrated technology to make your job
>>> easier
>>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>>>
>>
>> --------------------------------------------------------------------------------
>>
>>
>>> _______________________________________________
>>> Springframework-developer mailing list
>>> Spr...@li...
>>> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>>>
>>
>> Using Tomcat but need to do more? Need to support web services, security?
>> Get stuff done quickly with pre-integrated technology to make your job easier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>> _______________________________________________
>> Springframework-developer mailing list
>> Spr...@li...
>> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
> Roberto Cosenza
> Infoflex Connect AB, Sweden
> Tel: +46-(0)8-55576867, Fax: +46-(0)8-55576861
Roberto Cosenza
Infoflex Connect AB, Sweden
Tel: +46-(0)8-55576867, Fax: +46-(0)8-55576861
--
Nordic Messaging Technologies is a trademark of Infoflex Connect.
Please visit www.nordicmessaging.se for more information about our
carrier-grade messaging products.
|