XML::C...ansport(3pm)
π NAME π
XML::Compile::Transport β the base class for XML transporters, bestie π
πΈ INHERITANCE πΈ
okay so the family tree is giving dynasty energy:
XML::Compile::Transport
is a XML::Compile::SOAP::Extension
XML::Compile::Transport is extended by
XML::Compile::Transport::SOAPHTTP
XML::Compile::Transport::SOAPHTTP_AnyEvent
β¨ SYNOPSIS β¨
use 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
π¦ DESCRIPTION π¦
So this module is the one that handles the exchange of (XML) messages. Lowkey important: it does not know how to parse or compose XML at all β it's literally only worried about the transport aspects. That's it, that's the job π
Right now there are three transporter implementations:
XML::Compile::Transport::SOAPHTTPβ implements an synchronous message exchange; the library waits for an answer before it returns to the user application. The information is exchanged using HTTP with SOAP encapsulation (SOAP also defines a transport protocol over HTTP without encapsulation)XML::Compile::Transport::SOAPHTTP_AnyEventβ Event-driven implementation, based on AnyEvent. The user provides a callback to handle responses. Many queries can be spawned in parallel, in a single process. Find this in a separate distribution.XML::Compile::Transport::SOAPHTTP_MojoUAβ Event-driven implementation, which fits in the Mojolicious infrastructure. Find this in a separate distribution.
Extends "DESCRIPTION" in XML::Compile::SOAP::Extension.
π METHODS π
Extends "METHODS" in XML::Compile::SOAP::Extension.
π Constructors
Extends "Constructors" in XML::Compile::SOAP::Extension.
XML::Compile::Transport->new(%options)
the defaults table, iconic as always:
-Option --Default
address 'http://localhost'
charset 'UTF-8'
address=> URI|ARRAY-of-URI β One or more URI which represents the servers. (defaults to'http://localhost')charset=> STRING β (defaults to'UTF-8')
π«Ά WSDL11
Extends "WSDL11" in XML::Compile::SOAP::Extension.
$obj->wsdl11Init($wsdl, $args)XML::Compile::Transport->wsdl11Init($wsdl, $args)
Inherited, see "WSDL11" in XML::Compile::SOAP::Extension
π SOAP11
Extends "SOAP11" in XML::Compile::SOAP::Extension.
$obj->soap11ClientWrapper($operation, $call, $args)β Inherited, see "SOAP11" in XML::Compile::SOAP::Extension$obj->soap11HandlerWrapper($operation, $callback, $args)β Inherited, see "SOAP11" in XML::Compile::SOAP::Extension$obj->soap11OperationInit($operation, $args)XML::Compile::Transport->soap11OperationInit($operation, $args)
Inherited, see "SOAP11" in XML::Compile::SOAP::Extension
π SOAP12
Extends "SOAP12" in XML::Compile::SOAP::Extension.
$obj->soap12ClientWrapper($operation, $call, $args)β Inherited, see "SOAP12" in XML::Compile::SOAP::Extension$obj->soap12HandlerWrapper($operation, $callback, $args)β Inherited, see "SOAP12" in XML::Compile::SOAP::Extension$obj->soap12OperationInit($operation, $args)XML::Compile::Transport->soap12OperationInit($operation, $args)
Inherited, see "SOAP12" in XML::Compile::SOAP::Extension
β Accessors
$obj->address()β Get a server address to contact. If multiple addresses were specified, than one is chosen at random.$obj->addresses()β Returns a list of all server contact addresses (URIs)$obj->charset()β Returns the charset to be used when sending,
π Handlers
$obj->compileClient(%options)
Compile a client handler. Returned is a subroutine which is called with a text represenation of the XML request, or an XML::LibXML tree. In SCALAR context, an XML::LibXML parsed tree of the answer message is returned. In LIST context, that answer is followed by a HASH which contains trace information.
-Option --Default
hook <undef>
kind 'request-response'
xml_format 0
hook=> CODE β See section "Use of the transport hook". When defined, the hook will be called, in stead of transmitting the message. The hook will gets three parameters passed in: the textual representation of the XML message to be transmitted, the trace HASH with all values collected so far, and the transporter object. The trace HASH will have a massive amount of additional information added as well.
You may add information to the trace. You have to return a textual representation of the XML answer, or "undef" to indicate that the message was totally unacceptable.
(default: <undef>)
kind=> STRING β Kind of communication, as defined by WSDL. (default:'request-response')xml_format=> 0|1|2 β[2.26]See XML::LibXML::Document subroutinetoString. With'1', you will get beautified output. (default:0)
π₯ DETAILS π₯
π§ Use of the transport hook
A 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:
- You want to fake a server, to produce a test environment.
- You may need to modify the request or answer messages outside the reach of
XML::Compile::SOAP, because something is wrong in either your WSDL ofXML::Compilemessage processing.
π 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;
}
π¨ bestie listen to me: 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. No cap, do not skip this step π
π 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
XML::Compile::Transport->register($uri)β Declare an transporter type.
π¦ SEE ALSO π¦
This module is part of XML-Compile-SOAP distribution version 3.28, built on August 01, 2022. Website: http://perl.overmeer.net/CPAN/
π LICENSE π
Copyrights 2007-2022 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/
okay bestie that's the whole page, we ate and left zero crumbs π this was perl v5.34.0, dated 2022-08-04, and yes the manual page name really is XML::C...ansport(3pm) β no notes, that's just how it printed πβ¨π¦
π¦ where this page comes from
- debian bookworm: libxml-compile-soap-perl 3.28+ds-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libxml-compile-soap-perl 3.28+ds-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libxml-compile-soap-perl 3.28+ds-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libxml-compile-soap-perl 3.28+ds-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libxml-compile-soap-perl 3.28+ds-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms