Horrendous J2EE App



  • I am currently working on a project for a big mobile phone operator in the UK. They use a J2EE application on their site to handle customer registration. I think it was developed in-house a few years back (maybe 2001? - I don't know, we don't have the history of it - I work for an IT consultancy, and we're now responsible for the maintenance of the app). It uses JSP, Servlets, and EJB 2.

    Posting up code probably isn't going to do it justice, it's probably best to just explain a few things about the app. So, in no particular order:

    • It's been edited hundreds of times over the years, you know how requirements change. Unfortunately, nobody bothered to clean out any of the old code. Ever. There are JSPs galore and no-one has a clue what they do or why they're there.
    • There are no test scripts, JUnit tests, anything.
    • There is no documentation on the design (as you would expect); there is also no documentation on the purpose of the functionality apart from the comments in the code.
    • Instead of using a pre-existing framework, the original designers decided to write their own (depending on when the app was written, there might not have been many existing frameworks so this might not be a big WTF),
    • Due to writing their own framework, validation is a little 'iffy'. There is no server-side validation: it's all done using JavaScript. If someone had JavaScript disabled, they'd be able to bypass all validation. But that's OK, because the site doesn't work with JavaScript disabled anyway.
    • They decided to go with the 'Extended Front-Controller Servlet' design pattern. This is a little-known pattern - it can be best summed up like this: "The entire 'Controller' layer of your application should be written in one gigantic, 10,000-line servlet"...

    Picking out the worst bits from a 10,000 line servlet is a tricky job. To be honest, the individual parts aren't that bad (it's not that kind of WTF) - it's just the whole thing added up makes one bit WTF.

     Here's a sample, though, of how the routing works. This is one big method at the top of the servlet which dispatches the request to the various methods which handle... lots of different things.

    private void chooseActionRoute(HttpServletRequest request, HttpServletResponse response, String method) 
    throws ServletException, IOException
    {
      String reqURI = request.getRequestURI();
    

    ...

    final char ACTION_SOMETHING = 'S';
    // ... (40 or so "final char" declarations) ...

    char reqInd = ACTION_INVALID;

    if (reqURI.endsWith(REQ_SOMETHING))
    {
    reqInd = ACTION_SOMETHING;
    }
    // ... 40 or so similar "if" statements ...

    switch (reqInd)
    {
    case ACTION_SOMETHING:
    doActionSomething(request, response, method...);
    break;
    // ... 40 or so more case statements...
    }
    }



  • 10,000 line servlet... I hope you don't have to open that up in RAD.



  • This wouldn't happen to be T-mobile, would it?

    Because I've just been through hell trying to get into my account (still haven't managed it)... 


Log in to reply