After being a little bit disappointed about using Grails in Alfresco (see my post below), I decided to see how could Alfresco be integrated with Groovy.
Alfresco introduced a while ago the "webscripts", with that they added a powerful scripting API based on JavaScript and the Rhino engine. When you add FreeMarker templates to that, what you could get is a nice output that you could customize to be some JSON data, XML or whatever suites you. That is amazing but I was not that happy as we have to wait for Alfresco to expose more of their services via the scripting API. Adding Groovy capabilities to any application and not only to Alfresco seems "natural" and I think that it helps in prototyping without having to recompile.
I took the groovy.servlet.GroovyServlet implementation and added a few lines that allows to configure a Spring bean as servlet parameters and to make them available in the groovy scripts.
The code is not yet published somewhere as a forge project but you can find it here. All you have to do is have Spring and Spring MVC on your classpath (Alfresco already has it) add Groovy libraries (groovy-all is a good solution, at least version 1.5.x) and configure your web.xml with the Groovy servlet that I am providing, an example could be found here. That example is using spring's DispatcherServlet but you could use the GroovyServlet as any other servlet, directly in your web.xml. If your are also using the DispatcherServlet then you have to configure it correctly as shown here.
Once you are done with those configuration just add the desired beans to the servlet configuration and you are on "rails" with Alfresco.
The samples provided here are using the ServiceRegistry bean and it is mapped in Groovy as registry, so to get any other Alfresco service you have to start from there. But you are free to map whatever bean you want.
Although, some people are saying that there are problems using Alfresco beans with Groovy, I did not have those problems till now, but I am not saying it will happen.
Subscribe to:
Post Comments (Atom)
2 comments:
Based on this idea I integrated a groovy server to try out the API:
http://thinkalfresco.blogspot.com/2009/01/groovy-scripting-for-alfresco-alf-hack.html
Hi,
have you tried Jibe. There is a nice Groovy integration with Alfresco.
Post a Comment