Monday, April 30, 2007

webservice pain

I wish I could proudly announce that I have a slick new webservice for my Google Translator ready for public consumption. It's been almost a month since I started working on the thing in my free time. This should have been a relatively straight-forward project to implement, but alas, it's been hell every step of the way. SOAP is hard and ugly, and plenty of people warned me about it before I even started. "Use REST!!", they proclaimed, and now I can see why.

I started off on my journey with the intention of making a nice POJO backed JSR-109 style webservice. The SEI was fairly trivial, and it works much like the RMI version that I did earlier. Once you have your interface done, there isn't any more coding to do, it's all xml wiring, mapping, and magic. Which is far nastier than it should be.

My first mistake was trying to attack the problem in a generic way. Before you get started on a webservice, know what your target platform is and read the container specific documentation/examples. My target platform is jBoss 4.0.5. I would have saved myself a great deal of time and pain if I had started off on with the jBossWS examples.

The reason your platform choice is so important is because of the tooling. Your platform will most likely provide some set of tools for generating all the nasty XML files that JSR-109 demands (jax-rpc mapping, WSDL, etc). jBossWS comes with a little tool called wstool which takes a pretty simple xml config file and then spits out all the ugly XML files that you need for your webservice. Having to generate these files by hand would give you nightmares, so good tooling is essential. I also had to download and use the now out of date JWSDP-2.0 for several things, including wscompile (more tooling).

Once all that was done, everything worked, well almost. As long as no non-latin character encodings were involved, everything was just peachy. If, however, I want to translate English to Russian, and get UTF-8 Cyrillic returned to me, things don't work so well. Somewhere inside the jBossWS code, it's mangling up my result string, and that's going to take some poking around. Hopefully I'll figure everything out and get the thing to behave correctly.

So, maybe next month?

No comments:

Post a Comment