You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by JOSE L MARTINEZ-AVIAL <jl...@gmail.com> on 2012/10/20 22:35:01 UTC

Custom error result for ExceptionMappingInterceptor

Hi,
  I want to use ExceptionMappingInterceptor to manage any exception thrown
while processing a request. The issue I have is that I want to map the
action to diferent results depending on some parameters of the request.
More specifically, the browser's client can send three diferent types of
request to my app:

    FullScreen -> It's a full navigation, i.e., the browser goes to a
diferent URL. In this case all the screen is reloaded, obviously.
    PaneScreen -> Part of the screen is updated using HTML code ( the
result of a JSP). The request is done using AJAX, so there is no navigation
in the formal sense.
    AJAX/JSON -> The page retrieves some information from the server in
JSON format using AJAX. There is also no navigation.

  The problem I have is that depending on the type of navigation (And I can
know that looking at the headers and the namespace of the action request) I
need to send diferent error results to the client. If it's a FullScreen
request I need to send a full error page. If it's a PaneScreen request,
then only a handful of HTML needs to be sent, since it only affects the
pane that send the request. Last, but not least, if it is a AJAX/JSON
screen I want to send a 500 error code with specific information in JSON
format so a meaningful message can be shown to the user.

  After researching a bit, it seems my only options are to chain an
HandleExceptionAction to the ExceptionMappingInterceptor result, so the
action can send the correct  result to the user (
http://stackoverflow.com/questions/5746941/mapping-struts-2-exception-handler-to-an-action),
or implement my own version of ExceptionMappingInterceptor. Is there any
other option I am missing?

thanks

K:

Re: Custom error result for ExceptionMappingInterceptor

Posted by Antonios Gkogkakis <gk...@tcd.ie>.
Another option would be to extend the ExceptionMappingInterceptor and
override the  findResultFromExceptions method.
In the overriden method you can do your checks and return a global result
accordingly

Antonios

On 20 October 2012 21:35, JOSE L MARTINEZ-AVIAL <jl...@gmail.com> wrote:

> Hi,
>   I want to use ExceptionMappingInterceptor to manage any exception thrown
> while processing a request. The issue I have is that I want to map the
> action to diferent results depending on some parameters of the request.
> More specifically, the browser's client can send three diferent types of
> request to my app:
>
>     FullScreen -> It's a full navigation, i.e., the browser goes to a
> diferent URL. In this case all the screen is reloaded, obviously.
>     PaneScreen -> Part of the screen is updated using HTML code ( the
> result of a JSP). The request is done using AJAX, so there is no navigation
> in the formal sense.
>     AJAX/JSON -> The page retrieves some information from the server in
> JSON format using AJAX. There is also no navigation.
>
>   The problem I have is that depending on the type of navigation (And I can
> know that looking at the headers and the namespace of the action request) I
> need to send diferent error results to the client. If it's a FullScreen
> request I need to send a full error page. If it's a PaneScreen request,
> then only a handful of HTML needs to be sent, since it only affects the
> pane that send the request. Last, but not least, if it is a AJAX/JSON
> screen I want to send a 500 error code with specific information in JSON
> format so a meaningful message can be shown to the user.
>
>   After researching a bit, it seems my only options are to chain an
> HandleExceptionAction to the ExceptionMappingInterceptor result, so the
> action can send the correct  result to the user (
>
> http://stackoverflow.com/questions/5746941/mapping-struts-2-exception-handler-to-an-action
> ),
> or implement my own version of ExceptionMappingInterceptor. Is there any
> other option I am missing?
>
> thanks
>
> K:
>