Archive for February, 2012

This Week in Grails (2012-08)

Monday, February 27th, 2012

Check out Mike Hugo’s cool screencast demonstrating the AutoTest plugin. The plugin looks great – I’m a big fan of anything that makes testing easier, quicker, or more intuitive.

I released a version of the database-session plugin that actually works (the version 1.0 release should have been a snapshot). I created it to be able to deploy apps on Heroku and run multiple web server instances (they don’t support session affinity or clustering) but it’s usable any time you want to store session data in a database or other datastore. In fact Masatoshi Hayashi has created a variant of the plugin that uses MongoDB and I’ll be working with him to get that released soon. Anybody want to write one that uses Redis or Memcached?

I’ll also be working with Alex Shneyderman to get a release of the hibernate-filter plugin out this week. It’s almost ready to go and works with Grails 2.0 apps, so it should be out soon.

If you haven’t already, check out my post Using Servlet 3.0 Async Features in Grails 2.0. Note that Tomcat 7.0.26 was released this week and it fixes a serious bug when deploying servlet 3.0 applications that would cause an OOME unless you disabled scanning for annotated web.xml classes.


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:

  • delicious version 0.1. Integration with the Del.icio.us API
  • grails-runtime-docs version 1.0.0-M1. Generates both Java and Groovy documentation for a project, also displaying the dynamic methods and properties added to artifacts along with their source information
  • zendesk version 1.0.1. Interface to Zendesk support system via their API

