#{
package JRPC;
use JSON::XS;
use Data::Dumper;
use strict;
use warnings;
#UNUSED:my $rstub = {'id' => 66666, 'jsonrpc' => '2.0'};
our $VERSION = '0.61';
# 0 = No validation (trust client, any excep
Require 'id','jsonrpc', 3
our $msgvalid = 1;
# This is prelogger callback. MUST be a _hard_ CODE ref to be used (not symbolic reference).
our $prelogger;
=head1 NAME
JRPC - Create JSON-RPC Services
focusing on app logic, not worrying about the details of JSON-RPC Processing.
=head1 SYNOPSIS
use JRPC;
# Load one of the Service modules JRPC::CGI, JRPC::Apache2 or JRPC::Nginx
# See part
erl
use Data::Dumper;
use JRPC::Client;
use JSON::XS;
use Getopt::Long;
#use threads;
use strict;
use warnings;
=head1 NAME
jrpc_client.pl - Generic JSON-RPC Client for JRPC toolkit
=head1 SYNOPSI
m * url - Service URL to send JSON-RPC request to
=item * method - JSON-RPC Method (e.g 'Pkg.meth' or just 'meth')
=item * parafile - JSON file with parameters for JSON-RPC "params" section
=back
tions (\%para, @pspec);
if (!$para{'url'}) {die("Need URL");}
#if (!$para{'parafile'}) {die("Need JSON-RPC Parameter file ('parafile')");}
if (!$para{'method'}) {die("Need 'method' (In valid format 'm
package JRPC::Nginx;
use JRPC;
use JSON::XS;
# require - to avoid symbol resolution problems ?
require nginx; # nginx / Nginx ?
use strict;
use warnings;
our $VERSION = "0.9";
# See Perldoc at the e
.
#This encapsulates the
#=cut
sub handle_2nd_stage {
my ($r) = @_;
my $jr = {'id' => $$, 'jsonrpc' => '2.0', };
my $buffer = $r->request_body();
eval {
# Parse Request
my $j =
now) that do not serialize
# well. Be ready to encounter exceptions here.
my $out = JSON::XS::encode_json($jr); # Serialize as a separate step to know length
################# Nginx Outpu
);
# qw(OK)
use Apache2::Const -compile => qw(:common); # 'OK', 'DECLINED'
use APR::Table ();
use JSON::XS;
use JRPC; # Import ... ?
*jdie = JRPC::createfault;
#use Storable (); # Would import store -
ache2::RequestUtil;
=head1 NAME
JRPC::Apache2 - JSON-RPC Services in Apache2 / mod_perl runtime
=head1 DESCRIPTION
This package is a mod_perl JSON-RPC handler / dispatcher. It only contains the co
SetHandler modperl
PerlResponseHandler JRPC::Apache2
</Location>
=cut
# Parse and handle JSON-RPC Request.
# reads POST body by $r->read($buffer, $len).
# if/else dispatching (of 3 meth) give
talsToBrowser warningsToBrowser/;
use JSON::XS;
use JRPC;
use strict;
use warnings;
use Scalar::Util ('reftype'); # Check base types
=head1 NAME
JRPC::CGI - JSON-RPC 2.0 Processing for CGI and HTTP:
:Server::Simple::CGI
=head1 DESCRIPTION
This package provides JSON-RPC 2.0 services processor for 2 runtimes based on:
=over 4
=item * CGI (CGI.pm) Plain old CGI scripting (or mod_perl ModPerl::Re
Keep this anywhere that may use CGI request object
sub CGI::uri {return $_[0]->script_name();}
# JSON RPC Response ID for malformed requests.
our $naid = 666666666;
=head2 JRPC::CGI::handle_cgi($cgi
Send Requests to a JSON-RPC Service.
# We completely ride on the wonderful LWP Module.
{
package JRPC::Client;
#
use LWP;
use LWP::UserAgent;
use base ('LWP::UserAgent');
use JSON::XS;
use Data::Dump
er;
#our $mime;
#BEGIN {
# De-facto JSON-RPC Mime type
our $mime = 'application/json';
#};
=head1 NAME
JRPC::Client - JSON-RPC 2.0 Client
=head1 SYNOPSIS
use JRPC::Client;
my $client = JRP
so'}\n");
=head1 DESCRIPTION
JRPC::Client is a Perl LWP based JSON-RPC 2.0 Client hoping to minimize tedious boilerplate code for JSON-RPC
interaction, yet enabling advanced use cases by the power o