After the five years course at the University of A Coru–a (Spain), I’ve just finished my end of course project, ONess, and got the Computer Engineer degree. I’m so happy ðŸ˜€
When an error happens in a web application a stack trace is shown to the user. How to avoid this and show a beautiful error page while logging internally the error that happened? Use the Struts exception handler.
Add the following code to your struts-config.xml. If you don’t want to show different error messages you only need that exception with type=”java.lang.Exception”. The other ones are to show different error messages using Spring exception hierarchy.
<global-exceptions> <exception key="errors.optimistic.locking.failure" path=".error" type="org.springframework.dao.OptimisticLockingFailureException"/> <exception key="errors.data.access.resource.failure" path=".error" type="org.springframework.dao.DataAccessResourceFailureException"/> <exception key="errors.data.retrieval.failure" path=".error" type="org.springframework.dao.DataRetrievalFailureException"/> <exception key="errors.data.access" path=".error" type="org.springframework.dao.DataAccessException"/> <exception key="errors.transaction" path=".error" type="org.springframework.transaction.TransactionException"/> <exception key="errors.unknown" path=".error" type="java.lang.Exception"/> </global-exceptions>
- errors.optimistic.locking.failure=The object was already modified
- errors.data.access.resource.failure=Can’t connect to the database
- errors.data.retrieval.failure=The object you try to access doesn’t exist
- errors.data.access=Data access error
- errors.transaction=Transaction error
- errors.unknown=Unknown error
If you’re using log4j for logging add to your log4j.properties
log4j.rootLogger=ERROR, stdout log4j.logger.org.apache.struts.action.ExceptionHandler=DEBUG, stdout # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
This way the stack traces are logged to standard output (in Tomcat this is logged to logs/stdout.txt)
I am presenting ONess the 14th october at 9:00 in the University of A Coru–a, Spain, so if you’re near ðŸ˜‰ and want to see it, you can contact with me.
Planet Apache is a sindication of blogs from Apache Software Foundation committers (as me). Great people with interesting things to say.
Software patents are causing a crazy situation where big companies patent the most stupid things.
Sun is seeking a patent on the company’s per-employee software pricing plan. It’d be interesting knowing who owns the per-company or per-computer princing patents.
Amazon.com has filed suit against Barnesandnoble.com, alleging that the rival book and music e-tailer illegally copied Amazon’s patented 1-Click technology. Has Microsoft patented the double click? Is that the reason why Bill Gates is the richest man all over the world?
The worst thing is that open source can have serious problems with patents.
I’ve find a good example about using multiple message resources in Struts as if they were only one, this means that you don’t need to specify the bundle in each tag.
For those people out there that use JSTL+Struts, as I do, you know that message resources must be configurated in Struts config file besides JSTL config because Struts Validator needs it.
I’ve tidied up the code for using it in ONess, you can get it in the oness-common-webapp-controller (check ActionServlet and CustomMessageResources in the sources) and the configuration in oness-common-webapp-view, you need to change the action servlet in
web.xml to use the customized one and in
struts-config.xml specify the message resources separated by commas.
Now I need something similar to be used in JSTL, I think that Spring has some support for that.
A real extreme tool is Guantanamo by Aslak Hellesoy, it makes me understand the true meaning of “extreme” ðŸ˜‰
Do you have problems maintaining high test coverage? Send the untested code to Guantanamo!
Guantanamo is a tool that deletes all code lines that are not covered by tests. Guantanamo is part of the Extreme XP Tools family. Some thoughts about why it was created are written down here.