13 June 2007

The JAXP hits!!--More--

I had a spare moment, so I thought I'd shoot myself in the foot. Well, the shooting was unintentional, but it happens so often under these circumstances, you'd think I'd have figured out when to flinch by now.

Standard near-end-of-project clean-up, replacing any remaining "err.printStackTrace()" calls with proper logging statements and other tidying-up. I had in my notes "Add input XML validation". We hadn't had any problems with XML formatting before, but it seemed like a good thing to have when we went into production (can you hear the warning siren going off?). So I cons up a quick XMLValidator class with an inputIsValid() method and get that working. Plug it into the project and test all the various inputs we have, everything is happy, so I deploy it to our test server and have our external development partner have a go at it.

On the first run, he reports "Hey, it gives me a validation error." So we check, and sure enough, he's got one of the attributes misspelled. We fix that and re-submit and he gets another one. We check, and find another one. Fix and re-submit, get another validation failure. Only this time, we can't figure out why. The error message he's getting is "cvc-elt.1: Cannot find the definition of 'SchoolInfo'" (which is one of the elements in our schema). We can't find the problem, so I cut the XML from the server log and submit it on my test system where I can step through the validation with the debugger. Lo and behold, no problem! :/

So what's different between dev and test? Same app server, same jar file, whoops! I'm running Java 1.5 on my dev server, but the test server is 1.6 (why?) . Poke around a bit (OK, a lot) and find out that J2SE1.5 uses JAXP 1.3, while 1.6 uses JAXP1.4. Hmmm, so what's the difference? Well, it's not exactly documented anywhere, but when validating under JAXP1.4, you have to explicitly make the DocumentBuilderFactory (from which you create the parser that creates the document that you pass to the validator...) namespace-aware, and tell it that the resulting parser will be used for validation. Which makes sense, I guess, it's just that all this (and so much more!) is included with the JDK, and there's no real migration guide or set of comprehensive release notes that spells out these changes. And let's face it, if there were, it would be so big nobody would read it anyway. It would be nice if they could provide total backwards compatibility, but I know that's not always possible.

I dunno, I finally got Ruby 1.8.5 installed, and got Rails set up, and I'm working through Dave Thomas's Rails book, and I'm finding it's much quicker to develop in Rails than JEE. Of course, I haven't done anything much in Rails yet (and I don't know Ruby at all), but I've got a project that I had to shelve because it was taking too long to write in Java, and I'm going to dust off those notes and see if I can get it done in Ruby. If so, then I may have to roll out some Ruby utilities here at the orifice and see if I can get them entrenched. From what I can see, .NET isn't going to make web development any quicker than JEE, so I might as well push for something that is.

No comments: