]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/perlmods/OpenSRF/AppSession.pm
Initial revision
[OpenSRF.git] / src / perlmods / OpenSRF / AppSession.pm
1 package OpenSRF::AppSession;
2 use OpenSRF::DOM;
3 use OpenSRF::DOM::Element::userAuth;
4 use OpenSRF::DomainObject::oilsMessage;
5 use OpenSRF::DomainObject::oilsMethod;
6 use OpenSRF::DomainObject::oilsResponse qw/:status/;
7 use OpenSRF::Transport::PeerHandle;
8 use OpenSRF::Utils::Config;
9 use OpenSRF::Utils::Logger qw(:level);
10 use OpenSRF::EX;
11 use OpenSRF;
12 use Exporter;
13 use base qw/Exporter OpenSRF/;
14 use Time::HiRes qw( time usleep );
15 use warnings;
16 use strict;
17
18 our @EXPORT_OK = qw/CONNECTING INIT_CONNECTED CONNECTED DISCONNECTED CLIENT SERVER/;
19 our %EXPORT_TAGS = ( state => [ qw/CONNECTING INIT_CONNECTED CONNECTED DISCONNECTED/ ],
20                  endpoint => [ qw/CLIENT SERVER/ ],
21 );
22
23 my $logger = "OpenSRF::Utils::Logger";
24
25 our %_CACHE;
26 our @_CLIENT_CACHE;
27 our @_RESEND_QUEUE;
28
29 sub kill_client_session_cache {
30         for my $session ( @_CLIENT_CACHE ) {
31                 $session->kill_me;
32         }
33 }
34
35 sub CONNECTING { return 3 };
36 sub INIT_CONNECTED { return 4 };
37 sub CONNECTED { return 1 };
38 sub DISCONNECTED { return 2 };
39
40 sub CLIENT { return 2 };
41 sub SERVER { return 1 };
42
43 sub find {
44         return undef unless (defined $_[1]);
45         return $_CACHE{$_[1]} if (exists($_CACHE{$_[1]}));
46 }
47
48 sub find_client {
49         my( $self, $app ) = @_;
50         $logger->debug( "Client Cache contains: " .scalar(@_CLIENT_CACHE), INTERNAL );
51         my ($client) = grep { $_->[0] eq $app and $_->[1] == 1 } @_CLIENT_CACHE;
52         $client->[1] = 0;
53         return $client->[2];
54 }
55
56 sub transport_connected {
57         my $self = shift;
58         if( ! exists $self->{peer_handle} || 
59                                         ! $self->{peer_handle} ) {
60                 return 0;
61         }
62         return $self->{peer_handle}->tcp_connected();
63 }
64
65 # ----------------------------------------------------------------------------
66 # Clears the transport buffers
67 # call this if you are not through with the sesssion, but you want 
68 # to have a clean slate.  You shouldn't have to call this if
69 # you are correctly 'recv'ing all of the data from a request.
70 # however, if you don't want all of the data, this will
71 # slough off any excess
72 #  * * Note: This will delete data for all sessions using this transport
73 # handle.  For example, all client sessions use the same handle.
74 # ----------------------------------------------------------------------------
75 sub buffer_reset {
76
77         my $self = shift;
78         if( ! exists $self->{peer_handle} || ! $self->{peer_handle} ) { 
79                 return 0;
80         }
81         $self->{peer_handle}->buffer_reset();
82 }
83
84
85 sub client_cache {
86         my $self = shift;
87         push @_CLIENT_CACHE, [ $self->app, 1, $self ];
88 }
89
90 # when any incoming data is received, this method is called.
91 sub server_build {
92         my $class = shift;
93         $class = ref($class) || $class;
94
95         my $sess_id = shift;
96         my $remote_id = shift;
97         my $service = shift;
98
99         return undef unless ($sess_id and $remote_id and $service);
100
101         my $conf = OpenSRF::Utils::Config->current;
102         
103         if( ! $conf ) { 
104                 OpenSRF::EX::Config->throw( "No suitable config found" ); 
105         }
106
107         if ( my $thingy = $class->find($sess_id) ) {
108                 $thingy->remote_id( $remote_id );
109                 $logger->debug( "AppSession returning existing session $sess_id", DEBUG );
110                 return $thingy;
111         } else {
112                 $logger->debug( "AppSession building new server session $sess_id", DEBUG );
113         }
114
115         if( $service eq "client" ) {
116                 #throw OpenSRF::EX::PANIC ("Attempting to build a client session as a server" .
117                 #       " Session ID [$sess_id], remote_id [$remote_id]");
118                 $logger->debug("Attempting to build a client session as ".
119                                 "a server Session ID [$sess_id], remote_id [$remote_id]", ERROR );
120         }
121
122
123         my $max_requests = $conf->$service->max_requests;
124         $logger->debug( "Max Requests for $service is $max_requests", INTERNAL );# if $max_requests;
125
126         $logger->transport( "AppSession creating new session: $sess_id", INTERNAL );
127
128         my $self = bless { recv_queue  => [],
129                            request_queue  => [],
130                            requests  => 0,
131                            endpoint    => SERVER,
132                            state       => CONNECTING, 
133                            session_id  => $sess_id,
134                            remote_id    => $remote_id,
135                                 peer_handle => OpenSRF::Transport::PeerHandle->retrieve($service),
136                                 max_requests => $max_requests,
137                                 session_threadTrace => 0,
138                                 service => $service,
139                          } => $class;
140
141         return $_CACHE{$sess_id} = $self;
142 }
143
144 sub service { return shift()->{service}; }
145
146 sub continue_request {
147         my $self = shift;
148         $self->{'requests'}++;
149         return $self->{'requests'} <= $self->{'max_requests'} ? 1 : 0;
150 }
151
152 sub last_sent_payload {
153         my( $self, $payload ) = @_;
154         if( $payload ) {
155                 return $self->{'last_sent_payload'} = $payload;
156         }
157         return $self->{'last_sent_payload'};
158 }
159
160 sub last_sent_type {
161         my( $self, $type ) = @_;
162         if( $type ) {
163                 return $self->{'last_sent_type'} = $type;
164         }
165         return $self->{'last_sent_type'};
166 }
167
168 # When we're a client and we want to connect to a remote service
169 # create( $app, username => $user, secret => $passwd );
170 #    OR
171 # create( $app, sysname => $user, secret => $shared_secret );
172 sub create {
173         my $class = shift;
174         $class = ref($class) || $class;
175
176         my $app = shift;
177         my %auth_args = @_;
178
179
180         unless ( $app &&
181                  exists($auth_args{secret}) &&
182                  ( exists($auth_args{username}) ||
183                    exists($auth_args{sysname}) ) ) {
184                 throw OpenSRF::EX::User ( 'Insufficient authentication information for session creation');
185         }
186
187         if( my $thingy = OpenSRF::AppSession->find_client( $app ) ) {
188                         $logger->debug( "AppSession returning existing client session for $app", DEBUG );
189                         return $thingy;
190         } else {
191                 $logger->debug( "AppSession creating new client session for $app", DEBUG );
192         }
193
194
195         
196         my $auth = OpenSRF::DOM::Element::userAuth->new( %auth_args );
197
198         my $conf = OpenSRF::Utils::Config->current;
199
200         if( ! $conf ) { 
201                 OpenSRF::EX::Config->throw( "No suitable config found" ); 
202         }
203
204         my $sess_id = time . rand( $$ );
205         while ( $class->find($sess_id) ) {
206                 $sess_id = time . rand( $$ );
207         }
208
209         my $r_id = $conf->$app->transport_target ||
210                         die("No remote id for $app!");
211
212         my $self = bless { app_name    => $app,
213                            client_auth => $auth,
214                            #recv_queue  => [],
215                            request_queue  => [],
216                            endpoint    => CLIENT,
217                            state       => DISCONNECTED,#since we're init'ing
218                            session_id  => $sess_id,
219                            remote_id   => $r_id,
220                            orig_remote_id   => $r_id,
221                                 # peer_handle => OpenSRF::Transport::PeerHandle->retrieve($app),
222                                 peer_handle => OpenSRF::Transport::PeerHandle->retrieve("client"),
223                                 session_threadTrace => 0,
224                          } => $class;
225
226         $self->client_cache();
227         $_CACHE{$sess_id} = $self;
228         return $self->find_client( $app );
229 }
230
231 sub app {
232         return shift()->{app_name};
233 }
234
235 sub reset {
236         my $self = shift;
237         $self->remote_id($$self{orig_remote_id});
238 }
239
240 # 'connect' can be used as a constructor if called as a class method,
241 # or used to connect a session that has disconnectd if called against
242 # an existing session that seems to be disconnected, or was just built
243 # using 'create' above.
244
245 # connect( $app, username => $user, secret => $passwd );
246 #    OR
247 # connect( $app, sysname => $user, secret => $shared_secret );
248
249 # --- Returns undef if the connect attempt times out.
250 # --- Returns the OpenSRF::EX object if one is returned by the server
251 # --- Returns self if connected
252 sub connect {
253         my $self = shift;
254         my $class = ref($self) || $self;
255
256         return $self if ( ref( $self ) and  $self->state && $self->state == CONNECTED  );
257
258         my $app = shift;
259
260         $self = $class->create($app, @_) if (!ref($self));
261         return undef unless ($self);
262
263
264         $self->reset;
265         $self->state(CONNECTING);
266         $self->send('CONNECT', "");
267
268         my $time_remaining = OpenSRF::Utils::Config->current->client->connect_timeout;
269
270         while ( $self->state != CONNECTED  and $time_remaining > 0 ) {
271                 my $starttime = time;
272                 $self->queue_wait($time_remaining);
273                 my $endtime = time;
274                 $time_remaining -= ($endtime - $starttime);
275         }
276
277         return undef unless($self->state == CONNECTED);
278
279         return $self;
280 }
281
282 sub finish {
283         my $self = shift;
284         #$self->disconnect if ($self->endpoint == CLIENT);
285         for my $ses ( @_CLIENT_CACHE ) {
286                 if ($ses->[2]->session_id eq $self->session_id) {
287                         $ses->[1] = 1;
288                 }
289         }
290 }
291
292 sub kill_me {
293         my $self = shift;
294         if( ! $self->session_id ) { return 0; }
295         $self->disconnect;
296         $logger->transport( "AppSession killing self: " . $self->session_id(), DEBUG );
297         my @a;
298         for my $ses ( @_CLIENT_CACHE ) {
299                 push @a, $ses 
300                         if ($ses->[2]->session_id ne $self->session_id);
301         }
302         @_CLIENT_CACHE = @a;
303         delete $_CACHE{$self->session_id};
304         delete($$self{$_}) for (keys %$self);
305 }
306
307 sub disconnect {
308         my $self = shift;
309         unless( $self->state == DISCONNECTED ) {
310                 $self->send('DISCONNECT', "") if ($self->endpoint == CLIENT);;
311                 $self->state( DISCONNECTED ); 
312         }
313         $self->reset;
314 }
315
316 sub request {
317         my $self = shift;
318         my $meth = shift;
319
320         my $method;
321         if (!ref $meth) {
322                 $method = new OpenSRF::DomainObject::oilsMethod ( method => $meth );
323         } else {
324                 $method = $meth;
325         }
326         
327         $method->params( @_ );
328
329         $self->send('REQUEST',$method);
330 }
331
332
333 sub send {
334         my $self = shift;
335         my @payload_list = @_; # this is a Domain Object
336
337         $logger->debug( "In send", INTERNAL );
338         
339         my $tT;
340
341         if( @payload_list % 2 ) { $tT = pop @payload_list; }
342
343         if( ! @payload_list ) {
344                 $logger->debug( "payload_list param is incomplete in AppSession::send()", ERROR );
345                 return undef; 
346         }
347
348         my $doc = OpenSRF::DOM->createDocument();
349
350         $logger->debug( "In send2", INTERNAL );
351
352         my $disconnect = 0;
353         my $connecting = 0;
354
355         while( @payload_list ) {
356
357                 my ($msg_type, $payload) = ( shift(@payload_list), shift(@payload_list) ); 
358
359                 if ($msg_type eq 'DISCONNECT' ) {
360                         $disconnect++;
361                         if( $self->state == DISCONNECTED) {
362                                 next;
363                         }
364                 }
365
366                 if( $msg_type eq "CONNECT" ) { $connecting++; }
367
368
369                 if( $payload ) {
370                         $logger->debug( "Payload is ".$payload->toString, INTERNAL );
371                 }
372         
373         
374                 my $msg = OpenSRF::DomainObject::oilsMessage->new();
375                 $logger->debug( "AppSession after creating oilsMessage $msg", INTERNAL );
376                 
377                 $msg->type($msg_type);
378                 $logger->debug( "AppSession after adding type" . $msg->toString(), INTERNAL );
379         
380                 $msg->userAuth($self->client_auth) if ($self->endpoint == CLIENT && $msg_type eq 'CONNECT');
381         
382                 no warnings;
383                 $msg->threadTrace( $tT || int($self->session_threadTrace) || int($self->last_threadTrace) );
384                 use warnings;
385         
386                 if ($msg->type eq 'REQUEST') {
387                         if ( !defined($tT) || $self->last_threadTrace != $tT ) {
388                                 $msg->update_threadTrace;
389                                 $self->session_threadTrace( $msg->threadTrace );
390                                 $tT = $self->session_threadTrace;
391                                 OpenSRF::AppRequest->new($self, $payload);
392                         }
393                 }
394         
395                 $msg->protocol(1);
396                 $msg->payload($payload) if $payload;
397         
398                 $doc->documentElement->appendChild( $msg );
399
400         
401                 $logger->debug( "AppSession sending ".$msg->type." to ".$self->remote_id.
402                         " with threadTrace [".$msg->threadTrace."]", INFO );
403
404         }
405         
406         if ($self->endpoint == CLIENT and ! $disconnect) {
407                 $self->queue_wait(0);
408                 unless ($self->state == CONNECTED || ($self->state == CONNECTING && $connecting )) {
409                         my $v = $self->connect();
410                         if( ! $v ) {
411                                 $logger->debug( "Unable to connect to remote service in AppSession::send()", ERROR );
412                                 return undef;
413                         }
414                         if( $v and $v->class->isa( "OpenSRF::EX" ) ) {
415                                 return $v;
416                         }
417                 }
418         } 
419
420         $logger->debug( "AppSession sending doc: " . $doc->toString(), INTERNAL );
421
422
423         $self->{peer_handle}->send( 
424                                         to     => $self->remote_id,
425                                    thread => $self->session_id,
426                                    body   => $doc->toString );
427
428         return $self->app_request( $tT );
429 }
430
431 sub app_request {
432         my $self = shift;
433         my $tT = shift;
434         
435         return undef unless (defined $tT);
436         my ($req) = grep { $_->threadTrace == $tT } @{ $self->{request_queue} };
437
438         return $req;
439 }
440
441 sub remove_app_request {
442         my $self = shift;
443         my $req = shift;
444         
445         my @list = grep { $_->threadTrace != $req->threadTrace } @{ $self->{request_queue} };
446
447         $self->{request_queue} = \@list;
448 }
449
450 sub endpoint {
451         return $_[0]->{endpoint};
452 }
453
454
455 sub session_id {
456         my $self = shift;
457         return $self->{session_id};
458 }
459
460 sub push_queue {
461         my $self = shift;
462         my $resp = shift;
463         my $req = $self->app_request($resp->[1]);
464         return $req->push_queue( $resp->[0] ) if ($req);
465         push @{ $self->{recv_queue} }, $resp->[0];
466 }
467
468 sub last_threadTrace {
469         my $self = shift;
470         my $new_last_threadTrace = shift;
471
472         my $old_last_threadTrace = $self->{last_threadTrace};
473         if (defined $new_last_threadTrace) {
474                 $self->{last_threadTrace} = $new_last_threadTrace;
475                 return $new_last_threadTrace unless ($old_last_threadTrace);
476         }
477
478         return $old_last_threadTrace;
479 }
480
481 sub session_threadTrace {
482         my $self = shift;
483         my $new_last_threadTrace = shift;
484
485         my $old_last_threadTrace = $self->{session_threadTrace};
486         if (defined $new_last_threadTrace) {
487                 $self->{session_threadTrace} = $new_last_threadTrace;
488                 return $new_last_threadTrace unless ($old_last_threadTrace);
489         }
490
491         return $old_last_threadTrace;
492 }
493
494 sub last_message_type {
495         my $self = shift;
496         my $new_last_message_type = shift;
497
498         my $old_last_message_type = $self->{last_message_type};
499         if (defined $new_last_message_type) {
500                 $self->{last_message_type} = $new_last_message_type;
501                 return $new_last_message_type unless ($old_last_message_type);
502         }
503
504         return $old_last_message_type;
505 }
506
507 sub last_message_protocol {
508         my $self = shift;
509         my $new_last_message_protocol = shift;
510
511         my $old_last_message_protocol = $self->{last_message_protocol};
512         if (defined $new_last_message_protocol) {
513                 $self->{last_message_protocol} = $new_last_message_protocol;
514                 return $new_last_message_protocol unless ($old_last_message_protocol);
515         }
516
517         return $old_last_message_protocol;
518 }
519
520 sub remote_id {
521         my $self = shift;
522         my $new_remote_id = shift;
523
524         my $old_remote_id = $self->{remote_id};
525         if (defined $new_remote_id) {
526                 $self->{remote_id} = $new_remote_id;
527                 return $new_remote_id unless ($old_remote_id);
528         }
529
530         return $old_remote_id;
531 }
532
533 sub client_auth {
534         my $self = shift;
535         my $new_ua = shift;
536
537         my $old_ua = $self->{client_auth};
538         if (defined $new_ua) {
539                 $self->{client_auth} = $new_ua;
540                 return $new_ua unless ($old_ua);
541         }
542
543         return $old_ua->cloneNode(1);
544 }
545
546 sub state {
547         my $self = shift;
548         my $new_state = shift;
549
550         my $old_state = $self->{state};
551         if (defined $new_state) {
552                 $self->{state} = $new_state;
553                 return $new_state unless ($old_state);
554         }
555
556         return $old_state;
557 }
558
559 sub DESTROY {
560         my $self = shift;
561         delete $$self{$_} for keys %$self;
562         return undef;
563 }
564
565 sub recv {
566         my $self = shift;
567         my @proto_args = @_;
568         my %args;
569
570         if ( @proto_args ) {
571                 if ( !(@proto_args % 2) ) {
572                         %args = @proto_args;
573                 } elsif (@proto_args == 1) {
574                         %args = ( timeout => @proto_args );
575                 }
576         }
577
578         #$logger->debug( ref($self). " recv_queue before wait: " . $self->_print_queue(), INTERNAL );
579
580         if( exists( $args{timeout} ) ) {
581                 $args{timeout} = int($args{timeout});
582         } else {
583                 $args{timeout} = 10;
584         }
585
586         #$args{timeout} = 0 if ($self->complete);
587
588         $logger->debug( ref($self) ."->recv with timeout " . $args{timeout}, INTERNAL );
589
590         $args{count} ||= 1;
591
592         my $avail = @{ $self->{recv_queue} };
593         my $time_remaining = $args{timeout};
594
595         while ( $avail < $args{count} and $time_remaining > 0 ) {
596                 last if $self->complete;
597                 my $starttime = time;
598                 $self->queue_wait($time_remaining);
599                 my $endtime = time;
600                 $time_remaining -= ($endtime - $starttime);
601                 $avail = @{ $self->{recv_queue} };
602         }
603
604         #$logger->debug( ref($self)." queue after wait: " . $self->_print_queue(), INTERNAL );
605                 
606         my @list;
607         while ( my $msg = shift @{ $self->{recv_queue} } ) {
608                 push @list, $msg;
609                 last if (scalar(@list) >= $args{count});
610         }
611
612 #       $self->{recv_queue} = [@unlist, @{ $self->{recv_queue} }];
613         $logger->debug( "Number of matched responses: " . @list, DEBUG );
614
615         $self->queue_wait(0); # check for statuses
616         
617         return $list[0] unless (wantarray);
618         return @list;
619 }
620
621 sub push_resend {
622         my $self = shift;
623         push @OpenSRF::AppSession::_RESEND_QUEUE, @_;
624 }
625
626 sub flush_resend {
627         my $self = shift;
628         $logger->debug( "Resending..." . @_RESEND_QUEUE, DEBUG );
629         while ( my $req = shift @OpenSRF::AppSession::_RESEND_QUEUE ) {
630                 $req->resend;
631         }
632 }
633
634
635 sub queue_wait {
636         my $self = shift;
637         if( ! $self->{peer_handle} ) { return 0; }
638         my $timeout = shift || 0;
639         $logger->debug( "Calling queue_wait($timeout)" , DEBUG );
640         $logger->debug( "Timestamp before process($timeout) : " . $logger->format_time(), INTERNAL );
641         my $o = $self->{peer_handle}->process($timeout);
642         $logger->debug( "Timestamp after  process($timeout) : " . $logger->format_time(), INTERNAL );
643         $self->flush_resend;
644         return $o;
645 }
646
647 sub _print_queue {
648         my( $self ) = @_;
649         my $string = "";
650         foreach my $msg ( @{$self->{recv_queue}} ) {
651                 $string = $string . $msg->toString(1) . "\n";
652         }
653         return $string;
654 }
655
656 sub status {
657         my $self = shift;
658         $self->send( 'STATUS', @_ );
659 }
660
661 #-------------------------------------------------------------------------------
662
663 package OpenSRF::AppRequest;
664 use base qw/OpenSRF::AppSession/;
665 use OpenSRF::Utils::Logger qw/:level/;
666 use OpenSRF::DomainObject::oilsResponse qw/:status/;
667
668 sub new {
669         my $class = shift;
670         $class = ref($class) || $class;
671
672         my $session = shift;
673         my $threadTrace = $session->session_threadTrace || $session->last_threadTrace;
674         my $payload = shift;
675         
676         my $self = {    session     => $session,
677                         threadTrace => $threadTrace,
678                         payload     => $payload,
679                         complete    => 0,
680                         recv_queue  => [],
681         };
682
683         bless $self => $class;
684
685         push @{ $self->session->{request_queue} }, $self;
686
687         return $self;
688 }
689
690 sub queue_size {
691         my $size = @{$_[0]->{recv_queue}};
692         return $size;
693 }
694         
695 sub send {
696         shift()->session->send(@_);
697 }
698
699 sub finish {
700         my $self = shift;
701         $self->session->remove_app_request($self);
702         delete($$self{$_}) for (keys %$self);
703 }
704
705 sub session {
706         return shift()->{session};
707 }
708
709 sub complete {
710         my $self = shift;
711         my $complete = shift;
712         return $self->{complete} if ($self->{complete});
713         if (defined $complete) {
714                 $self->{complete} = $complete;
715         } else {
716                 $self->session->queue_wait(0);
717         }
718         return $self->{complete};
719 }
720
721 sub wait_complete {
722         my $self = shift;
723         my $timeout = shift || 1;
724         my $time_remaining = $timeout;
725
726         while ( ! $self->complete  and $time_remaining > 0 ) {
727                 my $starttime = time;
728                 $self->queue_wait($time_remaining);
729                 my $endtime = time;
730                 $time_remaining -= ($endtime - $starttime);
731         }
732
733         return $self->complete;
734 }
735
736 sub threadTrace {
737         return shift()->{threadTrace};
738 }
739
740 sub push_queue {
741         my $self = shift;
742         my $resp = shift;
743         push @{ $self->{recv_queue} }, $resp;
744         OpenSRF::Utils::Logger->debug( "AppRequest pushed ".$resp->toString(), INTERNAL );
745 }
746
747 sub queue_wait {
748         my $self = shift;
749         OpenSRF::Utils::Logger->debug( "Calling queue_wait(@_)", DEBUG );
750         return $self->session->queue_wait(@_)
751 }
752
753 sub payload { return shift()->{payload}; }
754
755 sub resend {
756         my $self = shift;
757         OpenSRF::Utils::Logger->debug(
758                 "I'm resending the request for threadTrace ". $self->threadTrace, DEBUG);
759         OpenSRF::Utils::Logger->debug($self->payload->toString,INTERNAL);
760         return $self->session->send('REQUEST', $self->payload, $self->threadTrace );
761 }
762
763 sub status {
764         my $self = shift;
765         my $msg = shift;
766         $self->session->send( 'STATUS',$msg, $self->threadTrace );
767 }
768
769 sub respond {
770         my $self = shift;
771         my $msg = shift;
772
773         my $response;
774         if (!ref($msg) || ($msg->can('getAttribute') && $msg->getAttribute('name') !~ /oilsResult/)) {
775                 $response = new OpenSRF::DomainObject::oilsResult;
776                 $response->content($msg);
777         } else {
778                 $response = $msg;
779         }
780
781         $self->session->send('RESULT', $response, $self->threadTrace);
782 }
783
784 sub respond_complete {
785         my $self = shift;
786         my $msg = shift;
787
788         my $response;
789         if (!ref($msg) || ($msg->can('getAttribute') && $msg->getAttribute('name') !~ /oilsResult/)) {
790                 $response = new OpenSRF::DomainObject::oilsResult;
791                 $response->content($msg);
792         } else {
793                 $response = $msg;
794         }
795
796         my $stat = OpenSRF::DomainObject::oilsConnectStatus->new(
797                 statusCode => STATUS_COMPLETE(),
798                 status => 'Request Complete' );
799
800         $self->session->send( 'RESULT' => $response, 'STATUS' => $stat, $self->threadTrace);
801
802 }
803
804
805 1;
806
807
808 __END__
809
810 [client]
811 interval:connect_timeout = 2 seconds
812
813 [servers]
814 subsection:StorageServer = Storage_config
815
816 [Storage_config]
817 #transport = xmlrpc
818 #transport_target = http://open-ils.org/RPC2/services/Storage
819
820 transport = jabber
821 transport_target = Storage@open-ils.org/SERVICE_RECEIVER
822 method_class = OpenSRF::App::Storage::PGStore;
823
824
825
826
827