<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} p
        {margin-top:0;
        margin-bottom:0}--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi Mark,</p>
<p>this is my first post.</p>
<p>I'm using your XML::Compile (superb) Library quite a long time now, and stumpled upon
</p>
<p>XML::Compile::Transport::SOAPHTTP_MojoUA last year.</p>
<p>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.</p>
<p>The<span style="color:black"> current release don't take advantage of the latest version of Mojolicious which has got improvements over the last 2 years !<br>
</span></p>
<p><span style="color:black">Perhaps you want consider an update to use promises and the delay loop ?<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<p><span style="color:black">Anyhow, right now, i patched the version you provide and added:<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<p><span style="color:black">_prepare_call sync req:<br>
</span></p>
<p><span style="color:black"># async call<br>
sub {<br>
my ($content, $trace, $mtom, $callback) = @_;<br>
my $promise = Mojo::IOLoop->delay;<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<p><span style="color:black">start ua (promises):<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<p><span style="color:black">$ua->start(<br>
$tx => sub {<br>
my ($ua, $tx) = @_;<br>
my $err = $tx->error;<br>
$promise->resolve($tx) if !$err || $err->{code};<br>
$promise->reject($err->{message});<br>
$handler->($tx);<br>
}<br>
);<br>
return $promise;<br>
</span></p>
<p><span style="color:black">};<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<p><span style="color:black">Demo script (HWG SMS Modem):<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<p><span style="color:black">#!/usr/bin/env perl<br>
<br>
use Mojo::Base -strict;<br>
</span></p>
<p><span style="color:black">use Mojo::Util qw(dumper b64_encode);<br>
use Mojo::IOLoop::Delay;<br>
use XML::Compile::WSDL11;<br>
use XML::Compile::SOAP11; # use SOAP version 1.1<br>
use XML::Compile::Transport::SOAPHTTP_MojoUA;<br>
<br>
#use Log::Report mode => 'DEBUG'; # or 'VERBOSE'<br>
<br>
sub soap {<br>
my $username = q{api};<br>
my $password = q{xxxxxxxxxxxxxxxxxxxxx};<br>
my $authorization = sprintf("Basic %s", b64_encode(qq{$username:$password}));<br>
my $wsdl = XML::Compile::WSDL11->new(q{/etc/hwg-sms-gateway/wsdl/hwg.wsdl});<br>
my $trans = XML::Compile::Transport::SOAPHTTP_MojoUA->new(<br>
connect_timeout => 2,<br>
request_timeout => 2,<br>
address => q{http://10.1.1.1/service.xml}<br>
);<br>
return $wsdl->compileCalls(<br>
transport => $trans,<br>
async => 1,<br>
method => q{POST},<br>
user_agent => qq{SMS-Agent/1.0},<br>
authorization => $authorization<br>
);<br>
}<br>
<br>
sub start {<br>
my $wsdl = soap();<br>
my $d = Mojo::IOLoop::Delay->new;<br>
<br>
$d->steps(<br>
sub {<br>
my $delay = shift;<br>
my $cb = $delay->begin;<br>
my $promise = $wsdl->call(<br>
QueueStatus => {<br>
Queue => q{GsmIn},<br>
_callback => sub {<br>
my ($xmlout, $trace) = @_;<br>
$delay->pass($xmlout);<br>
$cb->();<br>
}<br>
}<br>
);<br>
$promise->then(sub {<br>
my $promise = shift;<br>
})->catch(sub {<br>
my $err = shift;<br>
printf(STDERR "ERROR: %s\n", dumper $err);<br>
})->wait;<br>
},<br>
<br>
sub {<br>
my ($delay, $result) = @_;<br>
printf("DELAY LAST RECEIVED: %s\n", dumper $result);<br>
}<br>
)->wait;<br>
}<br>
<br>
start();<br>
<br>
1;<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<p><span style="color:black">Produces:<br>
</span></p>
<p><span style="color:black">DELAY LAST RECEIVED: {<br>
"response" => {<br>
"Cnt" => 0,<br>
"IdSet" => {},<br>
"Max" => 25,<br>
"Missed" => 0,<br>
"Rslt" => 0<br>
}<br>
}<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<p><span style="color:black">I would be great to have a state of the art version of this module.<br>
</span></p>
<p><span style="color:black">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.<br>
</span></p>
<p><span style="color:black">When using multiple concurrent promises, you cannot tell what have been called but to examine $tx-res->headers !<br>
</span></p>
<p><span style="color:black">Which i did, i use it in a production env for one year now.<br>
</span></p>
<p><span style="color:black">To be consistent, i only wanted to inform you about the changes in Mojolicious and what can be accomplished nowadways.<br>
</span></p>
<p><span style="color:black"><br>
</span></p>
<span style="color:black">Kind regards Franz</span>
</body>
</html>