[Xml-compile] Transport::SOAPHTTP header option

Gary Kennedy gary at apnic.net
Mon Nov 28 22:41:08 GMT 2011


I managed to get very similar code, but more playing this morning has shown that I only need create the user agent and then pass "user_agent => $ua" to compileClient/compileCalls and the transport layer takes care of itself.

I'd still use the text you have for the FAQ as it shows how to deal with the transport guts quite comprehensively, but maybe include a short bit about being able to use the user_agent option as a short-cut.

Cheers,
Gary

BTW - Ignore what I said about the header option before. I realise now that they should be set quite differently.

On 29/11/2011, at 7:08 AM, Mark Overmeer wrote:

> * Michael Ludwig (m.ludwig at epages.com) [111128 09:35]:
>>> So, my main question now is: How can I set/get cookies before/after a
>>> SOAP call?
>> 
>> Take control of the user agent to configure it and have it eat
>> as many cookies as you want.
> 
> 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?
> 
>  MarkOv
> 
> =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.
> 
> 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);
> 
>  # 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>.
> 
> _______________________________________________
> Xml-compile mailing list
> Xml-compile at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/xml-compile

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2876 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20111129/e4d9950f/smime.bin


More information about the Xml-compile mailing list