Java Sample 4:
Decoding Vendor Codes
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. -
A sample of a proxy created by VisualStudio.NET is available in the Sample Site.
-
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.
-
Create a function, TravelCodesController, 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.
|
package com.galileo.GWSGettingStarted; |
|
import java.text.MessageFormat; |
|
import java.util.Enumeration; |
|
import java.util.HashMap; |
|
import java.util.Hashtable; |
|
|
|
import org.w3c.dom.Element; |
|
import org.w3c.dom.NodeList; |
|
|
|
import com.galileo.webservices.TravelCodeServiceLocator; |
|
import com.galileo.webservices.TravelCodeServiceSoapStub; |
|
|
Declares the TravelCodesController class, which manages the Travel Codes Translator eBL request. |
public class TravelCodesController { |
Creates and sends requests. |
public Element CreateRequest(Element availResponse) |
|
{ |
Retrieves the record locator from the booking response. |
NodeList airvNodes = availResponse.getElementsByTagName("AirV"); |
Builds a hash table for the requests. |
Hashtable vendors = new Hashtable(); |
for (int ii=0;ii<airvNodes.getLength();++ii) |
|
Selects the first air segment from a valid air availability response. Use a DOM to create the request. |
{ |
String AirV = airvNodes.item(ii).getFirstChild().getNodeValue(); |
|
if (!vendors.containsKey(AirV)) |
|
{ |
|
vendors.put(AirV, "Airline"); |
|
} |
|
|
} |
The Travel Codes Translator eBL request to Decode. Note:
A The namespace is defined in the WSDL, whether ns.galileo.com or webservices.galileo.co |
StringBuffer req = new StringBuffer(); |
req.append("<Decode xmlns='http://ns.galileo.com'>"); |
|
for (Enumeration vendorEnum = vendors.keys();vendorEnum.hasMoreElements();) |
|
{ |
|
String AirV = (String) vendorEnum.nextElement(); |
|
req.append(MessageFormat.format("<{1}
Code=\"{0}\" />", |
|
} |
|
req.append("</Decode>"); |
|
|
return Util.string2Element(req.toString()); |
|
} |
Makes the translation request. |
public Element doTranslate(Element request) |
|
{ |
Instantiates the locator. |
TravelCodeServiceLocator tservice = new TravelCodeServiceLocator(); |
|
Element response = null; |
|
try |
|
{ |
Uses the service to get a stub that implements the SDI. |
TravelCodeServiceSoapStub
translator = (TravelCodeServiceSoapStub) |
The user name and password are assigned by Galileo. |
translator.setUsername(USER_NAME); |
translator.setPassword(PASSWORD); |
|
|
response = translator.Decode( request); |
|
} |
Exception handling. |
catch (Exception e) |
|
{ |
|
System.err.println(e.getMessage()); |
|
e.printStackTrace(System.err); |
|
} |
|
return response; |
|
} |
Declares the constants. Ensure URL is specific to your region or service level. |
private
final String TRAVEL_CODE_URL = |
private final String USER_NAME = System.getProperty("USER_NAME"); |
|
private final String PASSWORD = System.getProperty("PASSWORD"); |
|
private final String APOLLO_HAP = System.getProperty("APOLLO_HAP"); |
|
|
} |
-
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> |