Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Afternoon, I'm trying to write a SOAP service to decode a cookie and pass the details in SOAP to a Java client (Perl being better at data munging in this instance). Whilst testing this, I have not been able to print out the results (I've written the client in Perl to test) so that I know this part is working.
#!c:\perl\bin\perl.exe use strict; use warnings; use SOAP::Transport::HTTP; use CGI; use Carp; SOAP::Transport::HTTP::CGI ->dispatch_to('emailfind') ->handle; my $cgi = new CGI; package emailfind; sub findingit { my $cgi = shift; #croak "Error: cgi object not passed" if(!$cgi); my $cookie = $cgi->cookie('WALOGIN'); return if (!$cookie || $cookie eq 'RESET'); #exit function if co +okie empty or is RESET my ($e) = split(/-/, $cookie); my $email= pack("H*",$e); # decode email address return $email; }
I am not quite sure where I've gone wrong on this and would be grateful for some help before moving on any further. Ultimately I'm trying to pass on a username
#!c:\perl\bin\perl.exe use warnings; use SOAP::Lite; my $soap = SOAP::Lite ->uri('http://localhost/emailfind') ->proxy('http://localhost/cgi-bin/soapdish.pl'); unless ($soap->fault) { print $soap->findingit(); } else { print join ', ', $soap->faultcode, $soap->faultstring, $soap->faultdetail; }
Many thanks for any pointers.

Replies are listed 'Best First'.
Re: Creating SOAP client to pass data to Java
by shmem (Chancellor) on Jan 02, 2008 at 21:19 UTC
    After having invoked SOAP::Transport::HTTP::CGI->handle(), all is over. Your CGI initialization doesn't do anything.

    Then, you don't pass a CGI object to your emailfind::findingit method, which is OK, since you won't get a CGI object initialized anyways. Despite the CGI in the name, the SOAP::Transport::HTTP::CGI package doesn't use CGI and munges headers and POST params otherwise ('tis all LWP::* stuff).

    I haven't found a way yet to set a cookie via a SOAP client request, but the following rewrite might take you a bit further.

    Server code:

    #!/usr/bin/perl use SOAP::Transport::HTTP; SOAP::Transport::HTTP::CGI->dispatch_to("emailfind")->handle; package emailfind; use HTTP::Cookies; sub findingit { warn "****** findingit(".join(',',map{"'$_'"}@_).")\n"; my $function = shift; my $cookiejar = shift; die "No cookies" unless $cookiejar; my $cookie = $cookiejar->as_string(); die "no cookie" if (!$cookie || $cookie =~ /WALOGIN="RESET/); #ex +it function if cookie empty or is RESET my ($e) = $cookie =~ /WALOGIN="([^"]+)"/; return $e; }

    Client code:

    #!/usr/bin/perl use warnings; use SOAP::Lite; use HTTP::Cookies; my $cookie = HTTP::Cookies->new(); $cookie->set_cookie(undef,'WALOGIN','foo@bar.com','/','localhost',80,1 +,1,100,0); my $soap = SOAP::Lite -> uri('http://localhost/emailfind') -> proxy( 'http://localhost/cgi-bin/soapdish2.pl', ); my $res = $soap->findingit($cookie); print $res->result,"\n";

    Note that you don't call fault on your $soap object, but on the result object of the SOAP call - otherwise "fault" would be dispatched as a XML RPC call to the soap server.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Thanks for this Shmem, I'll keep working on it once I've got past the failed access to the class error which trace is bringing up.