Monday 8 September 2008

On using the BeanShell for system introspection

At work I came across the BeanShell
and its remote server mode.

From a server application you can invoke the command

server(1234);

in a beanshell which starts a tiny HTTP server on port 1234 and a telnet session server on port 1235.
When your server at port 1234 is then accessed via HTTP you get a page containing
an applet containing a JConsole. This applet communicates with the telnet session server.

We ignored the warning about the unrestricted access to all parts of the application
and used the applet in production.

And this helped us to analyze problems we would never have been able to solve
without the remote beanshell. Before we only had logs or beans accessible via JMX.
But these information was fixed after we inserted the log statements or defined
the managed beans.
The remote beanshell allowed us to look into any object which was reachable from
one given entry point object which we set into the beanshell interpreter at startup.

We were even able to call methods on these objects to fix states we did not expect
before to happen.

One disadvantage was that the remote server was not running under the standard port 8080.
Firewall issues prevented us from accessing the remote beanshell from our workstations.
We therefore had to login to our production (windows!) web servers, start a browser there
and call the remote beanshell.

I therefore implemented a servlet providing an Interpreter instance hold in the session.
The code can be checked out via anonymous svn from
http://subversion.banapple.de/public/beanshell-extensions/

The homepage is http://www.banapple.de/beanshell-extensions/index.html.

No comments: