martes, 14 de agosto de 2012

Complex types & Cloud connectors with Mule ESB

Hi there, have you ever worked with Mule ESB?

Quite nice, free and open source ESB that you should really check!

Now they have this concept of CloudConnector, which is basically an easy plug and play way to make you ESB talk to other service's API. Here is a list of all of them as of today.

Now this post is not about how to use nor create a  CloudConnector. This is just a short post about how to deal with a  CloudConnector when its methods returns Complex Types.

A Complex Type it's nothing else than a POJO, BUT the fact that it's a POJO make it some how a little more complex to use it the first time.

Why????

Well because the output of any call to a  CloudConnector it's something that you can not use out of the box just because you don't know what does it expose, I mean the getters of the object.
And the problem here is that when you are modifying a Mule configuration file (which is the way to program Mule ESB) there is no autocomplete like in Eclipse to help you.


So, now that I've stablished the problem I shall offer you the solution.
Mule ESB has native support for Groovy scripts, which allows you to access any object.

So let's take for instance a call to the LinkedIn Cloud Connector they offer:


<linkedin:get-profile-for-current-user config-ref="LinkedinConf"/>

When set up properly this should return you data from the profile of the currenent user. And it does but it does so by returning a POJO.
So if you want any useful information from it you should access its getter methods. BUT WAIT I DON'T KNOW THE CODE OF IT, even more important I don't have it.

And that's where Groovy comes in handy, for this will tell you what you can ask for this POJO returned:

<linkedin:get-profile-for-current-user config-ref="LinkedinConf"/>
<logger message="#[groovy:payload.getClass().getDeclaredMethods().toString()]" level="INFO" doc:name="Logger"/>


When put together this to tags in you Mule config file you'll be able to check all the methods exposed by this POJO and hopefully find something you can use.

Of course this is nothing more than the use of java reflection but for a newbie in both Java and Mule ESB this post my help you.


So that's it, have fun.

No hay comentarios:

Publicar un comentario