• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring & Struts - loading spring exception class from struts-config.xml

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi gang,

I have a web app using Spring's IoC, and Struts (for presentation layer). The issue is that I define an exception handler in the struts global-exceptions tag in the struts-config.
What I'd like to be able to do is to use Spring's IoC to inject some parameters into the exception handler class being used (I'm injecting string parameters that will change based on which environment the application is in).

All well and good, except that while I can see spring injecting the values into the exception handler class, when struts comes to get this class it makes it's own one up (and hence all the variables are null, and the app gets an error message on the error message page - classy).

Here's an exerpt from the struts-config file:

<exception handler="com.mbl.insurance.web.exception.SystemExceptionHandler" key="global.error.message" path="/error.do" scope="request"
type="java.lang.Exception" />

Now, the chap who wrote up the spring framework implemented it so that all the struts action classes inherit from an abstract action class, and in this class there are a bunch of getter methods, that pretty much pull the necessary spring-instantiated class from the bean factory.
However, how do I work this so that my SystemExceptionHandler class loaded by struts is the one that spring has instantiated!

Any ideas?
Andrew
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just thinking out loud. What am saying here could be outright wrong
I'm assuming that you w'd have configured struts to use Spring's request processor instead-

org.springframework.web.struts.DelegatingRequestProcessor

I see from the DelegatingRequestProcessor javadocs that they have not overriden the method 'processException' behaviour of the base class. I'm sure struts (by default) must be instanting the Exception handler in that method depending upon the exception that is getting thrown from your action and ofcourse struts-config.xml configuration. Now if I understand your requirement correctly, you dont want Struts to be doing that. So I guess you can override processException and get Spring to return the instance of the configured Exception handler instead. Do you mind taking a look at the source of both Struts RequestProcessor (processException) and Spring DelegatingRequestProcessor?
You might have to subclass DelegatingRequestProcessor , override processException and configure the new subclass as struts request processor though.
[ December 01, 2005: Message edited by: Karthik Guru ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic