1 #!/usr/bin/perl
 2 # Name: xmlBlaster/demo/perl/xmlrpc/hello.pl (xmlBlaster.org)
 3 # Invoke
 4 #   perl hello.pl http://myHost:8080/
 5 # if xmlBlaster runs on 'myHost'
 6 
 7 use Frontier::Client;
 8 use MIME::Base64;
 9 #use String::Trim;
10     
11 #$server_url = 'http://MyHost:8080/';
12 $server_url = @ARGV[0];
13 if ($#ARGV == -1) {
14    $host = `uname -n`;
15    $host =~ s/^\s*(.*?)\s*$/$1/; # trim whitespace
16    $server_url = "http://" . $host . ":8080/";  # guess where xmlBlaster is
17 }
18 print "\nTrying to connect to xmlBlaster server on $server_url ...\n";
19 
20 # Make an object to represent the XMLRPC server.
21 $server = Frontier::Client->new(url => $server_url);
22 print "Connected to xmlBlaster server on $server_url \n";
23 
24 # Call the remote server and get our result.
25 $sessionId = $server->call('authenticate.login', "ben", "secret",
26                                                  "<qos></qos>", "");
27 print "Login success, got secret sessionId=$sessionId \n";
28 
29 # Call the server and get its current memory consumption.
30 $queryKey = "<key oid='__cmd:?totalMem'/>";
31 # Call the server and query all messages with XPath:
32 #$queryKey = "<key queryType='XPATH'>/xmlBlaster</key>";
33 
34 @msgUnits = $server->call('xmlBlaster.get', $sessionId, $queryKey, "<qos/>");
35 print "\nResults for a get($queryKey):";
36 for $i (0 .. $#msgUnits) {
37    for $j (0 .. $#{$msgUnits[$i]}) {
38       print "\n-------------#$j-------------------";
39       $key = $msgUnits[$i][$j][0];
40       $contentBase64AndEncoded = $msgUnits[$i][$j][1];
41       $content = decode_base64($contentBase64AndEncoded->value());
42       $qos = $msgUnits[$i][$j][2];
43       print $key;
44       print "\n<content>" . $content . "</content>\n";
45       print $qos;
46       print "\n-------------#$j-------------------\n";
47    }
48 }
49 
50 # Try publishing a message:
51 $returnQos = $server->call('xmlBlaster.publish', $sessionId,
52                            "<key oid='MyMessage'></key>",
53                            "Hello world", "<qos><forceUpdate /></qos>");
54 print "\nResult for a publish():\n------------", $returnQos, "\n------------\n";
55 
56 
57 # Logout from xmlBlaster
58 $server->call('authenticate.logout', $sessionId);
59 print "\nLogout done, bye.\n";


syntax highlighted by Code2HTML, v. 0.9.1