What I Don’t Like About the Java Plugin

Why can’t the Java Plugin on Windows unload itself after you leave a page with a (stupid) applet on it, or after X amount of inactivity? I generally despise applets, but sometimes I have to use them, such as the one on the WebLogic console. What I really hate is pages that have an applet just for ad rotation. I have no problem with sites having ads, but loading up the Java VM (no small amount of RAM there) just to rotate ads bothers me.

But anyway, if they won’t do an auto-unload feature, at least give me the option of killing it via the Windows systray? (I am pretty sure that on Linux systems the plugin doesn’t hang around, but I could be wrong.)

How hard is that?

It’s Dead, Jim

I’m working with some Java wrappers for some CICS programs on our mainframe. I’ve been having a devil of a time getting the thing to work properly. In typical mainframe fashion, when it fails you get an ABEND and then some less-than-useful messages. Dig the one that I just got:

ECI_ERR_CICS_DIED

At least it was honest…

OK, Maven is Cool

I installed Maven tonight and within about 20 minutes had one of my simple projects building with it. Once I create the project.xml file, running maven java:jar fetched, compiled and jarred everything into a ready-to-use jar file. Running maven site:generate generated an entire project website including developer information, code metrics and other useful stuff. Very nice indeed. And this after spending less than half an hour with it!

“Weird” Error Messages

Whilst trying to use the nifty management console included with JRockit (supposedly the world’s fastest JVM), I recieved this error

COM.jrockit.common.util.AssertionFailedException: Received a weird y = 114 or weird time = 1041533639613 class = com.jrockit.console.ui.chart.DataSourceMemoryHeap

That’s the first time I’ve ever been told by a machine that something was “weird.”

Maven and Eclipse

I got this from James Strachan‘s blog. It’s about how you can have Maven generate the .project and .classpath files in order to have Eclipse auto-grok your project!

You can define this property a local build.properties, in the build.properties in your home directory or on the command line via -DpropertyName=value in the following command.

Then to update your eclipse installation so that its aware of the Maven repository, type the following.

maven eclipse:add-maven-repo

Now once you’ve configured your Eclipse installation, you can just cd into any of your maven-enabled projects directories and type

maven eclipse

and Maven will create a .project and .classpath for you!

Here‘s the full article. I’m a huge fan of Eclipse, and as I said before Maven was something I’d been meaning to look into. This adds another reason to look at it.

Cool Use of Jython

I just had to share this. I am working on a very large project using BEA‘s WebLogic 7. This project takes a good 10 minutes to go through an entire compile/deploy cycle. This is a real hassle when I need to noodle something out, test some idea, etc. I use Jython for all manner of nifty things including testing things from the client side of my app, but what if I wanted to test something from within the container? Sure I could write a Cactus test (and I have written many), but adding/changing a Cactus test results in a compile/deploy cycle. What I needed was something better.

What I came up with is a truly (dirty) hack that is totally insecure yet really useful. (IOW, don’t put it on a production server.)

I embeded a Jython interpreter inside an Apache Axis web service. I then have a short Jython script on the client side that sends an arbitraty script to the server, which is executed and then the stdout/stderr are bundled up and sent back in the SOAP response. I think this is really cool.

The files involved are

The web service is where the real work occurs, but it’s brain-dead simple. Here’s JythonWebService

package com.joeygibson.soap;

import java.io.StringWriter;

import org.python.util.PythonInterpreter;
import org.python.core.*;

public class JythonWebService
{
    private PythonInterpreter interp =
        new PythonInterpreter();
    Writer out = new StringWriter();
    Writer err = new StringWriter();

    public JythonWebService()
    {
        super();

        interp.setOut(out);
        interp.setErr(err);
    }

    public String exec(String script)
    {
        interp.exec(script);

        StringBuffer results =
            new StringBuffer(
                "----- StdOut -----nn");
        results.append(out.toString());
        results.append(
            "nn----- StdErr -----nn");
        results.append(err.toString());

        return results.toString();
    }
}

