Archive for March, 2013

This Week in Grails (2013-12)

Saturday, March 30th, 2013

The Groovy team released version 2.1.2 this week.

Check out Graeme’s blog post on the new async features in Grails 2.3.


If you want to keep up with these “This Week in Grails” posts you can access them directly via their category link or in an RSS reader with the feed for just these posts.


Translations of this post:



Plugins

There were 7 new plugins released:

  • google-analytics-tracker version 0.1. Provides a simple way to embed your web application with page view tracking and event tracking of Google Analytics
  • gorm-interceptors version 0.1. Interceptors for GORM methods (excluding find, countBy, addTo, removeFrom methods)
  • mixpanel version 1.0. Integration with www.mixpanel.com analytics
  • sanchez version 1.0. Integration for sanchez.js javascript/html/GSP templates on client and server-side
  • segmentio version 0.1.7. Use Segment.io to send your analytics data to any service you want, without you having to integrate with each one individually
  • tika-parser version 1.3.0. Bundles the Apache Tika toolkit along with a parser service
  • validate-config version 0.4. Adds methods to ConfigObject for validating expected and required properties

and 13 updated plugins:

  • aws-sdk version 1.4.1. Use the Amazon Web Services infrastructure services
  • clover version 3.1.11. Integrates the Clover code coverage tool
  • code-coverage version 1.2.6. Generates code coverage reports using Cobertura
  • facebook-sdk version 0.4.9. Allows your application to use the Facebook Platform and develop Facebook apps on Facebook.com or on web sites (with Facebook Connect)
  • geasyui version 0.7. Supplies jQuery EasyUI resources and taglibs
  • gson version 1.1.2. Provides alternate JSON (de)serialization using Google’s Gson library
  • jaxrs version 0.7. Supports the development of RESTful web services based on the Java API for RESTful Web Services (JSR 311: JAX-RS)
  • jdbc-pool version 7.0.37. Replaces default Grails Commons DBCP Pool with Tomcat JDBC Pool” target=’_blank’>http://people.apache.org/~fhanik/jdbc-pool/)
  • jesque version 0.6.1. Groovier approach to using jesque
  • jquery-validation-ui version 1.4.4. Client Side Validation without writing JavaScript
  • recaptcha version 0.6.3. Integrates ReCaptcha and Mailhide services
  • spring-security-facebook version 0.13.2. Plugin for Facebook Authentication, as extension to Grails Spring Security Core plugin
  • uploadr version 0.7.1. HTML5 Drag and Drop file uploader

Interesting Tweets

Jobs



User groups and Conferences


This Week in Grails (2013-11)

Monday, March 18th, 2013

Graeme has been working on adding more asynchronous support for Grails 2.3, with additional controller features and new support for async GORM. Check out the initial documentation.

You can now register for GR8Conf EU at the “early bird” rates – be sure to get your tickets before the prices go up. They have announced the speaker lineup, and they are looking for sponsors. You can also check out their Laynrd page.

Registration for GR8Conf US is also open, and you have until the end of the week to get your ticket at the “Door Buster” rate.

The SpringOne 2GX call for papers call for papers is open, so submit a talk if you’re interested in speaking there in September. If you want to attend, register here before their prices go up.


If you want to keep up with these “This Week in Grails” posts you can access them directly via their category link or in an RSS reader with the feed for just these posts.


Translations of this post:



Plugins

There was one new plugin released:

and 11 updated plugins:

  • coffeescript-resources version 0.3.7. Create coffeescript modules that automatically compiles on every file change with jCoffeeScript
  • console-enhancements version 1.0. Enhances the grails console output for better visibility
  • cxf-client version 1.5.2. Use existing (or new) Apache CXF wsdl2java generated content to invoke SOAP services
  • geasyui version 0.6. Supplies jQuery EasyUI resources and taglibs
  • goblin version 0.3.3. A browser game framework
  • gson version 1.1. Provides alternate JSON (de)serialization using Google’s Gson library
  • health-control version 0.2. Automated control of services, resources and other things that might fail from time to time
  • plastic-criteria version 0.7. Mock Grails Criteria for Unit Tests
  • spring-security-facebook version 0.13. Plugin for Facebook Authentication, as extension to Grails Spring Security Core plugin
  • spring-security-saml version 1.0.0.M20. SAML 2.x support for the Spring Security Plugin
  • webflow version 2.0.8. Integrates Spring Web Flow with Grails

Interesting Tweets

Jobs



User groups and Conferences


This Week in Grails (2013-10)

Tuesday, March 12th, 2013

The speaker lineup for GR8Conf US has been announced, and a partial list of speakers have been announced for GR8Conf EU. Be sure to get your tickets now before the prices go up.

