1 package OpenSRF::Application::Demo::Math;
2 use base qw/OpenSRF::Application/;
3 use OpenSRF::Application;
4 use OpenSRF::Utils::Logger qw/:level/;
5 use OpenSRF::DomainObject::oilsResponse;
6 use OpenSRF::DomainObject::oilsPrimitive;
7 use OpenSRF::EX qw/:try/;
13 our $log = 'OpenSRF::Utils::Logger';
17 # my( $class, $method_name, $method_proto ) = @_;
19 # if( $method_name eq "add" ) {
23 # if( $method_name eq "sub" ) {
27 # if( $method_name eq "mult" ) {
31 # if( $method_name eq "div" ) {
41 my $method_name = shift;
44 $log->debug( "Creating a client environment", DEBUG );
45 my $session = OpenSRF::AppSession->create(
46 "dbmath", sysname => 'math', secret => '12345' );
48 $log->debug( "Sending request to math server", INTERNAL );
50 my $method = OpenSRF::DomainObject::oilsMethod->new( method => $method_name );
52 $method->params( @params );
62 my $vv = $session->connect();
65 throw OpenSRF::EX::CRITICAL ("DBMath connect attempt timed out");
69 $req = $session->request( $method );
70 $resp = $req->recv(10);
72 } catch OpenSRF::DomainObject::oilsAuthException with {
77 if ( defined($resp) and $resp and $resp->class->isa('OpenSRF::DomainObject::oilsResult') ){
79 $log->debug( "Math server returned " . $resp->toString(1), INTERNAL );
86 if( $resp ) { $log->debug( "Math received \n".$resp->toString(), ERROR ); }
87 else{ $log->debug( "Math received empty value", ERROR ); }
90 throw OpenSRF::EX::ERROR ("Did not receive expected data from MathDB");
96 sub add_1_action { 1 };
101 return send_request( "add", @args );
104 sub sub_1_action { 1 };
108 return send_request( "sub", @args );
111 sub mult_1_action { 1 };
115 return send_request( "mult", @args );
118 sub div_1_action { 1 };
122 return send_request( "div", @args );