Simple, eh? We create the Jython interpreter and then give it two StringWriters that will capture stdout and stderr, respectively. Then in the exec method we accept the script from the SOAP envelope, let the interpreter execute it, and then bundle up the stdout and stderr with nice little markers to differentiate them. That then goes back over the wire to the caller.

Next is remote.py that executes the service from the client side.

import string, sys
from java.io import *
from org.apache.axis import *
from org.apache.axis.client import *
from javax.xml.namespace import QName

global service, call

service = Service()
call = service.createCall()
call.setTargetEndpointAddress(
    "http://localhost:7001/ivr/services/AxisServlet")
call.setOperationName(
    QName("JythonWebService", "exec"))

f = open(sys.argv[1])
scriptLines = f.readlines()
f.close()

script = string.join(scriptLines, "")

ret = call.invoke([script])
print ret

Here we first import the necessary packages/classes from both Java and Jython. We then create the Axis Service and Call objects, setting the endpoint and operation name on the call. Next we load up the specifed file (this could easily be changed to support multiple scripts from the command line), concatenate each line into one big string, and then execute the web service. The script is then passed as the sole argument (wrapped in an array) to the exec method of Call, which executes the remote call. Finally the result is printed.

Next in line is remote.bat the batch file I used to execute the client. It just sets up a reasonable classpath and then invokes Jython.

@ECHO OFF
setlocal

set CLASSPATH=<jars from the axis/lib directory>
call jython remote.py %*

This adds all the jar files in the axis/lib directory to the classpath and then runs our remote.py script through Jython. You may have to get creative with how you set your classpath. I use 4NT as my command prompt, which has much longer command line allowances. The setting of the classpath can be a pretty long string and CMD.exe may barf on it. YMMV.

Finally we need to test something. Here’s test.py that will run on the server via our web service

from javax.naming import *

ic = InitialContext()
vv = ic.lookup("ejb/VVLookup").create()
l = vv.getValidValuesForFieldNumber(1558)

for i in l: print i

Obviosly you would have to tailor this for your setup since it’s doubtful that you have a stateless session bean deployed at ejb/VVLookup… Anyway, you can see that I create an InitialContext (with no parameters since we’re inside the container) do a lookup, execute a method that returns a collection and then iterate over it, printing them out. Since print goes to stdout, the output will be captured and then returned to the client.

That’s it! If anyone want’s a copy, let me know. It’s so simple, though, that you could just do it yourself.

Googling From Blosxom

I’ve made a few changes to my copy of Blosxom to add the little “Google” link you see at the end of this entry. I’ve seen this on other blogs here and there so I decided to add it to mine. It consists of a subroutine called buildGoogle that takes the second line of each story file and builds the Google URL with the query string built from your keywords. The second line of the file will only be used as keywords if the line starts with KW:. If it starts with anything other than that, it will be included as part of the body. For example, a file with this

KW: blosxom perl blog

as its second line will produce this

 | Google

To include the link itself in your stories, edit your story.html and add $google wherever you want the link to show up. If the link was not built because you didn’t have a KW: line, then nothing will show up. This is from my story.html. Notice it comes right after code creating the perma-link.

 #$google 

Here is the patch if you would like to use it.

Anyone Using Komodo?

I’ve seen this IDE from ActiveState for a while now called Komodo. Is anyone using it? It looks pretty nice. Quite a bit nicer than it did about a year or so ago when I first saw it. Can anyone recommend a better Perl/Python/Ruby editor? I’m looking at the latest pre-release of FreeRIDE which will be a very nice editor when it’s finished. If you are into Ruby you should give FreeRIDE a try. The 0.5.0 release candidate came out today.

WebWork and Maven

You know how you’ve never heard of something and then over a short period of time you see or hear references to that thing you’ve never heard of and you start to get the feeling that it’s something you should look at? I’m having that feeling about two things right now. One is Maven from the great folks at the Apache Jakarta project. The other is WebWork from OpenSymphony. I know that Maven is some sort of build tool, they refer to it as a “Java project management and project comprehension tool” whatever that means. WebWork is an MVC-ish framework for building websites, similar to Struts from what I can tell.

Over the past several weeks, both of these keep coming up. I need to spend some time investigating.