AMF-Connection
view release on metacpan or search on metacpan
- tests
- more documentation
- more testing
- look into results/class mapping
examples/amfclient.pl view on Meta::CPAN
use AMF::Connection;
use HTTP::Cookies;
use JSON;
BEGIN
{
no strict 'refs';
# blessed hash object to JSON object
map
{
my $amf_class = $_;
my $foo = $amf_class."::TO_JSON";
# unbless object
*$foo = sub {
my $f = $_[0];
#process_amf_object ($f, $amf_class);
+{ %{$f} };
}
} (
# add your own remote service classes here - or use an SWFDecompiler
'flex.messaging.messages.AcknowledgeMessage'
);
# blessed hash object to JSON array
map
{
my $foo = $_."::TO_JSON";
# unbless
*$foo = sub {
$_[0]->{'externalizedData'};
}
} (
'flex.messaging.io.ArrayCollection'
);
}
examples/get-brightcove-videos-metadata.pl view on Meta::CPAN
# see http://code.google.com/p/get-flash-videos/
use AMF::Connection;
use JSON;
BEGIN
{
no strict 'refs';
# blessed hash object to JSON object
map
{
my $amf_class = $_;
my $foo = $amf_class."::TO_JSON";
# unbless object
*$foo = sub {
my $f = $_[0];
#process_amf_object ($f, $amf_class);
examples/get-brightcove-videos-metadata.pl view on Meta::CPAN
'com.brightcove.templating.SecondaryContentDTO',
'com.brightcove.templating.FeaturedItemDTO',
'com.brightcove.catalog.trimmed.VideoDTO',
'com.brightcove.utils.BrightcoveDateDTO',
'com.brightcove.catalog.TagDTO',
'com.brightcove.catalog.VideoCuePointDTO'
);
# blessed hash object to JSON array
map
{
my $foo = $_."::TO_JSON";
# unbless
*$foo = sub {
$_[0]->{'externalizedData'};
}
} (
'flex.messaging.io.ArrayCollection'
);
}
lib/AMF/Connection.pm view on Meta::CPAN
return (wantarray) ? @call : $call[0];
};
sub callBatch {
my ($class, @batch) = @_;
my $request = new AMF::Connection::Message;
$request->setEncoding( $class->{'encoding'} );
# add AMF any request headers
map { $request->addHeader( $_ ); } @{ $class->{'headers'} };
# TODO - prepare HTTP/S request headers based on AMF headers received/set if any - and credentials
foreach my $call (@batch)
{
next
unless (defined $call && ref ($call) =~ m/HASH/
&& defined $call->{'operation'} && defined $call->{'arguments'});
my $operation = $call->{'operation'};
lib/AMF/Connection.pm view on Meta::CPAN
my $request_stream = new AMF::Connection::OutputStream($class->{'output_amf_options'});
# serialize request
$request->serialize($request_stream);
#use Data::Dumper;
#print STDERR Dumper( $request );
# set any extra HTTP header
map { $class->{'ua'}->default_header( $_ => $class->{'http_headers'}->{$_} ); } keys %{ $class->{'http_headers'} };
my $http_response = $class->{'ua'}->post(
$class->{'endpoint'}.$class->{'append_to_endpoint'}, # TODO - check if append to URL this really work for HTTP POST
Content_Type => "application/x-amf",
Content => $request_stream->getStreamData()
);
croak "HTTP POST error: ".$http_response->status_line."\n"
unless($http_response->is_success);
lib/AMF/Connection.pm view on Meta::CPAN
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 : {},
lib/AMF/Connection.pm view on Meta::CPAN
=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).
Simple batch requests and responses is provided also.
See the sample usage synopsis above to start using the module.
=head1 DATE TYPE SUPPORT
The latest 0.79 version of Storable::AMF added basic date support with the new_date() and perl_date() utilitiy functions. This is just great. Internally an AMF Date Type represents a timestamp in milliseconds since the epoch in UTC ("neutral") timezo...
lib/AMF/Connection.pm view on Meta::CPAN
There is still an issue when arbitrary Date structures are returned from an AMF server to an AMF::Connection (E.g. as part of values of structured AMF Objects). In this case, the AMF::Connection does not try to reparse the Perl object structure retur...
All this means that an AMF::Connection client application can not rely on those Date returned by the server as being Perl timestamps (seconds since the epoch) and will need explicitly call perl_date() or divide the timestamp by 1000 *explicitly*.
=head2 USING OLD Storable::AMF VERSIONS
In older versions (pre 0.79) of Storable::AMF there was no support for the AMF0/AFM3 Date Type, and everything was being passed as string to the server (E.g. "2010-09-22T02:34:00"). Or as double (number) if the date was in timestamp seconds since the...
=head1 MAPPING OBJECTS
By combining the power of Perl bless {}, $package_name syntax and the Storable::AMF freeze()/thaw() interface, it is possible to pass arbitrary structured AMF Objects the corresponding AMF server can interpret. This is possible due a simple Perl obje...
This means that an AMF::Connection application can wrap all ActionScript / Flex AMF Objects around Perl Objects and get them sent; and returned into a Perl object BLOB using the power of Storable::AMF freeze()/thaw().A
For example to send a SearchQueryFx AMF Object to the server an AMF::Connection advanced search call(), the following code could be used:
my $client = new AMF::Connection ( ... );
# ... prepare parameters...
my $searchAMFObject = bless( {
lib/AMF/Connection.pm view on Meta::CPAN
'startHit' => int($startHit),
'searchString' => $searchString,
'hitsPerPage' => ($hitsPerPage) ? int($hitsPerPage) : 20,
'sortId' => $sortId,
}, 'com.mycompany.application.flex.data.SearchQueryFx');
my $response = $client->call( "MySearchSevice.searchAdvanced", [ $searchAMFObject ] );
#....
For other Java to ActionScript type mappings possibilities see http://livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/io/amf/ActionMessageOutput.html#writeObject(java.lang.Object)
For PHP gateways at the moment there is not a known/documented way to map client to server objects.
Future versions of AMF::Connection may add a proper configurable factory for application specific ActionScript/Flex object mappings.
=head1 METHODS
=head2 new ($endpoint)
Create new AMF::Connection object. An endpoint can be specified as the only parameter. Or set in a second moment with the setEndpoint() method.
=head2 call ($operation, $arguments)
Call the remote service method with given parameters/arguments on the set endpoint and return an AMF::Connection::MessageBody response. Or an array of responses if requsted (wantarray call scope). The $arguments is generally an array reference, but t...
lib/AMF/Connection/MessageBody.pm view on Meta::CPAN
use Carp;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my ($target,$response,$data) = @_;
my $self = {
'target' => $target,
'response' => $response,
'data' => $data # we might want to have some kind of mapper between remote objects and local / user registered ones
};
return bless($self, $class);
};
sub setTarget {
my ($class, $target) = @_;
$class->{'target'} = $target;
};
( run in 0.546 second using v1.01-cache-2.11-cpan-49f99fa48dc )