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';
19 my $method_name = shift;
22 $log->debug( "Creating a client environment", DEBUG );
23 my $session = OpenSRF::AppSession->create(
24 "dbmath", sysname => 'math', secret => '12345' );
26 $log->debug( "Sending request to math server", INTERNAL );
28 my $method = OpenSRF::DomainObject::oilsMethod->new( method => $method_name );
30 $method->params( @params );
40 my $vv = $session->connect();
43 throw OpenSRF::EX::CRITICAL ("DBMath connect attempt timed out");
47 $req = $session->request( $method );
48 $resp = $req->recv(10);
50 } catch OpenSRF::DomainObject::oilsAuthException with {
55 if ( defined($resp) and $resp and $resp->class->isa('OpenSRF::DomainObject::oilsResult') ){
57 $log->debug( "Math server returned " . $resp->toString(1), INTERNAL );
64 if( $resp ) { $log->debug( "Math received \n".$resp->toString(), ERROR ); }
65 else{ $log->debug( "Math received empty value", ERROR ); }
69 throw OpenSRF::EX::ERROR ("Did not receive expected data from MathDB\n" . $resp);
71 throw OpenSRF::EX::ERROR ("Received no data from MathDB");
76 __PACKAGE__->register_method( method => 'send_request', api_name => '_send_request' );
78 __PACKAGE__->register_method( method => 'add_1', api_name => 'add' );
84 my $meth = $self->method_lookup('_send_request');
85 my $result = $meth->run('add',@args);
89 return send_request( "add", @args );
92 __PACKAGE__->register_method( method => 'sub_1', api_name => 'sub' );
98 my $meth = $self->method_lookup('_send_request');
99 my $result = $meth->run('sub',@args);
103 return send_request( "sub", @args );
106 __PACKAGE__->register_method( method => 'mult_1', api_name => 'mult' );
112 my $meth = $self->method_lookup('_send_request');
113 my $result = $meth->run('mult',@args);
117 return send_request( "mult", @args );
120 __PACKAGE__->register_method( method => 'div_1', api_name => 'div' );
126 my $meth = $self->method_lookup('_send_request');
127 my $result = $meth->run('div',@args);
131 return send_request( "div", @args );