AMF-Connection
view release on metacpan or search on metacpan
lib/AMF/Connection.pm view on Meta::CPAN
};
# TODO
#
# sub command { } - to send "flex.messaging.messages.CommandMessage" instead
#
sub setCredentials {
my ($class, $username, $password) = @_;
$class->addHeader( 'Credentials', { 'userid' => $username,'password' => $password }, 0 );
};
sub _process_response_headers {
my ($class,$message) = @_;
foreach my $header (@{ $message->getHeaders()}) {
if($header->getName eq 'ReplaceGatewayUrl') { # another way used by server to keep cookies-less sessions
$class->setEndpoint( $header->getValue )
unless( ref($header->getValue) );
} elsif($header->getName eq 'AppendToGatewayUrl') { # generally used for cokies-less sessions E.g. ';jsessionid=99226346ED3FF5296D08146B02ECCA28'
$class->{'append_to_endpoint'} = $header->getValue
unless( ref($header->getValue) );
};
};
};
# just an hack to avoid rewrite class mapping local-to-remote and viceversa and make Storable::AMF happy
sub _brew_flex_remoting_message {
my ($class,$source,$operation,$headers,$body,$destination) = @_;
return bless( {
'clientId' => _generateID(),
'destination' => $destination,
'messageId' => _generateID(),
'timestamp' => time() . '00',
'timeToLive' => 0,
'headers' => ($headers) ? $headers : {},
'body' => $body,
'correlationId' => undef,
'operation' => $operation,
'source' => $source # for backwards compatibility - google for it!
}, 'flex.messaging.messages.RemotingMessage' );
};
sub _generateID {
my $uniqueid;
if($HASUUID) {
eval {
my $ug = new Data::UUID;
$uniqueid = $ug->to_string( $ug->create() );
};
} elsif ($HASMD5) {
eval {
$uniqueid = substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32);
};
} else {
$uniqueid ="";
my $length=16;
my $j;
for(my $i=0 ; $i< $length ;) {
$j = chr(int(rand(127)));
if($j =~ /[a-zA-Z0-9]/) {
$uniqueid .=$j;
$i++;
};
};
};
return $uniqueid;
};
1;
__END__
=head1 NAME
AMF::Connection - A simple library to write AMF clients.
=head1 SYNOPSIS
use AMF::Connection;
my $endpoint = 'http://myserver.com/flex/amf/'; #AMF server/gateway
my $service = 'myService';
my $method = 'myMethod';
my $client = new AMF::Connection( $endpoint );
$client->setEncoding(3); # use AMF3 default AMF0
$client->setHTTPCookieJar( HTTP::Cookies->new(file => "/tmp/mycookies.txt", autosave => 1, ignore_discard => 1 ) );
my @params = ( 'param1', { 'param2' => 'value2' } );
my $response = $client->call( "$service.$method", \@params );
if ( $response->is_success ) {
my $result_object = $response->getData();
# ...
} else {
die "Can not send remote request for $service.$method method on $endpoint\n";
};
my @response = $client->callBatch ( { "operation" => $service.$method", "arguments" => \@params }, ... );
=head1 DESCRIPTION
I was looking for a simple Perl module to automate data extraction from an existing Flash+Flex/AMS application, and I could not find a decent client implementation. So, this module was born based on available online documentation.
This module has been inspired to SabreAMF PHP implementation of AMF client libraries.
AMF::Connection is meant to provide a simple AMF library to write client applications for invocation of remote services as used by most flex/AIR RIAs.
The module includes basic support for synchronous HTTP/S based RPC request-response access, where the client sends a request to the server to be processed and the server returns a response to the client containing the processing outcome. Data is sent...
AMF0 and AMF3 support is provided using the Storable::AMF module. While HTTP/S requestes to the AMF endpoint are carried out using the LWP::UserAgent module. The requests are sent using the HTTP POST method as AMF0 encoded data by default. AMF3 encod...
If encoding is set to AMF3 the Flex Messaging framework is used on returned responses content (I.e. objects casted to "flex.messaging.messages.AcknowledgeMessage" and "flex.messaging.messages.ErrorMessage" are returned).
( run in 0.908 second using v1.01-cache-2.11-cpan-140bd7fdf52 )