This example takes encoded air vendor names from the air availability response in Sample 1, and decodes them into human language using Travel Codes Translator eBL.
Create a proxy
of the XML Select Web Service, using a WSDL for your region or service
level. For example:
https://americas.copy-webservices.travelport.com/B2BGateway/service/TravelCodesTranslator?WSDL.
Most toolkits do not explicitly support proxies that connect to a Web Service via a secured firewall. See Connecting to Galileo Web Services for more details about working with proxy servers and other authentication issues.
Full Perl sample files are available at the Sample Site.
Create a Translate controller, which formats an XML template, retrieves the required data from the AirAvailability_6_5 response, and sets the parameters for the request. The following code also contains proxy server credentials that are included with the request to bypass the firewall.
Declares the TravelCodes controller class, which manages the Travel Codes Translator eBL request. |
package Controllers::TravelCodes; |
|
use strict; |
|
use SOAP::Lite +trace => 'debug'; |
|
use XML::Simple; |
|
|
Creates
and sets up the credentials for Travel Codes Translator eBL. The user
name and password are assigned by Galileo.
|
our $USER_NAME = "USERNAME"; |
our $PASSWORD = "PASSWORD"; | |
sub SOAP::Transport::HTTP::Client::get_basic_credentials { | |
return $USER_NAME => $PASSWORD; | |
|
} |
|
|
The constructor for Travel Codes Translator eBL. |
sub new { |
|
my $type = shift; |
|
my $self = {}; |
Defines the Host Access Profile, which is required to access Galileo Web Services. |
$self->{ApolloHAP} = "Profile"; |
Declares and initializes variables for the required namespaces and Travel Codes Translator eBL endpoint. |
$self->{NAMESPACE} = 'http://webservices.galileo.com/TravelCodesTranslator'; |
$self->{ENDPOINT} = 'https://americas.copy-webservices.travelport.com/B2BGateway/service/TravelCodesTranslator'; | |
|
return bless $self, $type; |
|
} |
|
|
Builds an XML document using booking information from the first segment of the valid Air Availability response. |
sub BuildRequest |
{ | |
my $self = shift; | |
my $xmlAirAvail = shift; | |
Parses the Reservation Builder response and pull out the first flight segment. |
my $xs = new XML::Simple(); |
my $availRef = $xs->XMLin($xmlAirAvail); | |
my $flights = $availRef->{'soapenv:Body'} | |
->{SubmitXmlResponse} | |
->{SubmitXmlResult} | |
->{AirAvailability_6_2} | |
->{AirAvail} | |
->{AvailFlt}; | |
|
my $thisFlight; |
|
print "Flights=$flights"; |
|
|
Build a hash table for the requests, so that codes are only decoded once.
|
my %allVendors; |
for $thisFlight (@{$flights}) | |
{ | |
$allVendors{$thisFlight->{AirV}} = "Airline"; | |
$allVendors{$thisFlight->{StartAirp}} = "Airport"; | |
$allVendors{$thisFlight->{EndAirp}} = "Airport"; | |
$allVendors{$thisFlight->{Equip}} = "AircraftType"; | |
|
} |
|
|
|
my $req = ""; |
Makes the Flight Information eBL request. |
$req .= '<Decode xmlns=\'http://ns.galileo.com\'>'; |
Request for all flight segments. |
foreach my $code (sort keys %allVendors) |
|
{ |
Flight segment request. The <Flight> element is repeated as necessary for additional segments. |
$req .= "<$allVendors{$code} Code='$code' />"; |
|
} |
|
$req .='</Decode>'; |
|
|
|
return $req; |
|
} |
|
|
Submits the Flight Information eBL call. |
sub doTranslateCodes |
|
{ |
|
my $self = shift; |
Wraps the input parameters with the appropriate parameter names. SOAP::Lite does support this function for complex types, such as XML. |
my $request = '<DecodeInput>'.(shift).'</DecodeInput>'; |
Save the Request to this object. |
$self->{request} = $request; |
Instantiates the Itinerary Soap::Lite object. |
my $itineraryService = SOAP::Lite |
Sets the URL of the Soap Proxy. |
-> uri($self->{NAMESPACE}) |
By default, Soap::Lite uses the pound sign (#) to concatenate URLs. Replace the pound sign with a slash (/). |
-> on_action(sub{sprintf '%s/%s', @_ }) |
The default response is a hash value because the return type, xmlelement, is complex. Setting outputxml() to TRUE creates an XML response. |
-> outputxml("1") |
Sets the proxy endpoint to the Itinerary service. |
-> proxy($self->{ENDPOINT}); |
|
|
Assigns the return value of the Travel Code object's call to the Decode method. |
my $response = $itineraryService |
Sets the namespace for the Decode method parameters. |
->call(SOAP::Data->name("Decode")->attr({xmlns => $self->{NAMESPACE}}), |
Returns the response data as an XML element. |
SOAP::Data->name(DecodeInput => $request)->type('xml')); |
Saves the response to the object. |
$self->{response} = $response; |
|
return $response; |
|
} |
|
1; |
The Apollo or Galileo CRS returns the following data in a response.
Travel Codes Translator eBL decode response. |
<Decode Version="1.0.200303102232" xmlns="http://ns.galileo.com"> |
Lists the translation for each air vendor code listed in the request. |
<Airline Code="AA">American</Airline> |
<Airline Code="BD">bmi british</Airline> | |
<Airline Code="UA">United</Airline> | |
<Airline Code="US">US Airways</Airline> | |
Ends the Travel Codes Translator eBL response. |
</Decode> |