I’ve been tooling around writing a SOAP client that meets my needs of being simple to use and easy to work with (which for me means no generated classes). At the same time I decided to take a look into STaX parsing. All is going swimmingly using the reference implementation until I need to get the current namespace context from a start event. It comes back null (according to the documents the worst it should be is empty).
Okay I think, well this is StAX and there are a good number of implementations around. I’ll just grab one of those.
The first place I tried was codehaus as the reference implementation now lives there and probably has an update or two. Yep there’s an update version 1.1.1-dev. Switch jars fire the test up. The 1.1.1-dev implementation dies in the same manner as the 1.0 implementation (null returned from getNamespaceContext()).
Being at codehaus I thought I’d try their other StAX parser Woodstox. As version 2.0 is at release candidate status I thought I’d give it a shot first. Nope, peek() on the reader returns information for the current event (i.e. the one I have just consumed) rather than the next event. I use peek a lot so needless to say my code doesn’t work. Okay, well it is only rc-1 so I forgive them and give version 1.0.6 a shot. Nope, now an earlier test that calls a writer dies with namespace declaration problems. Bum, ah well I’m pretty sure Sun have a shiny new implementation in the updated web services pack.
Okay, download, run shell script, install a bunch of stuff I’m really not interested in. Ah finally. I add the link to sjsxp.jar to my environment and away we go. Nope, nextTag().asStartTag() returns an error indicating that we are not on a tag event (the event is a StartTagEvent object btw). Knowing better than to try and figure out issues in suns j2ee stack (I’ve had to use sun one application server and no amount of logic will help you find the problems), I give up on it.
Now I believe that Oracle and Bea both have StAX implementations though from reading their websites and forums it looks as though they both have requirements based on their deployment environments. So that leaves me in the unfortunate position of not being able to use any of the implementation I’ve tried without issues. For now I’ll ignore the problem (I’ll return the value as a string rather than a QName) and keep an eye out for updates.
May 31st, 2005 at 6:56 am
Log a bug and we will fix getNamespaceContext() returning null but we need to know how to reproduce it …
http://www.extreme.indiana.edu/bugzilla/buglist.cgi?product=STAX
thanks,
alek
May 31st, 2005 at 1:24 pm
Logged a bug (http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=227) with an attched test case.
June 7th, 2005 at 12:40 am
regarding the StAX API:
is it a bit silly that there is a peek() to preview nextEvent()
but no such thing as “peekTag()” to preview nextTag()?
June 7th, 2005 at 1:39 am
One additional comment: it would be good if you could also inform Woodstox author (me…
) about the problem (cowtowncoder@yahoo.com). It’s much easier to fix problems one is aware of, and this one I hadn’t heard about before. I will definitely have a look.
This (eventReader.peek()) is one feature that apparently few developers have used, ie. bug hasn’t ever been reported. Most people do not make use of the event API (I think), so it is possible there are bugs on that side. Further, I can then add a new unit test on StaxTest side to catch this problem for all implementations that regularly check against StaxTest (Woodstox is fully compliant with its 100+ tests).
June 7th, 2005 at 3:12 pm
I kept meaning to write a test and file a bug … time … time … time :S
December 21st, 2005 at 2:57 pm
Ok. this was a while back, but for what it’s worth, the bug in Woodstox was reproduced and fixed a month ago or so (2.0.4 has the fix for sure — and 2.0 is now the stable branch). The problem only occured under specific circumstances (which made tracking it down harder), but now should work ok.
Also, Sun has released their Stax parser, SJSXP (aka “Zephyr”)… and it looks like it’s quite good quality from what I have seen (worthy competitor for Woodstox.
).