From e1581d4248a6fd42f6ebee233387777f63e25022 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 30 Jul 2014 13:29:46 -0400 Subject: [PATCH] LP#1350457: Pass caller's session to subrequests called via method_lookup 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. This patch also teaches OpenSRF object registration how to strip certain object members -- in particular, the session -- so that introspection continues to work. Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- src/perl/lib/OpenSRF/Application.pm | 13 +++++++++---- src/perl/lib/OpenSRF/Utils/JSON.pm | 9 ++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/perl/lib/OpenSRF/Application.pm b/src/perl/lib/OpenSRF/Application.pm index 5ae98bf..023bb8d 100644 --- a/src/perl/lib/OpenSRF/Application.pm +++ b/src/perl/lib/OpenSRF/Application.pm @@ -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 ); @@ -436,7 +437,12 @@ sub register_method { ($args{object_hint} = $args{package}) =~ s/::/_/go; } - OpenSRF::Utils::JSON->register_class_hint( name => $args{package}, hint => $args{object_hint}, type => "hash" ); + OpenSRF::Utils::JSON->register_class_hint( + strip => ['session'], + name => $app, + hint => $args{object_hint}, + type => "hash" + ); $_METHODS[$args{api_level}]{$args{api_name}} = bless \%args => $app; @@ -558,6 +564,7 @@ sub method_lookup { $meth = $self->method_lookup($method,$proto,1); } + $meth->session($self->session) if $meth && ref($self); # Pass the caller's session return $meth; } @@ -571,9 +578,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); } diff --git a/src/perl/lib/OpenSRF/Utils/JSON.pm b/src/perl/lib/OpenSRF/Utils/JSON.pm index 6411870..4efa3dc 100644 --- a/src/perl/lib/OpenSRF/Utils/JSON.pm +++ b/src/perl/lib/OpenSRF/Utils/JSON.pm @@ -212,7 +212,14 @@ sub perl2JSONObject { if(UNIVERSAL::isa($obj, 'HASH')) { $jsonobj = {}; - $jsonobj->{$_} = $pkg->perl2JSONObject($obj->{$_}) for (keys %$obj); + for my $k (keys %$obj) { + next if ( + $ref ne 'HASH' + and exists $_class_map{classes}{$ref}{strip} + and grep { $k eq $_ } @{$_class_map{classes}{$ref}{strip}} + ); + $jsonobj->{$k} = $pkg->perl2JSONObject($obj->{$k}); + } } elsif(UNIVERSAL::isa($obj, 'ARRAY')) { $jsonobj = []; $jsonobj->[$_] = $pkg->perl2JSONObject($obj->[$_]) for(0..scalar(@$obj) - 1); -- 2.43.2