Announcement Announcement Module
No announcement yet.
SI exception handling: http inbound-gateway + view-name Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SI exception handling: http inbound-gateway + view-name

    I have a very simple SI configuration:

    http inbound-gateway-> channel -> service activator.

    What I want to achieve is to:
    (a) get a jsp page when everything OK; now it's achieved by setting view-name property on the gateway and using an internal view resolver. Simple.
    (b) get *another* jsp page (or even pages - e.g. depending on the error type) when an error occurs.

    By default, every error generated in the Service Activator seems to be just added to the (internal) model but the view configured by name is still used - in this case, the caller (e.g. a browser) would not know about the error.

    This question extends to more general error handling recommendations for SI on system boundaries (not too much info on that in SI Reference).


  • #2

    Thanks for your question. Depending on your specific use-case, there are a few options available that may work as an immediate solution. The first option is not ideal, but you could implement your own custom view and render a different response depending on the success/error state from within that single view. For example you could do something like this:

        <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
        <bean name="myView"  class="org.springframework.integration.samples.http.MyCustomView"/>
    Then, you can use "myView" as your view name in the HTTP Inbound Gateway and within the view implementation itself you have access to the message payload (as part of the model) as well as any exceptions.

    Another option would be to use Spring MVC directly as your entry point and then interact with Spring Integration from within your Spring MVC Controller using e.g. a Gateway Proxy.

    Likewise, it's possible to just let an Exception propagate and then have the Spring MVC exception-mappings resolve the respective error view (without any MVC controllers involved, and no view-name attribute specified on your Spring Integration HTTP Inbound Gateway). For example:

    	<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    		<property name="exceptionMappings">
    		       <entry key="org.springframework.integration.samples.http.FooException" value="errorView"/>
    Lastly, I concede there might be the need improve the HTTP Inbound Gateway itself and provide support for an attribute "view-name-expression" that would allow you to retrieve the view name dynamically using SpEL Expressions.

    Another option would be to add support for an "error view". If this might be useful to you, please feel free to open a Jira ticket.

    I hope this gives you some options. Also, please let us know if you have other ideas, as depending on your use-case you may have specific requirements.





    • #3

      Thanks a lot for the response - it clarifies available options.

      I like the idea of making view name settable dynamically by SpEL - I hope the expression evaluation could be done as the final step - i.e. with full access to the *output* message? This will add missing flexibility to view part - see the extended scenario below:
      Say you want to expose the same data model for different consumers (json, html, feed) based on Accept request header. The simplest implementation is to use one HTTP Inbound Gateway (so the same URL structure can handle different data representations) and set up content negotiation view resolver. Having flexibility on redirecting to an appropriate view seems reasonable - nothing new, this is what Spring MVC gives us out of the box ;-)