|
NAMEXML::Compile::Transport - base class for XML transportersINHERITANCEXML::Compile::Transport is a XML::Compile::SOAP::Extension XML::Compile::Transport is extended by XML::Compile::Transport::SOAPHTTP XML::Compile::Transport::SOAPHTTP_AnyEvent SYNOPSISuse XML::Compile::Transport::SOAPHTTP; my $trans = XML::Compile::Transport::SOAPHTTP->new(...); my $call = $trans->compileClient(...); my ($xmlout, $trace) = $call->($xmlin); my $xmlout = $call->($xmlin); # when no trace needed DESCRIPTIONThis module defines the exchange of (XML) messages. The module does not known how to parse or compose XML, but only worries about the transport aspects.On the moment, there are three transporter implementations:
Extends "DESCRIPTION" in XML::Compile::SOAP::Extension. METHODSExtends "METHODS" in XML::Compile::SOAP::Extension.ConstructorsExtends "Constructors" in XML::Compile::SOAP::Extension.
WSDL11Extends "WSDL11" in XML::Compile::SOAP::Extension.
SOAP11Extends "SOAP11" in XML::Compile::SOAP::Extension.
SOAP12Extends "SOAP12" in XML::Compile::SOAP::Extension.
Accessors
Handlers
DETAILSUse of the transport hookA transport hook can be used to follow the process of creating a message to its furthest extend: it will be called with the data as used by the actual protocol, but will not connect to the internet. Within the transport hook routine, you have to simulate the remote server's activities.There are two reasons to use a hook:
XML and Header Modifications Some servers require special extensions, which do not follow any standard (or logic). But even those features can be tricked, although it requires quite some programming skills. The "transport_hook" routine is called with a $trace hash, one of whose entries is the UserAgent which was set up for the data transfer. You can modify the outgoing message XML body and headers, carry out the data exchange using the UserAgent, and then examine the returned Response for content and headers using methods similar to the following: sub transport_hook($$$) { my ($request, $trace, $transporter) = @_; my $content = $request->content; # ... modify content if you need my $new_content = encode "UTF-8", $anything; $request->content($new_content); $request->header(Content_Length => length $new_content); $request->header(Content_Type => 'text/plain; charset=UTF-8'); # ... update the headers $request->header(Name => "value"); # sent the request myself my $ua = $trace->{user_agent}; my $response = $ua->request($request); # ... check the response headers my $name = $response->header('Name'); # ... use the response content my $received = $response->decoded_content || $response->content; $response; } You should be aware that if you change the size or length of the content you MUST update the "Content-Length" header value, as demonstrated above. Transport hook for debugging The transport hook is a perfect means for producing automated tests. Also, the XML::Compile::SOAP module tests use it extensively. It works like this (for the SOAPHTTP simluation): use Test::More; sub fake_server($$) { my ($request, $trace) = @_; my $content = $request->decoded_content; is($content, <<__EXPECTED_CONTENT); <SOAP-ENV:Envelope>...</SOAP-ENV:Envelope> __EXPECTED_CONTENT HTTP::Response->new(200, 'Constant' , [ 'Content-Type' => 'text/xml' ] , <<__ANSWER <SOAP-ENV:Envelope>...</SOAP-ENV:Envelope> __ANSWER } Then, the fake server is initiated in one of the follow ways: my $transport = XML::Compile::Transport::SOAPHTTP->new(...); my $http = $transport->compileClient(hook => \&fake_server, ...); $wsdl->compileClient('GetLastTracePrice', transporter => $http); or my $soap = XML::Compile::SOAP11::Client->new(...); my $call = $soap->compileClient(encode => ..., decode => ..., transport_hook => \&fake_server); or my $wsdl = XML::Compile::WSDL11->new(...); $wsdl->compileClient('GetLastTracePrice', transport_hook => \&fake_server); Transport hook for basic authentication [Adapted from an example contributed by Kieron Johnson] This example shows a transport_hook for compileClient() to add to http headers for the basic http authentication. The parameter can also be used for compileAll() and many other related functions. my $call = $wsdl->compileClient($operation , transport_hook => \&basic_auth ); # HTTP basic authentication encodes the username and password with # Base64. The encoded source string has format: "username:password" # With the below HTTP header being required: # "Authorization: Basic [encoded password]" use MIME::Base64 'encode_base64'; my $user = 'myuserid' ; my $password = 'mypassword'; sub basic_auth($$) { my ($request, $trace) = @_; # Encode userid and password my $authorization = 'Basic '. encode_base64 "$user:$password"; # Modify http header to include basic authorisation $request->header(Authorization => $authorization ); my $ua = $trace->{user_agent}; $ua->request($request); } Helpers
SEE ALSOThis module is part of XML-Compile-SOAP distribution version 3.27, built on April 07, 2021. Website: http://perl.overmeer.net/CPAN/LICENSECopyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/
Visit the GSP FreeBSD Man Page Interface. |