Sunday, August 21, 2011

Tip: The JSP surgery

So, you've invested a whole lotta love and money in your java based web server.
And it's fine. Really.
But now it's time for an overhaul. The UI is dated, and you want to bring some fireworks back.
The problem - Your team has changed, it's been a while, and all your team has done so far were some bug fixes and some features. And the web layer is written in good ol' jsp - No one really knows how to rewrite it. Recently I've encountered a similar project - All the team left, the design was terrible, but I couldn't make changes to the back-end, only the jsp files.

What do you do?
My suggestion is to divide and conquer!

Here's a quick recipe on how to transform your server script code into a web service.

First off, see which data you need the server to really generate. Usually, it would be user details, a data table, plus some attributes.
After that, have your jsp code generate JSONs instead of html or javascript code.
This shouldn't be that hard.
Analyze all your code, and prepare new jsp files for each type of data needed. Use the current jsp function calls - There's no need to rewrite the java layer: All these files should do is write a JSON response. You can use Arrays.toString(), or a JSONArray, or you can generate the JSON explicitly from object attributes.


Then you can begin writing your client from scratch, and use these jsp as a web service. You may later write some Java servlets to replace them, or (Better off) use jax-rs to completely get rid of the jsp.
Step by step, you'll see your web application transform into something a lot more comfortable to use and maintain. A real web service, without rewriting your back-end. And when you do get the time to update your server, you'll be able to do it with only minor client modifications.

Have a good development week, and stay tuned for more!
y.

1 comment:

  1. Don't forget that there's also an amazing performance enhancement in these changes!! I would put more focus on the jax-rs area. I mean you make it sound like it's "a nice to have" thing and not a "have to" thing. Getting rid of the JSP code is priceless :-)

    Send this post to Alon and Michal :-)

    ReplyDelete