Blog

ColdBox Presents: Groovy Integration

Luis Majano April 15, 2009

Spread the word

Luis Majano

April 15, 2009

Spread the word


Share your thoughts

We are releasing a 1.0 version of our GroovyLoader plugin for ColdBox Applications today.  This plugin can be found in the extra downloads section of the ColdBox Website as part of the projects pack.  So what did we do, well, based on Barney Boisvert's inspiration on CFGroovy, we decided to create a plugin that would leverage ColdBox users with the Groovy Scripting Language.  We took some different approaches to the integration and we still have many things planned for it.  But as of now, these are the features that our GroovyLoader exhibits
  • Drop and Play functionality on ANY ColdBox application running on Railo 3.0 >, Adobe CF 8 >, or Open BD
  • Load a groovy environment (1.6.0) into any ColdBox application without modifying the running CF engine.  It uses our integrated JavaLoader to load all necessary libraries without modifying the CF engine.  It can also, load up ANY library you place in the GroovyLoader's lib directory automatically.  So if you kids start fooling around with packaged groovy libraries or java libraries like Hibernate, Spring, Gorm, etc. You can do so, by just dropping the files in that pre-configured folder.
  • Setup of a directory that will hold groovy classes/scripts, that the GroovyLoader will try to load at runtime. Uses the configureClassPath() method of the plugin and usually called once.
  • Integration with the ColdBox cache to provide resolution of parsed groovy-to-java classes for all parsed groovy source, including custom groovy source compilations
  • Ability to clean the parsed class cache from the ColdBox cache
  • Ability to clean the groovy classloader cache of parsed bits
  • Ability to handle complex groovy/java relationships and hierarchies
  • Easily extend/decorate the plugin to meet your needs or enhance it
  • Create groovy classes: create(clazz)
  • Execute groovy scripts: runScript(scriptName,varCollection)
  • Execute groovy source code: runSource(scriptSource,varCollection)
  • Execute groovy source code using a custom tag import
  • Groovy scripts and source code executions will be binded with the following variables. This means that the groovy scripts that are executed using runScript() and runSource() will have the following variables IMPLICITLY created at runtime. This creates a data bridge between ColdFusion and Groovy.
    • A custom passed structure called varCollection. This can have anything you like.
    • The coldbox request collection: coldbox_rc
    • The following coldfusion variables:
      • cf_pagecontext : The coldfusion pagecontext object
      • cf_application : The coldfusion application scope
      • cf_server : The coldfusion server scope
      • cf_session : The coldfusion session scope (if available)
So how does it work. Well, first of all, the download includes a very simple application that you can replicate and learn from.  As our integration progresses we will be adding more functionality and some extra surprises our very own Sana Ullah has been working on for quite a while now. Step1: Install the custom plugin in your application or as a core plugin, basically drop the GroovyLoader folder in your plugins directory of your app Step 2: Init the plugin on application start, usually the application start handler: Step 3: That's it, you can now use it a la carte to create groovy classes, run scripts, or run on deman source code via the method or the imported tag. You can see some sample handler methods below: var rc = event.getCollection(); rc.oHello = instance.GroovyLoader.create("Hello"); event.setView("home"); var rc = event.getCollection(); instance.GroovyLoader.clearClazzCache(); setNextEvent('groovy'); rc.varCollection = {createdAt=now()}; instance.GroovyLoader.runScript('Test',rc.varCollection); event.setView("runscript"); var rc = event.getCollection(); /* Source */ var source = "varCollection.GroovyArray = [1,2,3,4]"; rc.varCollection = {createdAt=now()}; instance.GroovyLoader.runSource(source,rc.varCollection); event.setView("runSource"); def today = coldbox_rc["today"] def SubjectLine = ["Hello","my","name","is","Luis Majano.","Expressed at",today] //Place in ColdBox event context coldbox_rc["SubjectLine"] = SubjectLine.join("_") I hope you enjoy this plugin and you help make it even better and better.

Add Your Comment

(3)

Apr 16, 2009 16:37:35 UTC

by Manithan

That is really great which is the perfect timing i was just looking for it where i have dynamic bean created and was planing to use with spring. i am really excited to try this one. thanks a lot. you rock!!!

Apr 22, 2009 04:45:05 UTC

by Martin

WOW - thats is what i need - thanks a lot! But the only question for me is: How can i use the hibernate plugin? In the CFGroovy project from Barny there is hibernate integrated. Is there a way to integrate it easy in the Coldbox-Groovy Plugin? My idea is to make the whole DAO-Layer in groovy+hibernate. and call it from CFCs :-)

Apr 22, 2009 11:28:51 UTC

by Luis Majano

HI Martin, We will be adding hibernate support in the next release. However, you are more than welcome to give it a shot. All the hooks are in place to set this up.

Recent Entries

October is here, and that means Hacktoberfest!

October is here, and that means Hacktoberfest!

Hacktoberfest is here!

Ortus Solutions is built upon Open source with our flagship products all open source, this event holds a special place in our hearts and it’s a great space to show developers how we are modernizing the CFML language. We invite everyone to get involved and contribute to CFML Community Projects, with documentation, code, and new this year, non-code contributions. 

Maria Jose Herrera
Maria Jose Herrera
October 04, 2022
Using CommandBox Docker Images to Perform Bytecode Source Conversions

Using CommandBox Docker Images to Perform Bytecode Source Conversions

There are times when code needs to be shipped in a compiled state. It might be for obfuscation or source protection, it might just because it runs faster that way, without the CFML server needing to compile templates at runtime. It's an excellent use case for production Docker images and code deploy pipelines.

Jon Clausen
Jon Clausen
October 03, 2022
cbElasticsearch 2.3.3 Released

cbElasticsearch 2.3.3 Released

We are pleased to announce the release of cbElasticsearch version 2.3.3. cbElasticsearch is the Elasticsearch module for the Coldbox platform, and provides a fluent CFML API for interacting with, searching, and serializing to Elasticsearch servers.

This release adds full compatibility for Elasticsearch v8.x as well as maintaining support for Elasticsearch versions 6 and 7.

Jon Clausen
Jon Clausen
October 03, 2022