#!/usr/bin/perl use strict; use warnings; use SOAP::Lite trace => [qw(debug)], on_fault => \&_handle_fault; import SOAP::Data 'name'; use HTTP::Cookies; my $COOKIE_FILE = '/tmp/bs-wsdl-cookies.txt'; my $WSDL_FILE = 'file:///tmp/bricolage-simpletest.wsdl'; main(); exit; sub main { my $client = SOAP::Lite->service($WSDL_FILE); # xxx: I have no idea what magic is done # to initialize things (transport), # so I end up calling login a 2nd time just to add the cookie_jar! # $client->login(name(username => 'admin'), # name(password => 'change me now!')); $client->login('admin', 'change me now!'); my $cookie_jar = HTTP::Cookies->new(ignore_discard => 1, file => $COOKIE_FILE, autosave=>1); $client->transport->cookie_jar($cookie_jar); # xxx: 2nd login # $client->login(name(username => 'admin'), # name(password => 'change me now!')), $/; $client->login('admin', 'change me now!'); # .... } # handle faults from SOAP::Lite's on_fault event sub _handle_fault { my ($soap, $r) = @_; # print out the error as appropriate if (ref $r) { if ($r->faultstring eq 'Application error' and ref $r->faultdetail and ref $r->faultdetail eq 'HASH' ) { # this is a bric exception, the interesting stuff is in detail print STDERR "Call failed:\n\n", join("\n", values %{$r->faultdetail}), $/, $/; } else { print STDERR "Call failed:\n\n", $r->faultstring, $/, $/; } print STDERR "Check the Apache error log for more detail.\n"; } else { print STDERR "TRANSPORT ERROR: ", $soap->transport->status, "\n"; print STDERR "Check the Apache error log for more information.\n"; } return SOAP::SOM->new(); }