Skip to main content

Way Down the Line

Posted by editor on September 23, 2005 at 5:59 AM PDT

Adding arbitrary web app debug code at runtime

"Debugging" can mean a lot of different things. The classic use case has a developer sitting at his or her machine, using a low-level debugger like jdb or IDE-based equivalents to inspect the state of variables, threads, objects, etc. And that's great. But there's also a sense of debugging involved in seeing a production system misbehaving and trying to find some way of determining what it's doing and why. Particularly with web apps, these situations aren't amenable to hooking up a debugger, because of the remote deployment, the fact that debugging may not be enabled, etc. And that's assuming the problem is amenable to that style of debugging.

Admit it: at least once, you've probably wanted to throw an arbitrary System.out.println() into a remote, running application, if only to start to figure out what the heck's going on. But of course, that means recompiling, restarting, and lots of other impracticalities. What you could really use is a maintenance servlet that would let you get in and do stuff at runtime.

This is Lorenzo Puccetti's line of thinking. In
today's Featured Article,
Dynamic Interaction with Your Web Application, he writes:

The servlet we want to write needs to be able to hook into any resource provided by the web server and allow the user to inspect any part of it. To be able to gather the required information, it might require flow-control constructs and loops. This leads to one solution: to make the servlet able to execute a script sent by the client (i.e., the browser). The script will have not only the ability to access any server resource, but by manipulating host objects representing a HTTP request and response, it will be capable of communicating back to the client.

He goes on to deploy the Rhino JavaScript interpreter behind this servlet, and shows how JavaScript code can access the Java runtime, allowing you to dig into your web application's behavior interactively, sending the results back to your browser.

This is a wide-open technique, which has some obvious benefits and hazards -- check it out, think it over, then let us know what you think in the article comments.

Vikram Goyal continues the cross-blog discussion of employment in Live and let code, featured in today's Weblogs:
"Programmers and Managers have a symbiotic relationship... I don't fully pretend to understand what they do, while they don't pretend to tell me how to code."

Rich Unger shows off A simple NetBeans module, written in NB 5.0:
"As promised, here's a recap of a simple module I built to help me test a bugfix."

Debugging on J2ME/CLDC devices, Oyvind Bakksjo writes:
"Debugging programs running on real J2ME/CLDC devices is hard and frustrating. Some things can be done, though."

The latest Poll asks "What's your highest level of involvement with the JCP?" Cast your vote on the front page, then visit the results page for results and discussion.

In Projects and
the Ninth Jini Community Meeting takes place October 19-20 in Chicago. "The meeting will run for two full days (Wednesday and Thursday) and be filled with a variety of technical, business/marketing, and general sessions." You can also get more info on previous Jini Community Meetings.

The Mac Java Community points out the availability of Apple's Xgrid agent for Java. "The goal of the project is that by using Java a completely cross-platform Xgrid agent can be produced. Using this agent it would be possible to build multiple platform Xgrid clusters that could be used to run any embarrassingly parallel tasks."

In today's Forums,
jeffmutonho worries about
Keeping up
How do you keep up with all the new java technologies that are out so fast?I tried buying books , but end up not even reading half the material because there's too much to learn and so little time...

sbohmann considers the unintended consequences of a proposed feature in
Re: "string" primitive:
"I've always found it the worst of features of C# that I can never be certain whether operator == will compare by reference or value. This forces me to use if ((Object)a == (Object)b) ... on instances of a class I haven't used before or whenever I simply don't remember whether the class had implemented operator ==, or not. It is NEVER about brevity. It is NEVER about beauty. It is always only about clarity. Hitting some more keys on the keyboard doesn't hurt nearly as much as ALWAYS having to think about every single tiny detail, just because there are no consistent mechanics to understand, but merely a lot of possible different ways a type might have been implemented in order to manipulate the language's basic syntax."

In Also in
Java Today
the article Struts-Velocity integration , features Struts Recipes co-author George Franciscus walking you step-by-step through integrating the Velocity Template Engine into your Struts applications. The result is a fast, flexible alternative to JSP, but with all the creature comforts you expect from Struts.

So, you're fixing bugs as fast as you can. Maybe you even have a rational process to prioritize the process. Great. Now when do you stop? In the ONLamp feature, How to Decide What Bugs to Fix When, Part 2, Scott Berkun (author of The Art of Project Management) says "you need to plan out, in advance, how you'll know when you're done. If you don't do this you'll spend hours arguing over whether code is done enough or not. If you're smart, and take the time earlier to define exit criteria, you'll set up your team to spend those hours coding instead of arguing."

In today's
News Headlines

Registered users can submit news items for the href=""> News Page using our
news submission
. All submissions go through an editorial review before being
posted to the site. You can also subscribe to the href=""> News RSS

Current and upcoming Java

Registered users can submit event listings for the href=""> Events Page using our href=""> events submission form.
All submissions go through an editorial review before being posted to the

Archives and Subscriptions: This blog is delivered weekdays as
the Java
Today RSS feed
. Also, once this page is no longer featured as the
front page of it will be
archived along with other past issues in the href=""> Archive.

Adding arbitrary web app debug code at runtime