1 package OpenILS::WWW::Method;
2 use strict; use warnings;
5 use Apache2::Const -compile => qw(OK REDIRECT :log);
6 use APR::Const -compile => qw(:error SUCCESS);
7 use Apache2::RequestRec ();
8 use Apache2::RequestIO ();
9 use Apache2::RequestUtil;
11 use OpenSRF::Utils::JSON;
15 use OpenSRF::EX qw(:try);
20 use constant MAX_SESSION_REQUESTS => 20;
28 my $cgi = CGI->new( $apache );
30 print "Content-type: text/plain; charset=utf-8\n\n";
33 my @p = $cgi->param();
34 warn "Params: " . Dumper(\@p);
36 my $method = $cgi->param("method");
37 my $service = $cgi->param("service");
41 if( ! $service || ! $method ) {
44 err_msg => "Service name and method name required to fulfill request",
49 print OpenSRF::Utils::JSON->perl2JSON($err);
50 return Apache2::Const::OK;
58 if(defined($cgi->param("param"))) {
59 for my $param ( $cgi->param("param")) {
60 push( @param_array, OpenSRF::Utils::JSON->JSON2perl( $param ));
63 for my $param ($cgi->param()) {
64 $param_hash{$param} = OpenSRF::Utils::JSON->JSON2perl($cgi->param($param))
65 unless( $param eq "method" or $param eq "service" );
71 perform_method($service, $method, @param_array);
73 perform_method($service, $method, %param_hash);
76 return Apache2::Const::OK;
79 sub child_init_handler {
80 OpenSRF::System->bootstrap_client(
81 config_file => "@sysconfdir@/opensrf_core.xml" );
87 my ($service, $method, @params) = @_;
89 warn "performing method $method for service $service with params @params\n";
93 if($session_hash{$service} ) {
95 $session = $session_hash{$service};
96 $session->{web_count} += 1;
98 if( $session->{web_count} > MAX_SESSION_REQUESTS) {
99 $session->disconnect();
100 $session->{web_count} = 1;
105 $session = OpenSRF::AppSession->create($service);
106 $session_hash{$service} = $session;
107 $session->{web_count} = 1;
111 my $request = $session->request( $method, @params );
114 while( my $response = $request->recv(20) ) {
116 if( UNIVERSAL::isa( $response, "Error" )) {
117 warn "Received exception: " . $response->stringify . "\n";
120 err_msg => "Error Completing Request:\n " .
121 "Service: $service \nMethod: $method \nParams: @params \n" .
122 $response->stringify() . "\n",
124 print OpenSRF::Utils::JSON->perl2JSON($err);
129 my $content = $response->content;
130 push @results, $content;
134 if(!$request->complete) {
135 warn "ERROR Completing Request";
138 err_msg => "Error Completing Request:\n ".
139 "Service: $service \nMethod: $method \nParams: @params \n" .
140 "request->complete test failed in OpenILS::Web::Method\n"
142 print OpenSRF::Utils::JSON->perl2JSON($err);
151 warn Dumper \@results;
153 print OpenSRF::Utils::JSON->perl2JSON( \@results );
158 # This module appears unfinshed and/or obsolete with many unconditional warns/dumps.
159 # File is not referenced elsewhere in the codebase. Candidate for deletion.