Archive for category Java

XStream – XStreamely easy way to work with XML data in Java

Tags: , , ,

From time to time there is a moment when we have to deal with XML data. And most of the time it is not the happiest day in our life. There is even a term “XML hell” describing situation when programmer has to deal with many XML configuration files that are hard to comprehend. But, like it or not, sometimes we have no choice, mostly because specification from client says something like “use configuration written in XML file” or something similar. And in such cases, XStream comes with its very cool features that make dealing with XML really less painful.

xstream

Overview

XStream is a small library to serialize data between Java objects and XML. It’s lightweight, small, has nice API and what is most important, it works with and without custom annotations that we might be not allowed to add when we are not the owner of Java classes.
Continue reading this post …


Be Sociable, Share!

Running unit tests and integration tests separately with Maven Failsafe and TestNG

Tags: , , ,

Recently for my new pet project I decided that I would like to have some tests executed during standard mvn test and some other ones only during different phase, let’s call it integration phase. I googled and googled and nothing seemed to work, so after struggling with making my setup work I’ve decided to write down my findings how I was able to configure TestNG with Maven to run integration and unit tests separately.

Basic (not working) setup

For integration testing there is a Maven Failsafe plugin that is supposed to do what we want out of the box. Unfortunately, things are not as easy and straightforward as we might expect.
Continue reading this post …


Be Sociable, Share!

Fixing bug in Hibernate Envers

Tags: ,

Recently in our project we were reported a strange bug. In a one report where we display historical data provided by Hibernate Envers, users encountered duplicated records in dropdown used for filtering. We tried to find a source of this bug, but after spending a few hours looking at the code responsible for this functionality we had to give up and ask for a dump from production database to check what actually is stored in one table. And when we got it and started investigating, it turned out that there is a bug in Hibernate Envers 3.6 that is a cause of our problems. But luckily after some investigation and invaluable help from Adam Warski (author of Envers) we were able to fix this issue.
Continue reading this post …


Be Sociable, Share!

Deploying Java Web Application on Jelastic

Tags: , , ,

Some time ago having your own full-fledged hosting with Java, Tomcat and any database wasn’t cheap, but luckily we live in a very interesting times and now there are many virtual hosting services in the Cloud providing an easy and affordable way to deploy your application and make it available to users.

And what is the best in such solutions, they grow with your application or startup. Services are free or almost free when your web application doesn’t need much memory and processors but when your web-app starts to gather more users’ attention and you have more and more concurrent sessions and visits each day, you could easily enhance your setup to match your needs. Everything is a matter of a few clicks, simple and fast.

To test how this deployment process look like, I’ve decided to put my Wicket tutorial web application online. It consist of three pages and two tables in database so I think it shouldn’t be a too complicated process to deploy it online. And as a Java hosting service I’ve chosen Jelastic, recent winner of 2012 Duke’s Choice Awards announced during JavaOne conference this year. Duke’s Choice Award is something like a Oscar in the Java world, so I thought that Jelastic might be a good choice to start with. Continue reading this post …


Be Sociable, Share!

Remember Me functionality in Apache Wicket

It is quite common in web applications to have “Remember Me” functionality that allows user to be automatically logged in each time when he visits our website.

Such feature can be implemented using Spring Security, but in my opinion using request based authentication framework with component based web framework is not the best idea. These two worlds just do not fit well together so I prefer to use my own baked solution which I will present below.

Base project

We start with a simple web application written using latest, still hot Apache Wicket 6. You can download complete sources from GitHub and start application using mvn clean compile jetty:run .

Base application consists of two pages:

  • Home Page: displays welcome message for logged and not-logged users or either logout or login link.
  • Login Page: allows user to login basing on simple in-memory collection of users. Some working login/password pairs: John/john, Lisa/lisa, Tom/tom .

Continue reading this post …


Be Sociable, Share!

Practical Unit Testing with TestNG and Mockito – review

Tags: , , ,

Book “Practical Unit Testing with TestNG and Mockito” (website) covers wide spectrum of knowledge about testing in Java environment using aforementioned libraries. But if you prefer JUnit over TestNG or PowerMock over Mockito, it is still valid and very good source of information about proper and painless testing. But of course, TestNG and Mockito users will be able to get most of this title. Below you can read some of my thoughts after reading this book.

Continue reading this post …


Be Sociable, Share!