and 17 updated plugins:

  • ajax-uploader version 1.1. Tag Library which implements Andrew Valum’s excellent file uploader
  • build-test-data version 2.0.1. Enables the easy creation of test data by automatic inspection of constraints
  • database-session version 1.1.2. Stores HTTP sessions in a database
  • equals-hashcode-test version 0.2-spock-0.5-groovy-1.7. Base Spock specification for testing equals and hashCode methods of domain classes and other Groovy objects
  • file-viewer version 0.3. Provides a user-friendly way to view folders and files
  • functional-test version 2.0-M1. Functional web testing using HtmlUnit to simulate the client browser
  • heroku version 1.0.1. Integrates Heroku’s cloud platform
  • joda-time version 1.4. Integrates the Joda Time date/time library into Grails
  • jxl version 0.51. Export data to Excel using the JXL library
  • localizable version 0.3. A wrapper for Google Maps geocoding service
  • mongodb-morphia version 0.7.8. Alternative MongoDB GORM based on the Morphia library (former gorm-mongodb)
  • multi-tenant-single-db version 0.8.2. Multi tenant setup focused on single database mode
  • simple-blog version 0.2.0. Adds a simple blog interface to an application
  • vaadin version 1.5.3. Adds Vaadin (http://vaadin.com/) integration
  • zk version 2.0.0.M5. Adds ZK Ajax framework (www.zkoss.org) support to Grails applications
  • zk-hibernate version 2.0.0.M5. Hibernate support for ZKGrails
  • zkui version 0.5. Seamlessly integrates ZK with Grails’ infrastructures; uses the Grails’ infrastructures such as GSP, controllers rather than zk’s zul as in ZKGrails plugin

Interesting Tweets

Jobs



User groups and Conferences


This Week in Grails (2012-07)

Tuesday, February 21st, 2012

Grails 2.0.1 was released this week. Check out the release notes page which has a link to the JIRA changelog and Graeme’s blog post.

A couple of cloud-related items. The Heroku deployment process depends on a bundled version of supported versions of Grails that includes the Jetty jars that will be used to run the server for that instance. They’re working on a 2.0.1 bundle but it’s not ready yet, so you’ll need to continue to use 1.3.7 or 2.0.0 until this is resolved. There’s also an issue with Cloud Foundry affecting Grails applications that use the Spring Security Core plugin. The deployment process is reordering filter-mapping elements in the web.xml file and causing IllegalStateExceptions. It only affects annotation-guarded applications, so using one of the other two approaches is a workaround. Watch this JIRA issue if this affects you.

Update: the Heroku team updated their supported versions and you can now deploy 2.0.1 apps along with 2.0.0 and 1.3.7


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 1 new plugin released:

  • tomcat-bundler version 0.0.1. Simplifies bundling application with Tomcat to create a whole package to be used by hosting

and 16 updated plugins:

  • cdn-resources version 0.2.1. Loads static resources using Content Delivery Networks using the Resources plugin framework
  • coffeescript-resources version 0.3.1. Create coffeescript modules that automatically compiles on every file change with jCoffeeScript
  • cxf-client version 1.2.7. Use existing (or new) Apache CXF wsdl2java generated content to invoke SOAP services
  • fields version 1.0.4. Customizable form-field rendering based on overrideable GSP template
  • grails-template-engine version 0.2.1. Exposes the GSP engine as a service to render GSPs outside of a web request
  • ic-alendar version 0.3.4. Export event data in the iCalendar format
  • jaces version 1.7.2.2. Streamlines the process of creating database applications using Dojo
  • kickstart-with-bootstrap version 0.5.6. Start your project with a good looking frontend, with adapted scaffolding templates for standard CRUD pages using Twitter Bootstrap
  • pluginator version 0.2. Lets you define callbacks and properties in an application that are normally only available in plugins, e.g. doWithWebDescriptor, doWithDynamicMethods, loadAfter, observe, etc.
  • raphael version 2.0.2. Provides the JavaScript Vector Library Raphaël – cross-browser vector graphics the easy way
  • regen version 0.3. Provides a generation framework and a set of pluggable artefacts under grails-app/generators
  • spring-security-facebook version 0.6.2. Plugin for Facebook Authentication, as extension to Grails Spring Security Core plugin
  • spring-security-oauth2-provider version 1.0.0.M5.1. OAuth2 Provider support for the Spring Security plugin
  • zk version 2.0.0.M4. Adds ZK Ajax framework (www.zkoss.org) support to Grails applications
  • zk-hibernate version 2.0.0.M4. Hibernate support for ZKGrails
  • zkui version 0.5.M3. Seamlessly integrates ZK with Grails’ infrastructures; uses the Grails’ infrastructures such as GSP, controllers rather than zk’s zul as in ZKGrails plugin

Interesting Tweets

Jobs



User groups and Conferences


Using Servlet 3.0 Async Features in Grails 2.0

Monday, February 20th, 2012

I was talking to someone last week about the new support for Servlet 3.0 async features in Grails 2 and realized I didn’t know that much about what was available. So I thought I’d try it out and share some examples. The documentation is a little light on the subject, so first some background information.


The primary hook to do asynchronous work in the 3.0 spec is the new startAsync method in the javax.servlet.ServletRequest class. This returns an instance of the javax.servlet.AsyncContext interface which has lifecycle methods such as dispatch and complete, gives you a hook back to the request and response, and lets you register an javax.servlet.AsyncListener. You call the start method passing in a Runnable to do the asynchronous work. Using this approach frees up server resources instead of blocking, which increases scalability since you can handle more concurrent requests.

In order to use this however the servlet that handles the request must support async, and all applied filters in the filter chain must too. The main Grails servlet (GrailsDispatcherServlet) is registered in the 3.0 version of the web.xml template with the async-supported attribute set to true. And Servlet3AsyncWebXmlProcessor adds <async-supported>true</async-supported> to all filter declarations in web.xml after it’s generated. So that’s covered for you; there is no required web.xml configuration on your part.

You also have to be configured to use servlet API 3.0. This is simple to do; just change the value of grails.servlet.version to “3.0” from the default value of “2.5”. Note that there is a legacy setting in application.properties with the name app.servlet.version; you should delete this line from your application.properties file since its value is ignored and overridden at runtime by the value from BuildConfig.groovy.


You don’t call startAsync on the request from a controller though; call startAsync directly on the controller. This method is added as a controller method (wired in as part of the controllers’ AST transforms from ControllersAsyncApi (by ControllerAsyncTransformer if you’re curious)). It’s important to call the controller’s startAsync method because it does all of the standard work but also adds Grails integration. This includes adding the logic to integrate all registered PersistenceContextInterceptor instances, e.g. to bind a Hibernate Session to the thread, flush when finished, etc., and also integrates with Sitemesh. This is implemented by returning an instance of
GrailsAsyncContext which adds the extra behavior and delegates to the real instance provided by the container (e.g. org.apache.catalina.core.AsyncContextImpl in Tomcat) for the rest.

Therer are a few other new async-related methods available in the request; they include boolean isAsyncStarted() and AsyncContext getAsyncContext().


I’ve attached a sample application (see below for the link) to demonstrate these features. There are two parts; a simple controller that looks up stock prices asynchronously, and a chat application.

StockController is very simple. It just has a single action and suspends to look up the current stock price for the requested stock ticker. It does this asynchronously but it’s typically very fast, so you probably won’t see a real difference from the serial approach. But this pattern can be generalized to doing more time-consuming tasks.

Call http://localhost:8080/asynctest/stock/GOOG, http://localhost:8080/asynctest/stock/AAPL, http://localhost:8080/asynctest/stock/VMW, etc. to test it.

The second example is more involved and is based on the “async-request-war” example from the Java EE 6 SDK. This implements a chat application (it was previously implemented with Comet). The SDK example is one large servlet; I split it up into a controller to do the standard request work and the ChatManager class (registered as a Spring bean in resources.groovy) to handle client registration, message queueing and dispatching, and associated error handling.

The implementation uses a hidden iframe which initiates a long-running request. This never completes and is used to send messages back to each registered client. When you “login” or send a message, the controller handles the request and queues a response message. ChatManager then cycles through each registered AsyncContext and sends JSONP to the iframe which updates a text area in the main page with incoming messages.

One thing that hung me up for quite a while was that things worked fine with the SDK example but not mine. Everything looked good but messages weren’t being received by the iframe. It turns out this is due to the optimizations that are in place to make response rendering as fast as possible. Unfortunately this resulted in flush() calls on the response writer being ignored. Since we need responsive updates and aren’t rendering a large page of html, I added code to find the real response that’s wrapped by the Grails code and send directly to that.

Try it out by opening http://localhost:8080/asynctest/ in two browsers. Once you’re “logged in” to both, messages sent will be displayed in both browsers.

Some notes about the test application:

  • All of the client logic is in web-app/js/chat.js
  • grails-app/views/chat/index.gsp is the main page; it creates the text area to display messages and the hidden iframe to stay connected and listen for messages
  • This requires a servlet container that implements the 3.0 spec. The version of Tomcat provided by the tomcat plugin and used by run-app does, and all 7.x versions of Tomcat do.
  • I ran install-templates and edited web.xml to add metadata-complete="true" to keep Tomcat from scanning all jar files for annotated classes – this can cause an OOME due to a bug that’s fixed in version 7.0.26 (currently unreleased)
  • Since the chat part is based on older code it uses Prototype but it could easily use jQuery

You can download the sample application code here.

This Week in Grails (2012-06)

Tuesday, February 14th, 2012

Groovy 1.8.6 was released this week and the upcoming Grails 2.0.1 release will include it.

The call for papers for GR8Conf Europe and GR8Conf US ends this week on the 15th so be sure to get your proposals in ASAP.

I released an update of the console plugin this week but all the credit for the changes goes to Matt Sheehan. The UI now supports either a horizontal or vertical view and has several other usability and look/feel tweaks (like CTRL+Enter will execute the current code). Upgrade to version 1.1 to see the updates.

It’s been 17 months since the last release, but the 0.2 release of the Spring Security UI plugin is finally out. It includes 19 fixed JIRA issues and now works with Grails 1.3.x and 2.0.0. Check out the docs here. I’m hoping to have some time this week to do a quick blog post this week discussing the changes and some notes on upgrading, in particular if you’ve customized some of the pages.

Check out my Why I’ll never use Groovy on Grails post if you haven’t already, and spread the word – there are still a lot of confused people out there 🙂


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 2 new plugins released:

  • kickstart-with-bootstrap version 0.5. Start your project with a good looking frontend, with adapted scaffolding templates for standard CRUD pages using Twitter Bootstrap
  • sham version 0.2. Uses the sham data generation library to generate test/demo data

and 22 updated plugins:

  • autobase version 1.0.0.0. Database migrations
  • build-info version 1.2.3. Provides a controller/view that display basic information about the war file
  • build-test-data version 2.0.0. Enables the easy creation of test data by automatic inspection of constraints
  • console version 1.1. A web-based Groovy console for interactive runtime application management and debugging
  • constraints version 0.8.0. Allows you to create custom domain Constraints for validating Domain objects
  • dojo version 1.7.1.5. Integrates the Dojo javascript toolkit
  • drools-gorm version 0.5.6. Integrates Drools 5.2 and jBPM 5 and provides persistent storage using GORM
  • export version 1.1. Export domain objects to a variety of formats (CSV, Excel, ODS, PDF, RTF and XML)
  • external-config-reload version 1.0.0. Polls for changes to external configuration files (files added to grails.config.locations), reloads the configuration when a change has occurred, and notifies specified plugins by firing the onConfigChange event in each
  • feature-toggle version 0.2. Provides Tag Libraries and dynamic methods to implement configurable features
  • fields version 1.0.3. Customizable form-field rendering based on overrideable GSP template
  • gsp-taglib version 0.4. Makes it possible to declare tags in a gsp in grails-app/taglib
  • jaxrs version 0.6. Supports the development of RESTful web services based on the Java API for RESTful Web Services (JSR 311: JAX-RS)
  • lesscss-resources version 1.0.1. Optimises the use of http://www.lesscss.org css files, compiling .less files into their .css counterprt, and place the css into the processing chain to be available to the other resource plugin features
  • paypal version 0.6.6. Adds PayPal integration
  • routing version 1.2.0. Send and route messages to a wide variety of destination endpoints directly from your Controllers and Services using Camel
  • routing-jms version 1.2.0. JMS integration for the grails-routing plugin
  • spring-security-facebook version 0.6. Plugin for Facebook Authentication, as extension to Grails Spring Security Core plugin
  • spring-security-oauth2-provider version 1.0.0.M5.1-SNAPSHOT. OAuth2 Provider support for the Spring Security plugin
  • spring-security-ui version 0.2. User interface extensions for the Spring Security plugin
  • zk version 2.0.0.M3. Adds ZK Ajax framework (www.zkoss.org) support to Grails applications
  • zk-hibernate version 2.0.0.M3. Hibernate support for ZKGrails

Interesting Tweets

Jobs



User groups and Conferences


Why I’ll never use Groovy on Grails

Monday, February 06th, 2012

Why? Because it doesn’t exist. The framework is called Grails. Just Grails. Go to http://grails.org/ and search the site. You won’t see any “Groovy on” anywhere. Seriously. Check it out. I’ll wait.

I guess some history about what caused all this is in order. Back in 2005 the Grails framework was started after discussions on the Groovy mailing list about the idea of a Groovy-based JVM alternative to Ruby on Rails which was then starting to get a lot of buzz. The original name was “Groovy on Rails”, but only a few months later in March 2006 Graeme sent a note to the mailing list titled “Groovy on Rails is no more (kind of)” saying that David Heinemeier Hansson had complained about the name, so he was changing it to just “Grails”.

It’s now February 2012. One month short of six years since the name was changed to Grails. And yet there are still a lot of recruiters (who are for the most part beyond hope) and even developers (who should know better) who call Grails “Groovy on Grails” and “Groovy on Rails”. “Groovy on Rails” makes some sense since there’s a historical basis for it, but “Groovy on Grails” makes me think of nonsense phrases like Splooby on Splails. We don’t call Spring MVC “Spring on Java” or Struts “Struts on Java”. Django isn’t “Django on Python”. Even recruiters looking for “Groovy & Grails” developers are a bit confused since you can’t use Grails without Groovy.

I was thinking that if there were a PHP framework that used the Rails-like convention-over-configuration approach that they could call it PHP on Rails, but that developers would just call it Phails, so I guess that’d be unfortunate. But someone did this, and I’m guessing got a similar note from DHH since the PHP on TRAX website describes the name as “Php On Trax (formerly Php On Rails)”.

So if you’re one of “them”, stop. Refer to the framework as Grails. And when replying to clueless recruiters who are looking for Groovy on Grails developers, gently remind them that there’s no such thing.

This Week in Grails (2012-05)

Monday, February 06th, 2012

Rob Fletcher has been doing some great work on scaffolding. Check out this slick demo app on Cloud Foundry. It uses his Fields plugin (the successor to the bean-fields) and Twitter Bootstrap.

I realized this week that I’d missed the transition of Rob’s blog to its new home and had missed some interesting posts: Organizing Functional Tests and Optional Tag Bodies.

When I switched to 2.0 for development of the Spring Security Core plugin, the PDF of the docs was clipped on the right and I assumed it was because of a 2.0 bug so I removed the PDF from the docs page. I tried generating PDF docs this week for another project and it worked fine and I realized that it was actually a combination of long non-breaking strings and the new larger font that was the issue, so I added in some spaces to allow line breaks and updated the docs page with a link to the PDF.

I also did some work to make working with Heroku a bit better. There was a reported issue with using SSL and Spring Security so I released a small update of the spring-security-core plugin (v1.2.7.2) to address that and updated the Heroku docs about how to use it. There wasn’t a need to update the Heroku plugin – it involves a configuration setting for the security plugin. I’m now also generating PDF docs for the Heroku plugin which you’ll see at the docs link.

Another standing issue with Heroku and Spring Security has to do with sessions when running multiple instances of an application. Heroku doesn’t offer any session clustering or session affinity options, so authentication will usually fail because after successfully logging into one instance, you’ll get redirected and there’s a good chance you’ll end up on an instance that doesn’t have your authentication details in its session. I started playing with an approach to session management that stores sessions in a database (either a database or a NoSQL store or even Memcached) and released a preliminary version of the database-session plugin to test it out, but it’s not ready yet. It was a mistake to release it as 1.0 – it should have been a snapshot release – so don’t use it yet.

I also updated the runtime-logging to work with Grails 1.3 and 2.0.


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 8 new plugins released:

and 22 updated plugins:

  • asynchronous-mail version 0.4. Send email asynchronously by storing them in the database and sending with a Quartz job
  • auto-test version 1.0. Monitors the project directory and attempts to run only the subset of tests affected by what changed
  • bean-fields version 1.0.BUILD-SNAPSHOT. Provides a suite of tags for rendering form fields for domain and command objects
  • cxf-client version 1.2.6. Use existing (or new) Apache CXF wsdl2java generated content to invoke SOAP services
  • dojo version 1.6.1.5. Integrates the Dojo javascript toolkit
  • elasticsearch version 0.18.7.1-SNAPSHOT. Adds support for the http://www.elasticsearch.com/ RESTful search engine
  • external-config-reload version 0.4.9. Polls for changes to external configuration files (files added to grails.config.locations), reloads the configuration when a change has occurred, and notifies specified plugins by firing the onConfigChange event in each
  • fields version 1.0.1. Customizable form-field rendering based on overrideable GSP template
  • grom version 0.2.3. Sends notifications on Windows, Linux, and Mac
  • jesque version 0.3.0. Groovier approach to using jesque
  • jesque-web version 0.3.0. Web interface to view and manage jesque queues, jobs and workers
  • jquery-mobile version 1.0.4. Provides jQuery mobile framework resource files
  • lesscss-resources version 1.0. Optimises the use of http://www.lesscss.org css files, compiling .less files into their .css counterprt, and place the css into the processing chain to be available to the other resource plugin features
  • paypal version 0.6.5. Adds PayPal integration
  • redis version 1.2. Provides integration with a Redis datastore
  • routing version 1.1.7. Send and route messages to a wide variety of destination endpoints directly from your Controllers and Services using Camel
  • runtime-logging version 0.4. Control Log4j logging at runtime
  • spring-security-core version 1.2.7.2. The official Grails security plugin; integrates with Spring Security
  • spring-security-saml version 1.0.0.M13. SAML 2.x support for the Spring Security Plugin
  • spring-security-shibboleth-native-sp version 1.0.3. Shibboleth Naitive SP support for the Spring Security grails plugin
  • twitter-bootstrap version 2.0.0.16. Twitter Bootstrap CSS framework resource files
  • twitter4j version 0.3.2. Send and receive Twitter messages using the twitter4j library

Interesting Tweets

Jobs



User groups and Conferences


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