Commit 635e1a18 authored by Benoit Mortier's avatar Benoit Mortier
Browse files

Fixes: #943 argonaut should work on ssl mode https

parent 4e14d205
......@@ -24,7 +24,7 @@ POE::Component::Server::JSONRPC - POE tcp or http based JSON-RPC server
'sum' => 'sum',
},
);
#tcp version:
POE::Component::Server::JSONRPC::Tcp->new(
Port => 3000,
......@@ -33,16 +33,16 @@ POE::Component::Server::JSONRPC - POE tcp or http based JSON-RPC server
'sum' => 'sum',
},
);
sub echo {
my ($kernel, $jsonrpc, $id, @params) = @_[KERNEL, ARG0..$#_ ];
$kernel->post( $jsonrpc => 'result' => $id, @params );
}
sub sum {
my ($kernel, $jsonrpc, $id, @params) = @_[KERNEL, ARG0..$#_ ];
$kernel->post( $jsonrpc => 'result' => $id, $params[0] + $params[1] );
}
......@@ -84,7 +84,7 @@ sub new {
$self->{parent} = $poe_kernel->get_active_session->ID;
$self->{json} ||= JSON->new;
my $session = POE::Session->create(
my $session = POE::Session->create(
object_states => [
$self => {
map { ( $_ => "poe_$_", ) }
......@@ -146,12 +146,13 @@ sub poe__start {
$heap->{clients} = {};
$heap->{id} = 0;
$kernel->yield('init_server');
}
=head2 poe_init_server
Should be defined in Http or Tcp
Should be defined in Http or Tcp
=cut
sub poe_init_server { print "error init_server\n"; }
......@@ -162,9 +163,9 @@ sub poe_init_server { print "error init_server\n"; }
sub poe_input_handler {
my ($self, $kernel, $session, $heap, $request, $response, $dirmatch) = @_[OBJECT, KERNEL, SESSION, HEAP, ARG0..$#_ ];
$heap->{clients}->{$heap->{id}} = {json_id => undef, response => $response};
my $json;
eval {
$json = $self->{json}->decode( $request->content );
......@@ -173,7 +174,7 @@ sub poe_input_handler {
$kernel->yield('error', $heap->{id}, q{invalid json request});
return;
}
$heap->{clients}->{$heap->{id}} = {json_id => $json->{id}, response => $response};
unless ($json and $json->{method}) {
......@@ -190,7 +191,7 @@ sub poe_input_handler {
my @params = @{ $json->{params} || [] };
$kernel->post($self->{parent}, $handler, $session->ID, $heap->{id}, @params);
$heap->{id}++;
if ($heap->{id}>=65535) { # limit to 2 bytes
$heap->{id} = 0;
......@@ -207,16 +208,16 @@ sub poe_result {
#~ print "answering to ".$id."\n";
my $client = $heap->{clients}->{$id};
my $json_content = $self->{json}->encode(
{ id => $client->{json_id} || undef,
error => undef,
result => (@results > 1 ? \@results : $results[0]),
}
);
#~ print "json content : ".$json_content."\n";
$kernel->yield('send',$client->{response},$json_content);
delete $heap->{clients}->{$id};
}
......@@ -229,22 +230,23 @@ sub poe_error {
my ($self, $kernel, $heap, $id, $error) = @_[OBJECT, KERNEL, HEAP, ARG0..$#_];
my $client = $heap->{clients}->{$id};
my $json_error_content = $self->{json}->encode(
{ id => $client->{json_id} || undef,
error => $error,
result => undef,
}
);
#~ print "json content : ".$json_error_content."\n";
$kernel->yield('send',$client->{response},$json_error_content);
delete $heap->{clients}->{$id};
}
=head2 poe_send
Should be defined in Http or Tcp
Should be defined in Http or Tcp
=cut
sub poe_send { print "error poe_send\n"; }
......
......@@ -38,7 +38,8 @@ use Data::Dumper;
POE::Component::Server::JSONRPC::Http - POE http based JSON-RPC server
=head2 new
constructor
constructor
=cut
sub new {
......@@ -47,19 +48,22 @@ sub new {
}
=head2 poe_init_server
Init HTTP Server.
Init HTTP Server.
=cut
sub poe_init_server {
my ($self, $kernel, $session, $heap) = @_[OBJECT, KERNEL, SESSION, HEAP];
$kernel->alias_set( 'JSONRPCHTTP' );
$self->{http} = POE::Component::Server::SimpleHTTP->new(
'ALIAS' => 'HTTPD',
'PORT' => $self->{Port},
$self->{Address} ? ('ADDRESS' => $self->{Address} ) : (),
$self->{Hostname} ? ('HOSTNAME' => $self->{Hostname} ) : (),
$self->{Address} ? ('ADDRESS' => $self->{Address} ) : (),
$self->{Hostname} ? ('HOSTNAME' => $self->{Hostname} ) : (),
$self->{SslKey} ? ('SSLKEYCERT' => ($self->{SslKey}, $self->{SslCert})) : (),
$self->{SslCacert} ? ('SSLINTERMEDIATECACERT' => $self->{SslCacert} ) : (),
'HANDLERS' => [
{
'DIR' => '.*',
......@@ -71,16 +75,17 @@ sub poe_init_server {
}
=head2 poe_send
Send HTTP response
Send HTTP response
=cut
sub poe_send {
my ($kernel,$response, $content) = @_[KERNEL,ARG0..$#_];
#HTTP
$response->code( 200 );
$response->content( $content );
$kernel->post( 'HTTPD', 'DONE', $response );
}
......
......@@ -16,7 +16,8 @@ use JSON::Any;
POE::Component::Server::JSONRPC::Tcp - POE tcp based JSON-RPC server
=head2 new
constructor
constructor
=cut
sub new {
......@@ -25,12 +26,13 @@ sub new {
}
=head2 poe_init_server
Init TCP Server.
Init TCP Server.
=cut
sub poe_init_server {
my ($self, $kernel, $session, $heap) = @_[OBJECT, KERNEL, SESSION, HEAP];
my $bind = sub {
my $method = $_[0];
......@@ -66,12 +68,13 @@ sub poe_init_server {
}
=head2 poe_send
Send TCP response
Send TCP response
=cut
sub poe_send {
my ($kernel,$response, $content) = @_[KERNEL,ARG0..$#_];
# TCP
$kernel->post($response => send => $response,$content);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment