LP#1350457: Pass caller's session to subrequests called via method_lookup
authorMike Rylander <mrylander@gmail.com>
Wed, 30 Jul 2014 17:29:46 +0000 (13:29 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 20 Aug 2014 21:11:21 +0000 (14:11 -0700)
In the process of looking up a method for an internal subrequest, we lose
session info. This is a problem when the subrequest makes a remote request,
because then the subrequest can't look up the proper locale, among other
things. The forthcoming branch passes the caller's session to the subrequest.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

src/perl/lib/OpenSRF/Application.pm

index 5ae98bf..d409957 100644 (file)
@@ -171,6 +171,7 @@ sub handler {
 
                if (ref $coderef) {
                        my @args = $app_msg->params;
+                       $coderef->session( $session );
                        my $appreq = OpenSRF::AppRequest->new( $session );
                        $appreq->max_chunk_size( $coderef->max_chunk_size );
                        $appreq->max_chunk_count( $coderef->max_chunk_count );
@@ -558,6 +559,7 @@ sub method_lookup {
                $meth = $self->method_lookup($method,$proto,1);
        }
 
+       $meth->session($self->session) if $meth; # Pass the caller's session
        return $meth;
 }
 
@@ -571,9 +573,7 @@ sub run {
        if ( !UNIVERSAL::isa($req, 'OpenSRF::AppRequest') ) {
                $log->debug("Creating a SubRequest object", DEBUG);
                unshift @params, $req;
-               $req = OpenSRF::AppSubrequest->new;
-               $req->session( $self->session ) if ($self->session);
-
+               $req = OpenSRF::AppSubrequest->new( session => $self->session );
        } else {
                $log->debug("This is a top level request", DEBUG);
        }