/ Published in: Perl
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/perl -w use SOAP::Lite; use CGI; use SoapAccess; use strict; use Data::Dumper; main(); sub main { my ($soap_res, $res); my ($element, $key, $count); my ($reqrv, $reqres, $rv, $result, $function, %resultH, @params); my $type = 1; # ********************************** # URI = "urn:adminTool" # ********************************* # my $SOAP_SERVER = "partnertest.hk1.outblaze.com"; my $SOAP_SERVER = "stagerm.outblaze.com"; # my $SOAP_SERVER = "resellertool1.hk1.outblaze.com"; # my $SOAP_SERVER = "rm.cl.outblaze.com"; # my $SOAP_SERVER = "devrm.outblaze.com"; # my $SOAP_SERVER = "reseller3.us4.outblaze.com"; # my $SOAP_SERVER = "rm.hk2.outblaze.com"; # my $SOAP_SERVER = "rm.us4.outblaze.com"; my $SOAP_PROXY = "http://$SOAP_SERVER/ob/servlet/rpcrouter"; my $URI = "urn:adminTool"; $function = "getCobrandServerInterface"; unless ($function) { } my $soap = new SoapAccess($URI, $SOAP_PROXY); ($type == 1) and ($reqrv, $reqres, $rv, $res, $result) = $soap->request($function, \@params); ($type == 2) and ($reqrv, $reqres, $rv, $res, %resultH) = $soap->request($function, \@params); #use MIME::Base64 qw(encode_base64 decode_base64); #my $a = $$rv{3711637}->{comment}; #print decode_base64($a); #print $a; ($type == 1) if ($type == 2) { } } } ## ### ### the definition of the package #### ### ### # # Class stored function simplifing access to SOAP # package SoapAccess; use strict; use SOAP::Lite; use HTTP::Cookies; use Data::Dumper; # # Constructor # # ********************** # Parameters : $uri, string, soap uri to the remote machine # $proxy, string, url to call the soap request # $timeout, integer, number of second for the soap transport timeout (Default : 30) # $retry, integer, number of of times to retries for soap call failure (Default : 3) # Return : the object # sub new { my ($class, $uri, $proxy,$proxy_second, $timeout, $retry) = @_; my $self = { "uri" => $uri, "proxy" => $proxy, "timeout" => $timeout || 40, # default timout 30 seconds "retry" => $retry || 1 , # default retry 3 times "proxy_second" => $proxy_second , }; # Init the soap object eval { $self->{soapobj} = SOAP::Lite ->uri($self->{uri}) ->proxy($self->{proxy}, cookie_jar => HTTP::Cookies->new(), timeout=>($self->{timeout})) }; if ($@) { } unless ($self->{soapobj}) { } } # # submite the request # # ********************* # Parameters : $function, string, name of the function you would call # @params, array, list of data you would pass to the function # Return : boolean, indicate if the call completed ok # string, description of what happened # array, list of data returned from the call # sub request { my ($self, $function, $params) = @_; my ($result); # setup init values my $soapobj = $self->{soapobj}; my $retry = $self->{retry}; while ($retry) { eval { $result = $soapobj->$function(@$params); }; # If result is good, terminate the call, otherwise, do another try }; eval { $self->{soapobj_second} = SOAP::Lite ->uri($self->{uri}) ->proxy($self->{proxy_second}, cookie_jar => HTTP::Cookies->new(), timeout=>($self->{timeout})) }; if ($@) { } $soapobj = $self->{soapobj_second} ; $retry = $self->{retry}; while ($retry) { eval { $result = $soapobj->$function(@$params); }; } ; if ($@) { } else { } else { } } } } } 1; ~