Friday, 25 February 2011

Integrating Grails and Hudson

The best way to ensure consistent code quality and system stability is to integrate your application with a Continuous Integration system. Hudson is one such CI system.

In this tutorial, i will give a small demo on how to integrate Grails with Hudson. I will assume you are familiar with the grails technology and have some basic idea of what continuous integration systems are.
Note: This is not a tutorial on Hudson!

Thursday, 24 February 2011

Exploring BootStrap.groovy

You may come across a scenario where you want to carry out a task every time your application starts or stops.

You just need to peep inside your grails-app/conf folder to find a groovy file called BootStrap.groovy.
BootStrap.groovy is a simple plain groovy script with two important closures : 'init' and 'destroy'. These closures are called upon when the application starts up and shuts down respectively.

Monday, 21 February 2011

Problem setting the grails proxy ?


If you are using grails on a windows box, you may face an issue while setting the grails proxy using the 'grails add-proxy' command. This is because of the way windows treats any paramters that you pass using the -- option and sets the host name and the port to boolean values.

Thursday, 10 February 2011

JDBCException due to stale connections in Grails

If your grails application remains idle for too long or the database connections remain idle for too long or the database is restarted you may see the following exceptions:

ERROR org.hibernate.util.JDBCExceptionReporter - No more data to read from socket
ERROR org.hibernate.util.JDBCExceptionReporter - OALL8 is in an inconsistent state
ERROR org.hibernate.util.JDBCExceptionReporter - Io exception: Broken pipe
ERROR org.hibernate.util.JDBCExceptionReporter - Already closed.
These issues are intermittent, that is, they may disappear when you try hitting again.
This issue occurs because the application tries to use a database connection that has become stale and should have been evicted.

java.lang.NoClassDefFoundError when sending async emails in Grails

Exception while sending emails in production environment.

If you are trying to send emails from your application asynchronously, using the Mail plugin, in the production environment you may see an exception like:
java.lang.NoClassDefFoundError: org/springframework/mock/web/MockHttpServletRequest 
This is because of a bug in the Mail plugin. This plugin uses the MockHttpServletRequest class from the spring framework test jar which is not bundled when you run the 'grails prod war' command.

Wednesday, 9 February 2011

RESTful webservices with Spring

REST (Representational State Transfer) is a stateless architectural style wherein resources are identified and manipulated. by their URIs and transferred over HTTP. A REST web service sends any parameters, data needed by the server within the HTTP headers and body.
In this article, we will build REST webservices with Spring and a client using the Spring RestTemplate to consume the webservice. I will not be going into the details of these technologies, the aim is to rapidly come up with a basic CRUD web-service.

I will be assuming, that you are familiar with the basics of Spring, DI and IoC, REST, and the basic web-application structure in java.

Without much ado, let's begin!

Monday, 7 February 2011

Read from a database and write into an xml using Groovy

You may come across a use-case where you need to read some data from a database and generate an xml report or file that needs to be sent across to be processed by some other system.

Doing this using a java program could be relatively overwhelming; with Groovy you can do this in a matter of minutes!

Let's take a look at how you can convert data returned from a sql query into an xml file.

Add search to your grails application using the searchable plugin

If you're building a web application, you're most certainly going to need some 'search' capabilities in your application. The searchable plugin is an amazing plugin that is built using Compass search engine and lucene. This plugin enables you to make your domain classes without writing almost any code. In this article we will be discussing how you can install and use this plugin, and also discuss some issues around it.

We will be creating a simple grails application, a couple of domain classes, and then we will explore the 'searchable' plugin. (find the source code of the sample application at the end of the article)

Let's get started!

Tuesday, 1 February 2011

Spring Hibernate Integration

In this article, I will be demonstrating how you can integrate hibernate with your Spring application. We will not be discussing hibernate and Spring in any detail. The focus is to get you started with an Spring application that persists data into a database using the hibernate ORM layer.

I will safely assume that you are familiar with Spring, hibernate, SQL, maven. For the purpose of this demo, i will be using the MySQL database, STS (SpringSource Tool Suite) or Eclipse with Spring support plugins installed. If you are not using any IDE, you just need to create some folders and config files yourself. But i see no reason why you shouldn't since it will really speed your development process.
(find the source code of the sample application at the end of the page)

So Let's get started!

Get started with Spring MVC

Spring MVC, one of the modules of the core Spring framework,  is a web-application development framework. As the name suggests, Spring MVC is an implementation of the Model(M), View(V), Controller(C) design pattern, which is based on request delegation and separation-of-concerns.
I am assuming, that if you have reached this article and are about to use it, you would be familiar with the basics of web-application development and the Spring framework in general. And Java of course ;)

I will briefly introduce you to the basics of how Spring MVC works and then will build a simple web-application (find the sample application source code for download at the end of the page).