Calendar
QuicksearchBookmarksMy del.icio.us
ArchivesCategoriesSyndicate This BlogBlog Administration |
Sunday, September 18. 2005Creating an rss feed with spring and Rome
Today I wanted to have a different way of using my application besides the plain jsp pages. Suddenly it struck me, i wanted an rss feed. I fired up my friend google and found the project Rome. It did not look that hard by browsing the sample applications. I also found a sample how you could use a servlet. Oke, the step to a spring implementation was not that hard. This blog item will talk you through the creation of a new view in Spring mvc, an RSS feed.
First you need to download Rome and ,a href="http://www.jdom.org">jdom. After downloading them, add the jars to the lib folder of your web project. (I am not going to discuss in detail how to setup your spring web mvc project, I have used the equinox project as a startup) Before we can create a class that generates an rss feed, we need to configure spring. We must be able to find the view class.
<prop key="/rss.html">rssController</prop>
Creating a feed with Rome is as simple as instantiating a new Feed object, setting the rss type and the content type, creating a feed output, and outputting the output. See the next code for the steps.
A feed consists of a few properties like: author, title, description, etc. It also contains a List with items. These items are called entries. For my sample I created the entries based on a list of orders I obtained through the OrderController by taking the list from the request. Each order becomes an entry. Some important parts are below.
And finally the method to create an entry based on an order:
I hope this will help some of you to create a spring view object and start your own rss feed. You can download the complete class here An improved base class for this class is now included in the Springmodules project. You can find it here Tuesday, June 21. 2005Code coverage with cobertura and luntbuild
Yesterday I was reading other blogs and I came across a code coverage product. About 2 years ago I also was looking for a free opensource code coverage tool. It was GroboCodeCoverage that I found. This tool just did not cut it for me. To much effort to get it to work for my kind of architecture, which consits of multiple projects. Each layer has it's own project (web,business,domain,data access). And I ran into performance problems very often. So when I heard about another framework I wanted to give it a try. Since I am using luntbuild as a build manager, I also want to integrate the results into luntbuild. The integration must be simular to the junit integration.
Now what is that tool I am talking about? I am talking about cobertura. Via the faq of cobertura I also found emma. I choose Cobertura for the easy installation and use, but most of all for the way the reports are created. I like them much more than the reports of emma. I the future I do want to have a look at emma to see if performance is different for the tools. Sorry for the long introduction, now we are going to install and use cobertura. First I installed version 1.4, but I ran into problems while using it with multiple components into one project. You have to merge the result files of the coverage measurements. This only worked correct in the latest greatest cvs version. Have a look at another blog item of mine that gives you a better option of presenting the link to the reports : extending luntbuild with cobertura reports cvs -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/cobertura login (Just hit enter for the password) cvs -z3 -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/cobertura checkout -P cobertura cd into the cobertura directory and run ant with the coverage jar options ant coverage jar This creates a cobertura.jar file. Before we can use ant we need to add some jars to the ant lib folder. These jars come with the cobertura sources. jakarta-oro-2.0.8.jar asm-2.0.jar log4j-1.2.9.jar java-getopt-1.0.9.jar ccl.jar javancss.jar Now we need to configure our ant build scripts so that the instrumentation (changing the byte code of the classes) takes place. After that we need to run the unit test with the correct classpath and finally run the reports task of cobertura. How does this look in our build script: <taskdef classpath="cobertura.jar" resource="tasks.properties" /> <target name="compiletest" description="Compile all test code, and instrument classes for coverage"> ... omitted code to compile test cases for clarity ... <cobertura-instrument todir="${dir.component.coverage.instrument}"> <ignore regex="util.*" /> <fileset dir="${dir.component.build}"> <exclude name="**/Test*"/> <include name="**/*.class"/> </fileset> </cobertura-instrument> <copy todir="${dir.component.coverage.src}"> <fileset dir="${dir.component.src.java}" includes="**/*.java" /> </copy> </target> This block of code instruments all classes in the build folder except for the test cases, in the end the sources are copied to a central directory. The sources are used to show you the lines that have test coverage. This is a work around, a next release will enable you to have multiple source directories in the report task. The classes are instrumented, now we must put them on the unit test classpath, we also need the cobertura.jar file at runtime on the classpath. <junit printsummary="on" fork="true" forkmode="once" haltonfailure="false" failureproperty="test.failed" showoutput="true"> <sysproperty key="net.sourceforge.cobertura.datafile" file="${basedir}/cobertura.ser" /> <classpath> <pathelement path="${dir.component.coverage.instrument}"/> <path refid="project.classpath"/> <pathelement path="${compiler.classpath}"/> <pathelement path="${dir.component.build}"/> <fileset dir="${dir.component.lib}"> <include name="*.jar"/> </fileset> </classpath> <formatter type="xml" usefile="true"/> <batchtest todir="${dir.project.junit.report}"> <fileset dir="${dir.component.src.test}"> <include name="**/Test*.java"/> </fileset> </batchtest> </junit> Important in this code are the sysproperty tag, this helps the unit test to find the just data file. Another important thing is to put the instrumented classes on the classpath before the normal classes. The directory for instrumented classes is obtained via the property ${dir.component.coverage.instrument}. The cobertura.jar file is in the lib folder ${dir.project.lib} that is added to the classpath via the project.classpath. After all unit tests have been executed we have cobertura.ser files for all components. We first need to make one data file and then run reports on this merged datafile. This is done by the following piece of script. <target name="test" depends="distribution,runtests" description="Runs the junit report"> ... omitted code to execute junitreport for clarity ... <cobertura-merge> <fileset dir="${basedir}/"> <include name="*/cobertura.ser"/> </fileset> </cobertura-merge> <cobertura-report srcdir="${dir.project.coverage.src}" destdir="${coverageHtmlReportDir}"/> </target> Important in this code is the merge tag, this looks at all subfolders for cobertura.ser files and merges these into a new cobertura.ser file. Another important part for luntbuild integration is the parameter ${coverageHtmlReportDir}. The value for this parameter is provided by luntbuild and gives the location for storing the report files. The next image gives an example of the report that is created for my sample application: [img]/images/ScreenshotCoverageReport.png[/img] Now we want those coverage reports in luntbuild. For starter, this can propobly be done different in the meaning of correct. What I have done is a hack, but for me it works. Have a look at another blogitem of mine for a better way of integrating the cobertura reports and luntbuild. Actually there is two things we should do: 1. Place the report files in the correct directory, this is done by ant but we need to pass the right parameter plus value. 2. Show a link on the website that directs to the coverage report. Lets start with the first item, this can be done by configuring the builder. Open your luntbuild project configuration. Go to the builder tab and put an extra variable in the Build properties box: coverageHtmlReportDir="${build.publishDir}/coverage_html_report" This parameter is used by ant to find the luntbuil publish directory. Now we want to add a link to the luntbuild Build view page. This done by adding some lines to the file LUNTBUILD_HOME/WEB-INF/BuildViewer.html ... more here ... <td width="10%" align="center" class="buildTitleRight"> <span jwcid="@Conditional" condition="ognl:junitHtmlReport!=null"> <span jwcid="@GenericLink" href="ognl:'statefulPublish/coverage_html_report/index.html'" title="coverage report"> coverage report </span> </span> </td> <td width="10%" align="center" class="buildTitleRight"> <span jwcid="@Conditional" condition="ognl:junitHtmlReport!=null"> <span jwcid="@GenericLink" href="ognl:'statefulPublish/'+ junitHtmlReport" title="junit report">junit report</span> </span> </td> ... more here ... I copied the td for junit, what I wanted was an extra parameter coverageHtmlReport. I did not figure out how to do just that. The following image shows what it is looking like. ![]() In reply to a question in the comments I have added the complete build.xml files as well. The project I am using cobertura for has modular design. Therefore there is one main build.xml file that is the starting point. There is another build.xml file that contains the generic targets used by the modules. Finally every module has it's own build.xml file. build-main.xml build-targets.xml build.xml Wednesday, June 15. 2005Installing linux fedora 4 on IBM laptop (T41p) (part 2)
I did have a blog entry about installing linux ob my laptop. Now fedora core 4 is released and there were some issues with my last installation. Therefore I had to do it again. After reading my own post i did not find it very intuitive. Therefore I make another post with only the commands that I used to get wireless to work.
Create the following file: /etc/sysconfig/network-scripts/ifcfg-ath0
Then add the following line to /etc/modprobe.conf:
Now open the network settings: Desktop > System settings > Network Edit the wireless device and connect to your network
Activate the wireless network card and save the configuration. That did the trick for me. If you have improvements or just comments, please feel free to add a comment to this blog item. Monday, June 13. 2005Installing linux fedora 4 on IBM laptop (T41p)
Today I have installed fedora core 4 on my ibm laptop. Most was working fine out of the box. I am having some problems finding utlities, but the command line works fine.
I was having some issues with my wireless network, but these are resolved now. Since this can be an issue for others as well I do want to share my experience with you. The first thing you need to do is find a good website, oke try this one for instance: http://www.niemueller.de/wiki/?ThinkpadT41pWithFC3 When following this guideline there was an issue with uudecode. This is not installed per default in fedora. Therefore you need to install these libraries. I found the right command on another website:
the website is: (beware, tough to read for some of us) http://wiki.nothing.sh/page/ThinkPad/Fedora%20Core%204 Then you probably know that your laptop has a small light for wireless activity. This can be turned on by issuing the following command before you run make:
Found that on the website: http://vsharma.net/thinkpad-t41p-fedora-core1/ Thats all, run make and make install and connect to your network. Thursday, June 2. 2005Continuous Integration and Luntbuild
Yesterday was a Continuous Integration day. I am pretty familiar with tools like apache ant and Cruisecontrol. But these tools just don't cut it. I don't like the website that you use with cruisecontrol and Maven is becoming more popular every day. Then I read that Luntbuild had a new release. I have been experimenting with Luntbuild in the past and thought about giving it another go.
First I needed to install luntbuild. There is an install guideline for dummies on the wiki. According to the guideline I installed tomcat (version 4.1.31), that is really not to hard. Then you should use the installer for luntbuild (version 1.2), this isn't working on my windows Xp. There is an issue with the script, uses a jar command that is not working out of the box, probably a hole in my knowledge. Then I downloaded the zipped version, altered the web.xml and applicationContext.xml files. I replaced some placeholders with real values web.xml - installDir, added the real path to the installation directory of luntbuild applicationContext.xml - inMemoryAuthenticationDAO, changed the placeholder of the password for luntbuild user For simplicity I used winzip to create the war file from the luntbuild/web directory. Then go to the tomcat manager website and upload the warfile. Then everything should be working and you should be able to logon to the luntbuild website. Now what? I have a website then can manage builds. I think I need a build first and to create a build you first need a project. The last few days I have been experimenting with springframework. In order to store the results I created a project at tigris.org, drop me an email if you want to have access to the website. This website uses Subversion as a Repository. Oke, now I have a project and I need a build that luntbuild can execute. I did have a look at maven, but I feel more confortable with ant. I created the following build.xml file.
I am not going to explain it here, there are good resources to find on the web about ant. The hardest part for me to find (oke, it was time to go to bed) was the integration with junit and luntbuild. Things that are hard to find are often easy to do. Luntbuild can provide parameter values to the ant script. One of these parameters defined in the project is : junitHtmlReportDir. This parameter is used in the report tag to copy the results to. <report format="frames" todir="${junitHtmlReportDir}"/> Luntbuild can be used to send emails with information about the build. Another fine option is to send messages to a jabber account or an msn messenger. To bad I can not get the messenger part to work. Maybe this will go as is should in the next few days. There is a good manual for luntbuild on theire website. I like luntbuild, it is fairly easy to use, I do need to do some work on reports like cruisecontrol has though. The user interface is very nice and does what it should. Friday, May 20. 2005Pragmatic project automation
This is a book by Mike Clark. It deals with automatically building, deploying and monitoring Java applications. The book first discusses what to automate and why. Within the wiki I discuss Continuous Integration (http://www.gridshore.nl/pmwiki/pmwiki.php?n=Main.ContinuousIntegration). This book discusses all parts of continous integration:
- One step builds (using a standard directory structure, building with ant, automatic unit tests with junit and ant) - Schedules builds (using cruisecontrol builds are created on time with reporting as well) - Push button releases (version control systems are important, a release contains executable code as well as documentation) - Installation and deployment - Monitoring Every part is discussed while using a tool. A few important remarks from the book: CRISP builds : Complete - No manual actions necessary to create a build and run tests Repeatable - You should be able to recreate previous builds Informative - If a build fails comments should be as obvious to find the problem Schedulable - It must be possible to schedule a build on a certain interval or at a certain time Portable - It should be to difficult to port the build to another machine A remark that is made about releases, is: Release early and often. It is very important to test your release procedure as well as the releases as early as possible. It is good to have a daily release. (Nightly build) There is also some help on installation, a good advice is to provide customers with some kind of test application that reads the configurations, and checks if the application is installed correct. This can provide you with just the right amount of information to get to the problem quickly. It was a very fun book to read and good to complete or start your 'Project Automation'
« previous page
(Page 2 of 2, totaling 16 entries)
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||