I released a new plugin this week that adds Dropwizard support for Grails. Check out the introductory blog post for usage information and a test project.


If you want to keep up with these “This Week in Grails” posts you can access them directly via their category link or in an RSS reader with the feed for just these posts.


Translations of this post:



Plugins

There were 3 new plugins released:

  • dropwizard version 0.1. Adds support for Dropwizard
  • file-server version 0.1. Serves files from any directories on disk
  • health-control version 0.1. Automated control of services, resources and other things that might fail from time to time

and 14 updated plugins:

  • aws-sdk version 1.3.33. Use the Amazon Web Services infrastructure services
  • bootstrap-crumbs version 1.0.2. Provide simple breadcrumb functionality using the twitter bootstrap library
  • coffeescript-compiler version 0.9.2. Compiles .coffee source files into .js files
  • cxf-client version 1.5.1. Use existing (or new) Apache CXF wsdl2java generated content to invoke SOAP services
  • gson version 1.0.1. Provides alternate JSON (de)serialization using Google’s Gson library
  • hd-image-utils version 0.4. High quality image manipulation plugin for scaling and cropping images. Uses the pure Java java-image-scaling library
  • ic-alendar version 0.3.5. Export event data in the iCalendar format
  • jesque version 0.6.0. Groovier approach to using jesque
  • kickstart-with-bootstrap version 0.9.6. Start your project with a good looking frontend, with adapted scaffolding templates for standard CRUD pages using Twitter Bootstrap
  • mongodb version 1.2.0. Aims to provide an object-mapping layer on top of MongoDB
  • recaptcha version 0.6.2. Integrates ReCaptcha and Mailhide services
  • resources version 1.2. A resource management and processing framework
  • sharding version 0.9. Defines multiple database shards to horizontally scale data
  • wslite version 0.7.2.0. Integrates the https://github.com/jwagenleitner/groovy-wslite library

Interesting Tweets

Jobs



User groups and Conferences


This Week in Grails (2013-09)

Wednesday, March 06th, 2013

We released Grails 2.1.4 and 2.2.1 this week; they are primarily bug fix releases.

Registration for GR8Conf Europe 2013 is now open. Be sure to sign up soon while the prices are very low.

I’ve been seeing a lot of buzz about Dropwizard as a framework for creating REST services. I thought it would be interesting to integrate it with Grails, but it ended up being a lot more work than I expected since the two approaches are very different, and very opinionated. I have an initial implementation available of a plugin and will add some docs and a sample application soon.


If you want to keep up with these “This Week in Grails” posts you can access them directly via their category link or in an RSS reader with the feed for just these posts.


Translations of this post:



Plugins

There was one new plugin released:

and 7 updated plugins:

  • coffeescript-compiler version 0.8.1. Compiles .coffee source files into .js files
  • geasyui version 0.4. Supplies jQuery EasyUI resources and taglibs
  • jquery-validation-ui version 1.4.2. Client Side Validation without writing JavaScript
  • kickstart-with-bootstrap version 0.9.5b. Start your project with a good looking frontend, with adapted scaffolding templates for standard CRUD pages using Twitter Bootstrap
  • localizations version 1.4.4.10. Store i18n strings in a database
  • recaptcha version 0.6.0. Integrates ReCaptcha and Mailhide services
  • redis version 1.3.3. Provides integration with a Redis datastore

Interesting Tweets

User groups and Conferences


Grails Dropwizard Plugin

Wednesday, March 06th, 2013

I’ve been seeing a lot of buzz about Dropwizard as a framework for creating REST services. I thought it would be interesting to integrate it with Grails, but it ended up being a lot more work than I expected since the two approaches are very different, and very opinionated. I have released an initial Grails plugin that integrates Dropwizard: dropwizard. The source is here and the docs are here.

To make thing more clear, I created a simple test application. You can download it here.

Available URLs

The application has a simple Person domain class with a dynamically scaffolded controller, so typical URLs like http://localhost:8080/dropwizardtest/person/list work as expected. The Dropwizard resources are mapped under the default “dropwizard” context path, so you can make a GET request (for example in a browser) for http://localhost:8080/dropwizard/people to see the JSON response for all Person instsances; there is one created in BootStrap.groovy and you can easily add more.

You can also view a single instance by id, for example http://localhost:8080/dropwizard/people/1 which should display

{"id":1,"fullName":"Person Jones","jobTitle":"Jefe Grande"}

Since there is only one user, a GET request for http://localhost:8080/dropwizard/people/42 should display

No such user.

You can create a new Person with a POST request to http://localhost:8080/dropwizard/people – do this with a REST client, or the Firefox Poster addon, or even using curl from the commandline:

curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"fullName":"Other Person","jobTitle":"Other Title"}' http://localhost:8080/dropwizard/people

Now if you view all instances with http://localhost:8080/dropwizard/people/ it should look like

[{"id":1,"fullName":"Person Jones","jobTitle":"Jefe Grande"},{"id":2,"fullName":"Other Person","jobTitle":"Other Title"}]

or you can use curl again:

curl http://localhost:8080/dropwizard/people/

There is a simple hello-world endpoint which replies with a hello message, and uses a specified name if provided. If you GET http://localhost:8080/dropwizard/hello-world you will see a response similar to

{"id":1,"content":"Hello, Stranger!"}

and if you add a name parameter – http://localhost:8080/dropwizard/hello-world?name=Ralph – you will see

{"id":2,"content":"Hello, Ralph!"}

You can also POST to /hello-world with the data for a Saying instance:

curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"id":123,"content":"test saying"}' http://localhost:8080/dropwizard/hello-world

and it will log the information using Logback:

INFO  [2013-03-05 08:35:28,334] grails.app.dropwizard.com.example.helloworld.resources.HelloWorldDropwizardResource: Received a saying: id: 123, content: test saying

The plugin comes with support for Freemarker and Mustache templates. GET http://localhost:8080/dropwizard/views/utf8.ftl to see a Freemarker response, and http://localhost:8080/dropwizard/views/utf8.mustache to see Mustache.

There is also a simple endpoint under http://localhost:8080/dropwizard/info that you can make GET requests for:

Application is running on port : 8080 connectorType : blocking

To test support for tasks, POST to http://localhost:8081/dropwizard/tasks/gc to run a garbage collection using the default “gc” task:

curl -H "Accept: application/json" -X POST http://localhost:8081/dropwizard/tasks/gc

and the response should be

Running GC...
Done!

You can run the sample HelloDropwizardTask too; send a POST request to http://localhost:8081/dropwizard/tasks/hello-task :

curl -H "Accept: application/json" -X POST http://localhost:8081/dropwizard/tasks/hello-task

and it should display

my task complete.

The admin URIs are available on port 8081. GET http://localhost:8081/dropwizard/metrics or http://localhost:8081/dropwizard/metrics?pretty=true to see current metrics:

   {
  "jvm" : {
    "vm" : {
      "name" : "Java HotSpot(TM) 64-Bit Server VM",
      "version" : "1.7.0_11-b21"
    },
    "memory" : {
    ...

GET http://localhost:8081/dropwizard/healthcheck to run all health checks:

* DataSource: OK
* deadlocks: OK
* template: OK

GET http://localhost:8081/dropwizard/threads to view a thread dump:

main id=1 state=WAITING
    - waiting on <0x38a13ac9> (a java.lang.Object)
    - locked <0x38a13ac9> (a java.lang.Object)
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.join(QueuedThreadPool.java:391)
    at org.eclipse.jetty.server.Server.join(Server.java:413)
    at grails.plugin.dropwizard.GrailsService.start(GrailsService.java:131)
    ...

And finally you can GET the simple http://localhost:8081/dropwizard/ping URL to check that everything is functional:

pong

Application notes

Dropwizard typically loads resources from the classpath, so there are a couple of ways to make files available. You can put files in src/java or grails-app/conf and non-source files will be copied to the classpath. This can clutter up those directories though, so you might want to add in a new folder for these files. The sample application has a src/resources folder for this, and adds an event callback in scripts/_Events.groovy to ensure that the files are available:

eventCompileStart = {
   ant.copy(todir: buildSettings.resourcesDir,
            failonerror: false,
            preservelastmodified: true) {
      fileset(dir: 'src/resources') {
         exclude(name: '*.groovy')
         exclude(name: '*.java')
      }
   }
}

You can put banner.txt there if you want a banner displayed and don’t set the Config.groovy property, the YAML config file, Freemarker and Mustache template files, and static resources mapped with AssetsBundles.

As mentioned in the plugin documentation, serialization of domain classes doesn’t work. The plugin explicitly converts Person instances to and from PersonDTO instances (e.g. see PeopleDropwizardResource). GORM isn’t required, so you’re free to use regular POJO/POGO based persistence. There is a somewhat old dto plugin that may or may not help here.

All of the test application’s classes (resources, health checks, etc.) are written in Groovy and are in grails-app/dropwizard, but as described in the docs you can write them in Java and register them yourself rather than using convention-over-configuration and letting them be auto-discovered. Classes in grails-app/dropwizard support dependency injection (for example the dataSource bean in DataSourceHealthCheck), and can conveniently access Config.groovy values with the ConfigValue annotation (see TemplateHealthCheck for an example of this).

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.