2
use strict;use warnings;
4
use OpenILS::Utils::Config;
5
use OpenILS::DomainObject::oilsMethod;
6
use OpenILS::DomainObject::oilsPrimitive;
7
use OpenILS::EX qw/:try/;
11
# ----------------------------------------------------------------------------------------
12
# This script makes a single query, 1 + 2, to the the MATH test app and prints the result
13
# Usage: % perl math_simple.pl
14
# ----------------------------------------------------------------------------------------
17
# connect to the transport (jabber) server
18
OpenILS::System->bootstrap_client();
20
# build the AppSession object.
21
my $session = OpenILS::AppSession->create(
22
"math", username => 'math_bench', secret => '12345' );
26
# Connect to the MATH server
27
if( ! ($session->connect()) ) { die "Connect timed out\n"; }
29
} catch OpenILS::EX with {
31
die "* * Connection Failed with:\n$e";
34
my $method = OpenILS::DomainObject::oilsMethod->new( method => "add" );
35
$method->params( 1, 2 );
41
$req = $session->request( $method );
43
# we know that this request only has a single reply
44
# if your expecting a 'stream' of results, you can
45
# do: while( $resp = $req->recv( timeout => 10 ) ) {}
46
$resp = $req->recv( timeout => 10 );
48
} catch OpenILS::EX with {
50
# Any transport layer or server problems will launch an exception
52
die "ERROR Receiving\n $e";
56
# something just died somethere
58
die "Caught unknown error: $e";
62
# ----------------------------------------------------------------------------------------
63
# $resp is an OpenILS::DomainObject::oilsResponse object. $resp->content() returns whatever
64
# data the object has. If the server returns an exception that we're meant to see, then
65
# the data will be an exception object. In this case, barring any exception, we know that
66
# the data is an OpenILS::DomainObject::oilsScalar object which has a value() method
67
# that returns a perl scalar. For us, that scalar is just a number.
68
# ----------------------------------------------------------------------------------------
70
if( UNIVERSAL::isa( $resp, "OpenILS::EX" ) ) {
74
my $ret = $resp->content();
75
print "Should print 3 => " . $ret->value() . "\n";
78
die "No Response from Server!\n";
83
# disconnect from the MATH server