Wednesday, January 13, 2010

Apache ServiceMix - Close encounter

Hi there,

I've been pushed by the project I'm working on to use a very specific platform for integrating services, namely Apache ServiceMix. After spending around 8 hours trying to put this piece of code to some use (and failing miserably) I've decided to blog about it.

It's going to be very negative! You've been warned!

Let me start from the absolute beginning which is installation. Apache ServiceMix comes in 2 different distributions: one directly from Apache and another one maintained by IONA company called Fuse ESB. Both were easy to install (especially easy in the case of Apache distro where it came in the usual zipped form ready to go after unzipping). Iona was a bit more annoying with its GUI-based installer (you guys thing we're morons not able to use zipped folders? I hope not!).

After a brief lecture of the tutorial I've started to do some coding. Well, it's an integration platform after all so I thought some "integration exercise" will be ok to start with. All I wanted to do was to generate some messages in constant intervals using quartz and send them to a message queue provided by ActiveMQ (btw. if you have not tried ActiveMQ I strongly recommend you do check it out! It's an amazing piece of free software!).

My problems started at the very beginning where I've had to browse through tons of poorly structured documentation (on both Iona and Apache web sites) to get the hang of how do I actually proceed with such a use case. At this point one might think it is ok because it is a complicated piece of technology so doing some reading is kind of expected... "Some" being the key word here: 8 hours spent on googling for information without much success is in my humble opinion a total disaster! Have you guys heard about user friendliness and learning curves? Not all of us are ESB gurus but many of us are thrown into the pit where using SMX is needed. You really might have done better here!

Speaking of which, there is actually support you can get - but it's PAID!!! You have to pay some jerks to give you information about stuff they have "packaged" and "maintained", whatever the latter part means. This is theft, to say the least...

Going back to the available materials. There's a "tutorial". A piece of "documentation" written in a very easy to understand way. Had this sh*t been right top to bottom my complains would not have been so hard. I mean can you imagine trying to find out how to deal with grails and be left with a hello-world-style application that does not even compile? Or if it actually compiles then running it is a no-go? Can you beat that?!

Moving on I've finally found the answer on the net (provided by some poor soul trying to do the same thing I did today, meaning get started with SMX) and he already found the errors so I was able to do the changes and see (exactly) one file being moved from one folder to another! Ain't that cool?!

Amazed by the extreme complexity of the solution I made I thought that doing some scripting would be kind of cool and maybe would provide me with some more confidence that not everything is actually lost. So I did some googling and bang! There it is! The actual "component" I need was called servicemix-scripting, there's a Maven archetype that creates an example service unit from scratch so I was hoping to feel a loooot more positive. Again, nothing could have been further from the truth...

servicemix-scripting is not available from Iona repositories but it comes bundled with Apache distribution. It is said that "components are written to be JBI-compliant" so I thought moving one component from one distro to the other should not present any issues since both are JBI compliant. The disappointment was huge when I found out that my service unit not only does not start (the one generated by default using Maven archetype) but the error message says completly nothing. I was like "assembly failed to do something because of administrative error of some damn kind"... ehhhhhhh...

I will not bother you with the "F" words I wanted to say about JMS integration. Suffice to say its description and tutorials are where the sun does not shine.

Well, had this not been part of my daily work I would have thrown it away after like 1 hour (yes, I am extremely pervasive! :) ). Will see if I can squeeze some positive outcome in the coming days out of this product. If I do (or if I don't) I'll blog about it soon.

Sunday, January 3, 2010

JavaScript Framework Comparison

I've just stumbled upon a very nice JavaScript framework comparison by Matthias Schuetz. Check it out at here

Saturday, December 26, 2009

Grails - a decomposed application project

Hi there,

I've been looking around for ways to nicely decompose a large application (an Enterprise Application so to speak) using Grails. It turns out this platform has such a capability already build-in! Interested? Read on...

The basic building blocks of Grails are plugins. There's a plugin for everything: the ORM layer, IoC container, security, twitter access - you name it! So how is this going to help us decompose a large enterprise-grade application? Well, we're going to compose it from... plugins!

Here's a step-by-step instruction on how to create the main application along with one additional pluging. Other plugins can be added exactly the same way as the single one mentioned here.
  1. Create a grails application (we're going to name it "myapp" here) using standard Grails command grails create-app myapp
  2. Do not change the folder just yet to myapp - instead issue the following Grails command: grails create-plugin myapp-plugin
  3. cd to myapp
  4. Add the line plugins.myapp-plugin=0.1 to application.properties (that's in the main application, not in the plugin!)
  5. cd to grails-app/conf
  6. Add the following line to BuildConfig.groovy: grails.plugin.location.'myapp-plugin' = '../myapp-plugin'
  7. cd out of the application and into the myapp-plugin folder
  8. Issue grails package-plugin command to create plugin.xml
  9. cd back to your application and run it as usual using grails run-app
That's it! Whenever you make changes to your plugin they will be automatically picked up just as if they were a part of your main application which is the greatest feature ever!

Have fun!

Friday, December 25, 2009

Groovy - dumping object's properties

Marry Christmas! This is the Christmas Eve and what follows is a Christmas Present for you!

Have you ever used BeanUtils from Apache to query the properties of an object? Was that easy? Well I did that and what I ended up was completely unreadable and chaotic. But there's good news! Here's how it's doable in Groovy:
object.properties
That's it! Groovy exposes the map of properties as a predefined property called "properties". Ain't that cool? Let's see how we would go about printing all the values of object's properties along with their names:
println object.properties.collect{it}.join('\n')
Here's what it's doing: it gets the map of properties, turns it into a list (collect{it}) and joins them with a new line character.

Did you notice that "class" is also one of the properties? That's nasty! How about filtering it out?
println object.properties.findAll{it.key != 'class'}.join('\n')
Now that's much better, but good only for one or two names to filter. How about a more general solution?
def filtered = ['class', 'active']
println object.properties
.collect{it}
.findAll{!filtered.contains(it.key)}
.join('\n')

That's much much better but still, if the object has like 15 properties looking them up is a pain if they are not sorted. Let's do something about it:
def filtered = ['class', 'active']

println object.properties
.sort{it.key}
.collect{it}
.findAll{!filtered.contains(it.key)}
.join('\n')

And there it is! A list of key=value (value taken from object's toString()) separated by a new-line character for easier browsing :)

I hope this will help you out with your Groovy adventures!

Have a nice holiday!

Sunday, December 20, 2009

Deploying Grails application on Tomcat6 on Ubuntu

Hi,

I've just had a few moments of struggle deploying my Grails application onto Tomcat installed via apt-get in Ubuntu. Thanks to the Ubuntu forum it didn't morph into a war :)

After apt-get install tomcat6 and putting my application into the webapps folder I've restarted Tomcat using the usual script but could not access my application at all. The log said something like this:

SEVERE: Exception sending context destroyed event to listener instance of class org.codehaus.groovy.grails.web.util.Log4jConfigListener
java.security.AccessControlException: access denied (java.util.PropertyPermission grails.env read)

After a few minutes of search I found the answer. By default Tomcat on Debian and Ubuntu uses a security manager that prevents application to access environment variables. Why this is the case I don't know but it is. And it is easy to turn it off. Just edit the file /etc/default/tomcat6 and change the line that reads

#TOMCAT6_SECURITY=yes

into

TOMCAT6_SECURITY=no

and live is good again.

Hope this helps!

Friday, December 18, 2009

Grails - the search is over

Recently I've been crushed with the simplicity of Grails framework. For those of you who don't know what's this thing is all about please check the Grails web site - it's well worth your while!

Here are some highlights I've checked out during the evaluation process:
  • Grails combines the best open source technologies into one easy to use framework (Spring IoC, Hibernate, Spring MVC, Spring WebFlow)
  • Additional integrations are as easy as one-line plugin installation (Jabber integration, JMS integration, additional view capabilities, JavaMelody monitoring - just to name a few)
  • ActiveRecord pattern as well as dynamic finders rock!

Stay tuned for some working examples. I'll post them during the weekend.

Monday, December 7, 2009

Transcoding AVCHD using latest FFMPEG build

Recently I found myself arguing with ffmpeg to accept the fact that my template for libx264 is in fact where I know it is. Some time ago it was pretty simple - you just had to copy the template into the current directory and use the form -vpre ./preset to make ffmpeg use it. Unfortunately after last update of ffmpeg this is not the case anymore...

After some time I've finally figured it out. Due to some incompatibility between the Linux version and Win32 binary the only place where ffmpeg is actually properly looking for those templates is

%HOME%/.ffmpeg

To that end I've created the following batch script and copied the ffmpeg's x264 templates to a subfolder .ffmpeg where my ffmpeg binary lives:
@echo off
SETLOCAL
SET HOME=%~d0/
ffmpeg.exe %*
ENDLOCAL

And that's it! Now ffmpeg thinks that the home folder is where it lives and I don't have to pollute my home folder with stuff that doesn't belong there.

You can download the latest FFMPEG binaries from here (you want the "static" version for this setup).

Have fun!