Techspace

IT happens only in IT

Creating Acegi Users in a script

We are using Acegi plugin for Authentication and Authorization in Grails. We had to create users in bulk using MySql script. We have to know the encrypted password for each user, corresponding to the clear text password to insert in the database. (Acegi encrypts the password before storing it in the database).

I came across this nice post http://stackoverflow.com/questions/1472431/acegi-password-encryption.

I was also thinking that Acegi must be using MD5, but after reading this post realized that it is SHA1 encryption.

You can get the sha1 encrypted password by issuing this command

echo -n password | openssl sha1

For eg. if your password is admin you can find encrypted password by issuing this command

echo -n admin | openssl sha1

October 6, 2009 Posted by Paras | Acegi, Grails | , , | No Comments Yet

Mule IDE for Galileo

I was stuck this week while trying to install Mule IDE plugin for Eclipse Galileo. Then I came across this. Basically, you have to uncheck “Group items by category” before installing the plugin

October 2, 2009 Posted by Paras | Mule | , , | 2 Comments

Grails – Plugin file not found for plugin project

If you have just renamed your Grails plugin project and getting this error “Plugin file not found for plugin project” and wondering – “What’s going on?”

Consider this. Grails is based on DRY principle. Convention over configuration. By convention, the plugin descripor file should end in the word “GrailsPlugin”

Most likely it would have happened that you wanted to rename AbcDef grails plugin to say Abc plugin

In the process, instead of renaming AbcDefGrailsPlugin.groovy file in your plugin root directoy to AbcGrailsPlugin.grooy, you might have mistakenly renamed it to just AbcPlugin.groovy. Since the word GrailsPlugin was not in the name, it was considered as the normal project instead of Plugin project.

If you look inside $GRAILS_HOME/scripts/_GrailsPluginDev.groovy file, you can see the following code snippet


metadataFile.name,
 "*GrailsPlugin.groovy",

In short, the solution is to rename the file and the class defined inside it to AbcGrailsPlugin.groovy

September 10, 2009 Posted by Paras | Grails, Grails Plugin | | No Comments Yet

Grails Maven Integration

Note: Information provided in this post may get outdated soon, because Grails, it’s plugin and dependencies gets updated very frequently.

Today I was trying to integrate my existing grails application with Maven. I had hard time with it. I referred to the following information

  • http://grails.org/Maven+Integration
  • http://forge.octo.com/maven/sites/mtg/grails-maven-plugin/examples/mavenize-a-grails-app.html

The pom generated by the plugin was of Grails 1.1 and I was using grails 1.1.1 therefore I had to make the following changes in my pom.xml


<dependency>
 <groupId>org.grails</groupId>
 <artifactId>grails-crud</artifactId>
 <version>1.1.1</version>
 </dependency>
 <dependency>
 <groupId>org.grails</groupId>
 <artifactId>grails-gorm</artifactId>
 <version>1.1.1</version>
 </dependency>

Since I was using MySql I had to add this too


<dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>3.1.14</version>
 </dependency>

Also you need to add this


<dependency>
 <groupId>org.tmatesoft.svnkit</groupId>
 <artifactId>svnkit</artifactId>
 <version>1.2.3.5521</version>
 <scope>runtime</scope>
 </dependency>

If you are not using Acegi then this is all you need to do for Maven integration. If you are using Acegi then you might have to make some more changes. In my case, I was getting ClassNotFoundException  for net.sf.ehcache.CacheException. I had to manually copy ehcache-1.3.0.jar from $MAVEN_REPOSITORY_HOME/repository/net/sf/ehcache/1.3.0 to $GRAILS_PROJECT_HOME/plugins/acegi/lib. It solved my issue and I was successfully able to run my grails app using mvn grails:run-app

As I said before, information in this post may get outdated very soon. But it solved my problem and it might solve your too.

September 10, 2009 Posted by Paras | Grails, Maven | , , , | No Comments Yet

Grails – No such property: save for class

