[Xml-compile] XML::Compile::Transport::SOAPHTTP_MojoUA very outdated (Mojo::Promise patch and further questions) !
Skale Franz
franz.skale at citycom-austria.com
Fri Dec 14 11:23:21 GMT 2018
Hi Mark,
this is my first post.
I'm using your XML::Compile (superb) Library quite a long time now, and stumpled upon
XML::Compile::Transport::SOAPHTTP_MojoUA last year.
It's very outdated so i patched it to use Mojo::Promise and Mojo::IOLoop::Delay to get flow control over the use of Non-Blocking I/O.
The current release don't take advantage of the latest version of Mojolicious which has got improvements over the last 2 years !
Perhaps you want consider an update to use promises and the delay loop ?
Anyhow, right now, i patched the version you provide and added:
_prepare_call sync req:
# async call
sub {
my ($content, $trace, $mtom, $callback) = @_;
my $promise = Mojo::IOLoop->delay;
start ua (promises):
$ua->start(
$tx => sub {
my ($ua, $tx) = @_;
my $err = $tx->error;
$promise->resolve($tx) if !$err || $err->{code};
$promise->reject($err->{message});
$handler->($tx);
}
);
return $promise;
};
Demo script (HWG SMS Modem):
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::Util qw(dumper b64_encode);
use Mojo::IOLoop::Delay;
use XML::Compile::WSDL11;
use XML::Compile::SOAP11; # use SOAP version 1.1
use XML::Compile::Transport::SOAPHTTP_MojoUA;
#use Log::Report mode => 'DEBUG'; # or 'VERBOSE'
sub soap {
my $username = q{api};
my $password = q{xxxxxxxxxxxxxxxxxxxxx};
my $authorization = sprintf("Basic %s", b64_encode(qq{$username:$password}));
my $wsdl = XML::Compile::WSDL11->new(q{/etc/hwg-sms-gateway/wsdl/hwg.wsdl});
my $trans = XML::Compile::Transport::SOAPHTTP_MojoUA->new(
connect_timeout => 2,
request_timeout => 2,
address => q{http://10.1.1.1/service.xml}
);
return $wsdl->compileCalls(
transport => $trans,
async => 1,
method => q{POST},
user_agent => qq{SMS-Agent/1.0},
authorization => $authorization
);
}
sub start {
my $wsdl = soap();
my $d = Mojo::IOLoop::Delay->new;
$d->steps(
sub {
my $delay = shift;
my $cb = $delay->begin;
my $promise = $wsdl->call(
QueueStatus => {
Queue => q{GsmIn},
_callback => sub {
my ($xmlout, $trace) = @_;
$delay->pass($xmlout);
$cb->();
}
}
);
$promise->then(sub {
my $promise = shift;
})->catch(sub {
my $err = shift;
printf(STDERR "ERROR: %s\n", dumper $err);
})->wait;
},
sub {
my ($delay, $result) = @_;
printf("DELAY LAST RECEIVED: %s\n", dumper $result);
}
)->wait;
}
start();
1;
Produces:
DELAY LAST RECEIVED: {
"response" => {
"Cnt" => 0,
"IdSet" => {},
"Max" => 25,
"Missed" => 0,
"Rslt" => 0
}
}
I would be great to have a state of the art version of this module.
What i also needs is a option (extra_opts) to add custom headers to the request which can be parsed by the Mojo::Promise object.
When using multiple concurrent promises, you cannot tell what have been called but to examine $tx-res->headers !
Which i did, i use it in a production env for one year now.
To be consistent, i only wanted to inform you about the changes in Mojolicious and what can be accomplished nowadways.
Kind regards Franz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20181214/000cb1bf/attachment.htm>
More information about the Xml-compile
mailing list