AW: [Xml-compile] Transport::SOAPHTTP header option

Michael Ludwig m.ludwig at epages.com
Tue Nov 29 14:39:53 GMT 2011


> Von: Mark Overmeer [mailto:mark at overmeer.net]
> Gesendet: Montag, 28. November 2011 22:08

> It is a recurring question. I have now taken your example, Michael, and
> extended it a bit for the XML::Compile::SOAP::FAQ  This is the text I
> have now... Comments?

Great - please see my additions inline.

Best,

Michael

> =head3 Adding HTTP headers
> 
> Some applications require to add headers to the HTTP headers sent or
> check headers which are received. SOAP is not about HTTP, so you have
> to dive deeper in the underlaying constructs; you have to construct the
> code references in more steps, not using the auto-generation mechanisms
> of some objects, by default hidden to you.

  A typical example of such a need for control is interfacing to a
  web service that requires the client to use cookies in order to
  store an authentication token obtained from some kind of login call
  and to be producent on subsequented requests to protected calls.

> The ::WSDL11 module detects that the soap-http protocol is needed.
> (There is also a pure http protocol defined in the SOAP spec, which
> is never used)  When the operation gets compiled (with compileClient),
  -----------> . <---

> the ::SOAPHTTP module is used to create the soap-http specific message
> transport logic. On its turn, that module uses LWP to do the actual
> HTTP exchange. To be able to access the in- and outgoing messages,
> you have to reach to that LWP::UserAgent.
> 
> Michael Ludwig contributed the following example (slightly adapted)
> 
>   my $ua = LWP::UserAgent->new;
> 
>   # First the HTTP logic
>   # defaults when SSL is used
>   $ua->ssl_opts(verify_hostname => 0, keep_alive => 1);

Actually, I put verify_hostname just as an example. Let's say that
for developing you're dealing with a test server featuring a self-
signed certificate ... then such action is needed.

As for keep_alive, I think it's generally a good idea if you intend
to make more than one call.

Not sure what you intend your comment above the statement to convey,
though ...

>   # Auto-use cookies
>   $ua->cookie_jar( {file => $my_jar_file
>     , autosave => 1, ignore_discard => 1 });
> 
>   # Now, we need the SOAP logic
>   my $trans = XML::Compile::Transport::SOAPHTTP
>     ->new(user_agent => $ua, timeout => 10, address => $srv_url);
> 
>   # Finally the message, with explicit transporter
>   my $call = $wsdl->compileClient($opname, transport => $trans);
> 
>   # $answer is the decoded XML content.
>   my($answer, $trace) = $call->( \%parms );
> 
>   # If you need headers from the response HTTP headers.
>   my $http_response = $trace->response;
>   print $http_response->header('X-Secret');
> 
> You may know the C<$srv_url> to get the address of the server, but
> you can also ask the operation itself. Here a different implementation:
> 
>   my $op    = $wsdl->operation($opname);
>   my $srv   = ($op->addresses)[0];
>   my $trans = XML::Compile::Transport::SOAPHTTP->new(address => $srv);
> 
>   # Now configure the userAgent
>   my $ua    = $trans->userAgent;
>   ...
> 
>   my $call  = $op->compileClient(transport => $trans);
>   ...
> 
> The L<LWP::UserAgent> has many useful hooks (<i>Handlers</i>), for
> instance C<request_send> and C<response_done>.

Indeed ... can't believe I've remained unaware of them for such a
long time!

Thanks for this fine library.

Michael



More information about the Xml-compile mailing list