I suddenly started getting this message in my grails app. I don’t know the root cause of the problem. But for me the cause of the problem was removal of some fields and renaming of certain fields in domain class. If you have rename and/or removed some fields then make sure you follow these steps

  1. Stopped the running grails application. Changes made in the domains, controllers and other grails-app artifacts sometimes doesn’t get updated while application is running
  2. Remove and update the reference of the removed or renamed fields from the gsp, constraints block of domain, any other static blocks in referenced domains, messages.properties and other property files.
  3. If you are not using in-memory db(HSQL) and using mysql or any other persistent database, then corresponding columns of the renamed/removed old fields are not deleted from database. If it does not affect the already existing data in DB then drop the corresponding table. When you restart application, grails will create the table for you again. If your table has foreign key reference, then drop the database altogether and create new DB and grant all privileges to the user used by Grails.

This solved my No such property: save for class issue. YMMV. In your case, the cause may be different.

September 8, 2009 Posted by Paras | Grails | | 1 Comment

Hyphen in MySQL database

If you have hyphen(-) in your mySQL database you can use back-ticks to escape while issuing commands

like
drop database `alfresco-dev`;

August 26, 2009 Posted by Paras | MySQL | | No Comments Yet

Null message in Grails

I had a domain object

class Project{
    String projectTitle
    Rso rso
}

Where Rso itself is another domain object.

Both projectTitle and rso could not be blank or null.
when I tried
project.projectTitle.blank message in messages.properties, it worked

but
project.rso.null was not working.
I was trying project.rso.null because the default message was mapped as default.null.message.

Then someone suggested me to use
project.rso.nullable and it worked.

August 18, 2009 Posted by Paras | Grails, Groovy | , | No Comments Yet

Running grails at some specific port

By default, jetty will run the application at port 8080, but if you want to run the application at some specific port, for example 8085 you should use

grails -Dserver.port=8085 run-app

July 7, 2009 Posted by Paras | Grails | | No Comments Yet

Grails : No domain class found for name domain-class-name . Please try again and enter a valid domain class name

Sometimes, even if you create domain objects in grails you get the error that No domain class found.
I am not sure why this happens because I am new to Grails and still learning. But the following steps work for me

i) Stop all the running grails app ctrl+C
ii) grails clean
iii) Now try grails generate-all domain-class-name

This generally works for me. I will update this post if I find the root cause of the problemSom

June 23, 2009 Posted by Paras | Grails, Groovy | , | 2 Comments

Building Web Apps with Spring 3.0 – Meeting notes

This presentation and notes are from the May 2009 Java User group meeting in Twin Cities. You can view the details and download the code from http://www.intertech.com/UserGroups/JUGPresentation.aspx?TopicID=135 It was an excellent presentation. Bob has discussed about new cool features in Spring 3 and how it simplifies the Spring MVC development. These presentation slides are created by him and all rights lies with him.

  • DispatcherServlet is the central servlet handling requests
  • See slide 7. The request handling takes place in the following order
    1. HTTP Request is first handled by Dispatcher Servlet
    2. DispatcherServlet refers HandlerMapping find the controller which will handle the request
    3. DispatcherServlet sends the request to the Controller. Controller returns view and/or model.
    4. DispatcherServlet refers to ViewResolver to determine the view page based on logical view name
    5. View is rendered
  • Controller hierarchy is deprecated in Spring 3.Just annotation is enough. No need to implement life-cycle methods
  • Flexible method arguments. Flexible return types.
  • Annotations like
    @RequestParam
    @ModelAttribute
    @RequestMapping
    @SessionAttribute
    @InitBinder
    and WebBindingInitializer
  • Convention verses configuration
  • ControllerClassNameHandlerMapping
  • Model and ModelMap
  • Rest Support

    Stateless, cacheable, scalable, communication protocol
    HTTP Methods – GET, POST, PUT(Idempotent), DELETE(Idempotent), HEAD, OPTIONS

  • Spring 3.0 has REST support

June 3, 2009 Posted by Paras | Spring, Uncategorized | , | No Comments Yet