Latest Danga::Socket (1.58 iirc)
Lo,
I'm having a lot of trouble with my ax2 app. The general
methodology is
this:
1) ax2 receives a request
2) ax2 serializes the request, creates a socket and sends
the request to
an rpc server ( Net::Server )
3) rpc serializes the result (xml and redirects etc) and
passes them
back to ax2
4) ax2 sends the result back to the browser
This works on my laptop. In fact it sort of works on the
production
server. However, if I have a request that produces a lot
of xml and then I click the link quite fast in the browser,
after a few
seconds ax2 gets all confused and doesn't return anything.
It also
forgets that I am authenticated and asks for credentials
again and then
returns nothing.
If I then try to go to the homepage it still produces
nothing. However
it is receiving requests and has remembered my
authentication.
It is also sending the correct request to the rpc server and
receiving
xml back in my Danga object. (put into self->notes) in
hook xmlresponse2
the xml is no longer defined tho.
More to the point, $self->client->peer_addr_string is
returning undef.
Which is either a cause or a symptom
Below is relevant logs and code. Any clue greatly
appreciated.
PLUGIN:
sub create_rpc {
my $self = shift;
my $PORT = 2000;
my $sock = IO::Socket::INET->new( PeerHost =>
'localhost',
PeerPort =>
$PORT,
Proto =>
'tcp',
Type =>
SOCK_STREAM,
Blocking => 0 )
or die "Error creating client on port
$PORT : $ n";
IO::Handle::blocking( $sock, 0 );
my $rpc =
Firstb2b::AxKit2::SubprocessEvent->new($sock,
$self->client);
#$self->client->notes( 'rpc', $rpc );
$self->notes( 'rpc', $rpc );
$rpc->AddOtherFds( fileno($sock) => sub{} );
$rpc->watch_read(1);
return $rpc;
}
sub hook_xmlresponse1 {
my ($self, $input) = _;
my ( $dom, $sub, $bl, $uri );
my $client = $self->client;
$self->log(LOGDEBUG, 'XML ONE ' );
$client->notes('xml_response', DECLINED);
if ( $client->headers_in->filename =~
/.(?i:png|gif|css|jpg|js|html)$/ ) {
$self->log(LOGDEBUG, 'DECLINING ORDINARY
FILE11111: '.
$client->headers_in->filename);
return DECLINED;
}
$self->show_params;
my $is_valid = $self->validate_uri;
$self->log(LOGDEBUG, 'IS: '. ($is_valid ? 'VALID' :
'NOT VALID'));
# If we're using auth, it's the auth sid, otherwise it's
the rpc sid
my $sid = $self->get_session_id;
my $rpc = $self->create_rpc;
my $params = { uri_params =>
$self->get_uri_params,
sid => $sid,
username =>
$client->notes('username'),
use_auth =>
$self->config('UsingAuth') };
$rpc->write( freeze( $params ) . 'ROSE' . EOL );
return CONTINUATION;
} # hook_xmlresponse1
sub hook_xmlresponse2 {
my ($self, $input, $hdrs) = _;
my $client = $self->client;
if ( $client->headers_in->filename =~
/.(?i:png|gif|css|jpg|js|html)$/ ) {
$self->log(LOGDEBUG, 'DECLINING ORDINARY
FILE22222: '.
$client->headers_in->filename);
return DECLINED;
}
$self->log(LOGDEBUG, 'XML TWO '.ref $input );
my $sid;
# my $rpc = $client->notes('rpc');
my $rpc = $self->notes('rpc');
if ($client->notes('xml_response') == OK) {
$self->log(LOGDEBUG, "nnXMLRESPONSE 2
OKOK");# rpc->data ".
#Dumper($rpc->).$client->notes('xml_response'));
# If it's auth we gen the sid, otherwise the rpc app
does it.
# The reason being that we don't know the states of
the app and
a session
# isn't generated until after a login.
# I suppose the app could tell us when to generate
one.
$sid = $rpc->;
# Only store the auth sid => rpc sid if we are
using auth
if ( $self->config('UsingAuth') ) {
$sessions->{$client->notes('authenticate::session')} =
$rpc-> if $sid;
}
else {
# TODO cookie the sid
}
# debug
if ( !$rpc-> || !$rpc-> ) {
my $uri =
"http://".$client->headers_
in->header('Host').$self->uri_gen( {state =>
'admin_mp'} );
$self->log(LOGDEBUG, "nnNO XML
RETURNED FROM RPC
XMLRESPONSE 2 REDIRECT -> ".
Dumper($rpc->).$client->notes('xml_response').$u
ri);
$client->headers_out->header('Location',
$uri );
return REDIRECT;
}
my $parser = XML::LibXML->new();
my $dom = $parser->parse_string(
$rpc-> );
$input->dom( $dom );
my $styles = $rpc->;
$client->notes('rpc', undef);
my $dir = $self->config('StyleSheetDir').'/';
my $out = $input->transform(map XSLT(
$dir.$_->,
%{$_->} ), {$styles});
$self->log(LOGDEBUG, 'XML2 OUT' );
return OK, $out;
}
elsif ($client->notes('xml_response') == REDIRECT) {
my $uri =
"http://".$client->headers_
in->header('Host').$rpc->;
$self->log(LOGDEBUG, "nnXMLRESPONSE 2
REDIRECT -> ".
Dumper($rpc->).$client->notes('xml_response').$u
ri);
$client->headers_out->header('Location', $uri
);
}
return $client->notes('xml_response');
}
package Firstb2b::AxKit2::SubprocessEvent;
# Used by AxKit plugin that drives our apps
use AxKit2::Constants;
use base qw(Danga::Socket);
use fields qw(data client);
use Storable qw( freeze thaw );
use Data: umper;
sub new {
my Firstb2b::AxKit2::SubprocessEvent $self = shift;
my $sock = shift;
my $client = shift;
$self = fields::new( $self ) unless ref($self);
$self->SUPER::new($sock);
$self-> = '';
$self-> = $client;
return $self;
}
sub event_read {
my Firstb2b::AxKit2::SubprocessEvent $self = shift;
my $bref = $self->read(20000);
warn "EVENT READ 1: bref ".($bref ? length($$bref)
: 0);#.Dumper($bref);
return $self->close($!) unless defined $bref;
chomp $$bref; # lose the n
warn "EVENT READ 2: chomped bref ".($bref ?
length($$bref) :
0);#.Dumper($bref);
my $finished = $$bref =~ s/ROSE 15?//;
$self-> .= $$bref;
if ( $finished ) {
$self-> = thaw $self->;
$self->->notes('xml_response',
$self->
|| OK);
warn "EVENT READ 3: self->data
".length($self->);#.Dumper($self->);
$self->->finish_continuation;
warn "EVENT READ 4";
}
else {
warn "EVENT READ 5 NOT FINISHED";
$self->->notes('xml_response',
DECLINED);
}
}
1;
2008-02-29 09:27:52.208145500 81.6.252.25:32877 L6
Connection from
81.6.252.25:32877
2008-02-29 09:27:52.244694500 81.6.252.25:32877 L6
uri_to_file
uri_translation translate: /ecomm/, root /ecomm, dr:
/var/www/AxKit2/ecomm/web/webroot
2008-02-29 09:27:52.245134500 81.6.252.25:32877 L7
uri_to_file
uri_translation Translated / to
/var/www/AxKit2/ecomm/web/webroot
(request uri: /ecomm/, path info: )
2008-02-29 09:27:52.245537500 81.6.252.25:32877 L7
authenticate
authentication Digest authentication for realm Ecomm II
2008-02-29 09:27:52.246413500 81.6.252.25:32877 L6
authenticate
authentication Identified user as john via Digest
2008-02-29 09:27:52.246746500 81.6.252.25:32877 L7
ecomm_2epm
xmlresponse XML ONE
2008-02-29 09:27:52.247020500 81.6.252.25:32877 L7
ecomm_2epm xmlresponse
2008-02-29 09:27:52.247021500
2008-02-29 09:27:52.247022500 VALIDATE URI PARAMS: $VAR1 =
undef;
2008-02-29 09:27:52.247023500
2008-02-29 09:27:52.247173500 81.6.252.25:32877 L7
ecomm_2epm
xmlresponse IS: VALID
2008-02-29 09:27:52.247345500 81.6.252.25:32877 L7
ecomm_2epm
xmlresponse GET SESSION: 6226d3bc4a70cce30a15448bed557dde
2008-02-29 09:27:52.254131500 EVENT READ 1: bref 1766 at
/usr/lib/perl5/site_perl/5.8.8/Firstb2b/AxKit2/SubprocessEve
nt.pm line 27.
2008-02-29 09:27:52.254157500 EVENT READ 2: chomped bref
1765 at
/usr/lib/perl5/site_perl/5.8.8/Firstb2b/AxKit2/SubprocessEve
nt.pm line 30.
2008-02-29 09:27:52.254271500 EVENT READ 3: self->data 15
at
/usr/lib/perl5/site_perl/5.8.8/Firstb2b/AxKit2/SubprocessEve
nt.pm line 37.
2008-02-29 09:27:52.254547500 peer undef L7 ecomm_2epm
xmlresponse XML
TWO AxKit2::Processor
2008-02-29 09:27:52.254676500 peer undef L7 ecomm_2epm
xmlresponse
2008-02-29 09:27:52.254677500
2008-02-29 09:27:52.254678500 XMLRESPONSE 2 OKOK
2008-02-29 09:27:52.254974500 peer undef L7 ecomm_2epm
xmlresponse
2008-02-29 09:27:52.254976500
2008-02-29 09:27:52.254976500 NO XML RETURNED FROM RPC
XMLRESPONSE 2
REDIRECT -> $VAR1 = {};
2008-02-29 09:27:52.254978500
200http://darkstar:8010/ecomm/?
state=admin_mp&rose=155c22b3cbf9d048cd2f905ffc75dda0
2008-02-29 09:27:52.255280500 EVENT READ 4 at
/usr/lib/perl5/site_perl/5.8.8/Firstb2b/AxKit2/SubprocessEve
nt.pm line 39.
2008-02-29 09:27:52.255331500 EVENT READ 1: bref 0 at
/usr/lib/perl5/site_perl/5.8.8/Firstb2b/AxKit2/SubprocessEve
nt.pm line 27.
2008/02/29-09:27:52 CONNECT TCP Peer:
"127.0.0.1:33787" Local:
"127.0.0.1:2000"
RPC SERVER RCVD REQUEST: $VAR1 = {
'sid' => '6226d3bc4a70cce30a15448bed557dde',
'use_auth' => '1',
'uri_params' => {},
'username' => 'john'
};
RPC SERVER SENDING RESULT: $VAR1 = {
'sid' => '6226d3bc4a70cce30a15448bed557dde',
'dom' => bless( do{(my $o = 168155464)},
'XML::LibXML: ocument'
),
'styles' => [
{
'params' => {},
'style' => 'menu.xsl'
},
{
'params' => {},
'style' => 'start.xsl'
},
{
'params' => {
'css' =>
'main.css'
},
'style' => 'common.xsl'
}
]
};
------------------------------------------------------------
---------
To unsubscribe, e-mail: axkit-users-unsubscribe axkit.org
For additional commands, e-mail: axkit-users-help axkit.org
|