March 21st, 2006

duke-muscle

Okay, let's talk tech

I completed my "second" AJAX project today, although really my first project is still only mostly-done. So this is actually the second, but the first to go into QA.

It's a nifty little app.

See, our web server is required to have a 60 minute timeout. Sometimes users will be taking a call, an affidavit, and they'll be talking and writing in the NOTES app for more than 60 minutes. They're typing, but they're not making any web server calls. So essentially the web server doesn't know they're still working.

Suddenly, much to their horror, a "the server timed out" popup box appears. When they click OK, they are logged out of the system and they lose all their notes.

It sucks, as you can imagine. They can't periodically save their note, because for legal reasons no note can be edited, and it can only be saved when it is complete. For the same legality, we really shouldn't save auto-drafts... although we may revisit that idea later on.

The solution is simple. A javascript timer. 5 minutes before they'll time out, a popup appears. "Are you still using this thing?" If the user clicks OK, an XMLHttpRequest calls and "pings" the server. (XMLHttpRequest, that's really all that Ajax is. The rest is javascript, smoke, and mirrors.)

Why do we use Ajax? A "regular" action won't work, because we don't want the user to switch or refresh screens. We just want to tell the server that we're still using it.

Anyway my server ping is a Struts action. It supplies a short XML file into the response's OutputStream then returns null. (Interesting side note: just calling an action wasn't sufficient. I had to actually put something into the HttpServletResponse to get this to work consistently.

There is no need to return an ActionForward, because Ajax just want to update a piece of an existing web page, not go to a new one. (There is even a nice 2-part JUnit test around this action, although I confess I didn't write it first.)

The last bit is javascript, which processes the server's response. It checks the XML data. Does it contain what it expected? Then all is well, and the user can get back to work.

If the XML data does NOT contain what we were looking for, then the server really did timeout. The user walked away, had another window on top, was at lunch, whatever -- they didn't click OK within the required 5 minutes. So we pop up an apologetic message, log them out, and send them back to the login screen.

Short and sweet! There are fancier solutions out there, but I think this minimal one will take care of things for now. (I can provide code samples to the curious reader, if this quick summary interested anyone.)

Sometimes I wonder if I shouldn't make myself a techie blog, to keep track of random little projects like this....
  • Current Music
    Michael Penn - romeo In Black Jeans
duke-angry

Stupid Stupid UPS

Well, the note on my door yesterday said they'd try one final time today, after 5pm. I'm supposed to work until 7, but I figured I could slip out early and work from home for the final couple of hours. So at 4:40, I said my goodbyes and jumped into my car.

(The note also said I could change today's delivery location if I wanted to, but only if I did it before 7pm. Of course, I didn't get the note until almost 8.... Also, I've had problems having packages delivered to my office in the past.)

I really wanted my package! I knew I-75 would be congested, so I took side roads all the way home. I was hurrying but not excessively so. I kept my eye on the clock, and I knew I'd make it with minutes to spare.

Well as I pulled into the driveway, I could see a UPS note stuck to my door, fluttering in the breeze. A little part of me exploded. "It's only 4:57!", I yelled at the clock.

Taking an idea from niiicolaaa, I slammed my car into reverse and roared back out of the driveway. I was going to find that truck, and they were going to give me my damn package. Eyes wild, nostrils flared, and lips thinned with rage, I started tearing up and down the side-streets. I'd slow at each intersection, my eyes eagerly sweeping the roads for a brown truck.

Nothing. Nowhere.

I was a woman out for blood, but there was no enemy to be found. Slowly my face relaxed and my anger gave way to sadness. Why couldn't I have my package? Where were they? Finally I gave up, and my car and I trudged dejectedly home.

I went to the tracking website, and it said they attempted to deliver at 1:58pm. One fifty-eight! Now why would they tell me it will be delivered after 5, if they're going to come before 2? That's not even close!

I rushed home from work early for this? No wonder I couldn't find the truck anywhere; it came by hours ago. They're probably somewhere drinking lattes and laughing at me this very minute.

Lying bastards.

I've told the website that I'd like to go pick it up this evening, and it says that it will be calling me soon with details on how that will work. We'll see if it's actually successful or not.... I have my doubts. Stupid UPS. Stupid Amazon. GRRRR!