Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Re: Struts 2: Unable to catch exceptions via global-exception-mappings

Ian Roughley

2007-10-01

Replies:

The result is executed after the interceptors and after the action has
executed. Look at the invoke() method on the DefaultActionInvocation
class. Therefore, because your exception is in rendering the result,
the exception is not managed by the interceptor. If you threw the same
exception from within the execute() method of an action, it would be
handled as you are expecting.

I think this comes down to the reasoning behind the interceptor. I see
it as a means to manage the run-time business logic, and not
developer-based configuration which will usually be managed during the
construction phase.

/Ian

mikeh96 wrote:
> thanks for looking. I pasted the full stack trace below.  I am not using
> any home grown action code (yet). This is coming from the
> DefaultActionSupport during the rendering stage.
>
> com.opensymphony.xwork2.DefaultActionInvocation.executeResult (DefaultActionInvocation.java:348)
>
> Do I need to subclass and do something in the action.execute() code ?
>
>
> here's the full trace
>
> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource (ResourceManagerImpl.java:458)
> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource (ResourceManagerImpl.java:341)
>  at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate (RuntimeInstance.java:831)
>  at
> org.apache.velocity.app.VelocityEngine.getTemplate (VelocityEngine.java:491)
>  at
> org.apache.struts2.dispatcher.VelocityResult.getTemplate (VelocityResult.java:221)
>  at
> org.apache.struts2.dispatcher.VelocityResult.doExecute (VelocityResult.java:150)
>  at
> org.apache.struts2.dispatcher.StrutsResultSupport.execute (StrutsResultSupport.java:178)
>  at
> com.opensymphony.xwork2.DefaultActionInvocation.executeResult (DefaultActionInvocation.java:348)
>  at
> com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:253)
>  at
> org.apache.struts2.impl.StrutsActionProxy.execute (StrutsActionProxy.java:50)
>  at
> org.apache.struts2.dispatcher.Dispatcher.serviceAction (Dispatcher.java:504)
>  at
> org.apache.struts2.dispatcher.FilterDispatcher.doFilter (FilterDispatcher.java:419)
>  at
> com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:73)
>  at
> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage (PageFilter.java:118)
>  at
> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter (PageFilter.java:52)
>  at
> com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:73)
>  at
> org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter (ActionContextCleanUp.java:99)
>  at
> com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:73)
>  at
> com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:175)
>  at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:240)
>  at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
>  at com.caucho.server.port.TcpConnection.run(TcpConnection.java:481)
>  at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:685)
>  at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:607)
>  at java.lang.Thread.run (Thread.java:613)
>
>
>
> Ian Roughley wrote:
>  
>> Is the exception occurring during the call to execute() (or equivalent)
>> business logic method? This is where the exception handler interceptor
>> is applied. It seems like the exception you are receiving is from a
>> rendering phase outside the execution of the actions logic.
>>
>> /Ian
>>
>>
>>
>> mikeh96 wrote:
>>  
>>> Thanks for taking the time.. unfortunately, the exceptions are still
>>> percolating up.
>>> Do you have it working?
>>>
>>>
>>>
>>>
>>> Brian Trzupek wrote:
>>>  
>>>    
>>>> I am not 100% sure on this, but I think you need to have
>>>> struts.devMode = false in struts.properties.
>>>>
>>>> Give that a whirl.
>>>>
>>>> Brian-
>>>>
>>>> On Sep 30, 2007, at 9:43 PM, mikeh96 wrote:
>>>>
>>>>  
>>>>      
>>>>> I am unable to trap an exception and it's being pushed up until it
>>>>> becomes a
>>>>> 500 Servlet Exception.
>>>>>
>>>>> Basically, I want to catch the exception if a user mistypes an
>>>>> action name
>>>>>
>>>>> I am using struts2 (2.0.9).
>>>>>
>>>>> Here's the top of the trace:
>>>>> org.apache.velocity.exception.ResourceNotFoundException:
>>>>> Unable to find resource '/templates/screens/inddd2ex.vm'
>>>>> at
>>>>> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(
>>>>> ResourceManagerImpl.java:458)
>>>>>
>>>>> Here's my struts.xml file
>>>>>
>>>>> (thanks for helping)
>>>>> ----------------------------------------------------------------
>>>>> <package name="default" extends="struts-default">
>>>>>
>>>>> <interceptors>
>>>>> <interceptor-stack name="simpleStack">
>>>>> <interceptor-ref name="defaultStack" />
>>>>> </interceptor-stack>
>>>>> </interceptors>
>>>>>
>>>>>
>>>>> <global-results>
>>>>> <result name="Exception" type="velocity"
>>>>>    
>>>>>      
>>>>>> /templates/screens/exception.vm</result>
>>>>>>      
>>>>>>        
>>>>> </global-results>
>>>>>
>>>>> <global-exception-mappings>
>>>>> <exception-mapping
>>>>>   exception="java.lang.Exception"
>>>>>   result="Exception"/>
>>>>> <exception-mapping
>>>>>   exception="org.apache.velocity.exception.ResourceNotFoundException"
>>>>>   result="Exception"/>
>>>>> <exception-mapping
>>>>>   exception="java.lang.Runtime"
>>>>>   result="Exception"/>
>>>>> </global-exception-mappings>
>>>>>
>>>>>
>>>>> <action name="*" class="com.opensymphony.xwork2.ActionSupport">
>>>>> <interceptor-ref name="exception" />
>>>>> <interceptor-ref name="defaultStack" />
>>>>> <result type="velocity">/templates/screens/{1}.vm</result>
>>>>> </action>
>>>>>
>>>>> </package>
>>>>> ----------------------------------------------------------------------
>>>>> ------
>>>>> --
>>>>> View this message in context: http://www.nabble.com/Struts-2%3A--
>>>>> Unable-to-catch-exceptions-via-global-exception-mappings-
>>>>> tf4545971.html#a12972599
>>>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>>>> For additional commands, e-mail: user-help@(protected)
>>>>>
>>>>>    
>>>>>      
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>>> For additional commands, e-mail: user-help@(protected)
>>>>
>>>>
>>>>
>>>>  
>>>>      
>>>  
>>>    
>>  
>
>  
©2008 junlu.com - Jax Systems, LLC, U.S.A.