Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java Open Source > BOOK: Professional Java Development with the Spring Framework
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Java Development with the Spring Framework
This is the forum to discuss the Wrox book Professional Java Development with the Spring Framework by Rod Johnson, Juergen Hoeller, Alef Arendsen, Thomas Risberg, Colin Sampaleanu; ISBN: 9780764574832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Java Development with the Spring Framework section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 10th, 2005, 05:13 PM
Registered User
 
Join Date: Oct 2005
Location: Madrid, M, Spain.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to dleal Send a message via MSN to dleal Send a message via Yahoo to dleal
Default Exception design on Boxoffice Sample Application?

Dear Members,

Looking in to the BoxOffice sample Aplication the exception messages are written in "hard code", they don't use any ResourceBundle for that.

For example (From NotEnoughSeatsException):

Code:
public NotEnoughSeatsException(long classId, int available, int requested) {
        super(ERROR_CODE, "Requested " + requested + " seats in class " + classId + "; only " + available + " are free");
        this.classId = classId;
        this.requested = requested;
        this.available = available;
    }


Every exception is designed on a similar way. There is no constructor with message as input argument.

How to implement a language independent way for defining the message exceptions?

In think in two possibilities:

1. Add a ResourceBundle attribute on the ApplicationException (base exception for all possible application exceptions)

2. Defining the exception constructors with a message attribute in order to be filled on places the exceptions will be thrown. With this solutions we need only a few exceptions, because ApplicationException with different message could apply for most cases (Probably a poor design strategy)

I am assuming the Application Exception police should consider that the exceptions are not only caught by the web side client, that is why each tier should be independ, so if I want also to run my application on console mode I would like that my exception will be treated property on language independ way (at least user exceptions)

So what is the purpose of the bean:

Code:
 
    <bean id="messageSource"        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename">
            <value>error-messages</value>
        </property>
    </bean>


Is is correct to desing an Exception policy creating dependence with such bean, how can we do that?, or it is better the solution I have propoused (1).

How can I unify this exception police using error-messages.properties from my web client side and also for throwing the exception could be caught on non web application.

If you take a look on BookSeatsController class from BoxOffice application, the exception are catch, in the form:

Code:
try {
            reservation = boxOffice.allocateSeats(request);
        } catch (RequestedSeatNotAvailableException e) {
            errors.reject(e.getErrorCode(), "Requested seats are not available");
        } catch (NotEnoughSeatsException e) {
            errors.reject(e.getErrorCode(), "Could not allocate the number of seats requested");
        }


So were goes this message in english????, should it be language independent? For example the error code: "seatNotAvailable" is not used at other places on the source code and there is no information on the error-message.properties of such error code, so it is not used as resource key for getting the translatated message.

As far as I remember on the Expert one-on-one J2EE book there is comment about the user error message and detailed error message (goes for log files) the first one should be language independent and the second one (log file) could be in english for example. I don't see very clear how to implement that on language indepent way and also independently of tier.

Thanks in advance,

David

Reply With Quote
  #2 (permalink)  
Old November 11th, 2005, 06:31 AM
Registered User
 
Join Date: Oct 2005
Location: Madrid, M, Spain.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to dleal Send a message via MSN to dleal Send a message via Yahoo to dleal
Default

(I respond in part to my self)

Following the comment from the Expert One-on-One J2EE Design and Development (R. Johnson et al.):

"Unless we are able to use a common base class for all exceptions in an application – something that isn't possible if we mix checked and unchecked exceptions – we will need to make our exceptions implement an ErrorCoded or similarly named interface that defines a method such as this: String getErrorCode();"

..."we are able to distinguish between error messages intended for end users and those intended for developers. Messages inside exceptions (returned by the getMessage() method) should be used for logging, and targeted to developers."

So, the getMessage() is intended for "advanced users/loging" and the getErrorCode() is intended for getting the corresponding real message (language independent) from the properties files defined on the

 <bean id="messageSource"
        class="org.springframework.context.support.Resourc eBundleMessageSource">
        <property name="basename">
            <value>error-messages</value>
        </property>
    </bean>

so it is more clear for the web tier (on *Controller classes), but how to do with a different tier, lets say in a dos command application that simply invokes the Service Classes (Business Classes) and the errors are catch, how to we get for example access to a simple Junit Test (dos command application) to such error code values.

I gues for testing we should use the method: AbstractDependencyInjectionSpringContextTests.cont extKey() , but I am not sure about that.

Thanks in advance,

David

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Design Time Exception in WinForm doctorwcc VB.NET 0 March 2nd, 2007 04:00 AM
Where is the code of sample application? rogerthis BOOK: Professional Java Development with the Spring Framework 1 November 27th, 2006 01:26 AM
Problems with Sample Application too_many_details BOOK: Professional Java Development with the Spring Framework 6 November 14th, 2006 01:24 PM
BoxOffice example Application stavares BOOK: Professional Java Development with the Spring Framework 1 March 7th, 2006 12:32 AM
Can't start the Phile sample web application kuotaiyi BOOK: ASP.NET Website Programming Problem-Design-Solution 1 June 12th, 2003 10:29 PM



All times are GMT -4. The time now is 07:50 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.