beanshell: scripting for java

Ok, I never really liked java – as I think it moves problem from developers to sysadmin 😉 but I have to say that there are very nice java things: beanshell is one of this.

The problem I face was the post-processing of funambol output to a mobile device, shortly I had to filter an xml (syncml) response, regexp-replacing some values if the client was a Nokia mobile.

Doing it in the webapp code was ugly and leaves the webapp jars Nokia-dependant 🙁
So I decided to look at synclets (the way as Funambol uses beanshell for this kind of job) and quick-and-dirty write those lines.

What’s a synclet?
1- Funambol extends BeanShell with BeanShellSynclet
2- a BeanShellSynclet is a java-bean (an object), configured by an xml file
3- the xml refers to a .bsh file which includes methods and attributes written in java
4- the xml contains a User-Agent string

How Funambol use Synclets
Synclets are used when a User-Agent connects to the server (ex. a Nokia Mobile)
1- Funambol stores synclet’s XMLs configuration files in a proper directory
2- create a synclet object for each configuration file whose matches the User-Agent connected
3- before passing syncml streams to clients, parse it with all those synclets

Advantages
1- your webapp code is clear and rfc-compliant
2- writing synclet is easy
3- synclets applies only to the right User-Agent
4- you don’t have to re-deploy webapps, as synclets are instantiate at runtime

Have your say & Peace,
Rob

Lascia un commento