September 28, 2004

Deserializing Java Vectors with SOAP::Lite

I'm seriously using SOAP for the first time and came to a stumbling block. I'm testing a SOAP interface to a Java middle tier with SOAP::Lite since it's supposed to be available from different environments/languages. But one of the methods I'm calling has the signature:

    public Vector fetchAllThingies()...

It's really just an array so it should be a piece of cake, right? Nope. SOAP::Lite doesn't seem to support multiple return values, or a single return value representing multiple objects. Everything seems to work, but if you ask for the result you only get the last item.

After floundering for a bit I found a soaplite mailing list post from Paul that basically said, "Yeah, we don't do that, but here's another way." Using that you should be able to get into a Vector of simple hashtables (probably Objects too, haven't tested yet) with this not-necessarily-definitive fix:

my $result = SOAP::Lite->new()
    ->uri( 'urn:SomeThingies' )
    ->proxy( 'http://somehost/SOAP' )
    ->fetchAllThingies();
   
# '//return/item' is an XPath expression...
my @thingies = $result->valueof( '//return/item' );
   
foreach my $thingy ( @thingies ) {
    # $thingy isa hashref with keys/values as you'd expect
}

We'll see what more fun awaits... but a positive benefit of being exposed to SOAP is that I'll understand how this OpenInteract2 handler works and hopefully put it in the next version.

Next: New-ish blog: James Walcott
Previous: Average speeds in traffic.com feeds