This sample uses response data from the air availability request in Sample 1 to book an air reservation. Booking calls can be made through either the Reservation Builder eBL or a combination of transactions in the XML Select Web Service. In this example, the booking call is made through a call to the Reservation Builder eBL, using the minimum data required to book an air reservation.
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/ReservationBuilder?WSDL.
A sample of a proxy created by Apache Axis is available at 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, BWSController, which formats an XML template, retrieves the required data from the AirAvailability_6_5 response and sets the parameters for the request, including a Booking Profile. This example assumes that the proxy server credentials have already been identified in the system properties. This method can be used in Apache Axis.
Notes:
BWSController also includes a Cancel Trip function, which is documented in Step 4.
The Reservation Builder eBL contains a ValidateInputs method, which can be used to validate the request against the XML schema. For brevity, this method is not included in the sample. However, the request data can be validated prior to calling the BookTrip method.
|
package com.galileo.GWSGettingStarted; |
import java.io.StringReader; | |
import java.text.MessageFormat; | |
import java.util.Calendar; | |
| |
import org.w3c.dom.Document; | |
import org.w3c.dom.Element; | |
import org.w3c.dom.NodeList; | |
| |
|
import com.galileo.webservices.*; |
|
|
Declares the BWSController class, which manages the Reservation Builder eBL request. |
public class BWSController { |
public BWSController() {} | |
Selects the first air segment from a valid air availability response. Use a DOM to create the request. |
public Element CreateRequest(Element xmlAirAvail) |
|
{ |
Retrieves the required booking information from the availability. |
NodeList allSegments = xmlAirAvail.getElementsByTagName("AvailFlt"); |
if (allSegments.getLength() ==0) | |
return null; | |
Element firstSegment = (Element)allSegments.item(0); | |
|
|
Gets the departure and arrival dates and times. GetText is a utility class that gets the content of the node pointed to by an XPath. Returns an empty string if there is no text or if the node does not exist. |
string dt = GetText(firstSegment, "StartDt"); |
string tm = GetText(firstSegment, "StartTm"); | |
Calendar departDateTime = parseHostDate(dt, tm); | |
| |
tm = GetText(firstSegment,"EndTm"); | |
Calendar arriveDateTime = parseHostDate(dt,tm); | |
arriveDateTime.add(Calendar.DATE, Integer.parseInt(GetText(firstSegment, "DayChg"))); | |
Gets the flight number. |
String flightNum = GetText(firstSegment, "FltNum"); |
Gets the departure airport. |
String departAirport = GetText( firstSegment, "StartAirp"); |
Gets the destination airport. |
String arriveAirport = GetText( firstSegment, "EndAirp"); |
Gets the airline vendor. |
String airline = GetText(firstSegment, "AirV"); |
|
|
Creates a new Date class.
|
Calendar tomorrow = Calendar.getInstance(); |
Gets tomorrow's date, and sets the Arrange Ticketing Date to the next day (TAU). The TAU typically defaults to Queue 10. |
tomorrow.add(Calendar.DATE, 1); |
String
ticketString = MessageFormat.format | |
|
|
Makes a Minimal Trip request to the Reservation Builder eBL. See the Minimal Trip Sample for detailed parameters. |
StringBuffer req = new StringBuffer(); |
req.append("<GWS_Trip"); | |
The namespace of the schemas. ota: fields are defined by the Open Travel Alliance. |
req.append(" xmlns='http://ns.galileo.com' xmlns:ota='http://www.opentravel.org/OTA'"); |
If PaymentAuthorize is FALSE, credit card authorization is not required. |
req.append("
ReceivedFrom='"+ receivedFrom
+ |
Begins the travel request. |
req.append(" <InventoryItems>\r\n"); |
Begins the flight request. |
req.append(" <Flight>\r\n"); |
Begins the flight segment request. |
req.append(" <FlightSegment "); |
The departure date. |
req.append("DepartureDateTime='"
+ |
The arrival date. |
req.append("ArrivalDateTime='"
+ |
The flight number. |
req.append("FlightNumber='" + flightNum +"' "); |
|
req.append(">\r\n"); |
|
|
The departure city. |
req.append(" <ota:DepartureAirport LocationCode='" + departAirport + "' />\r\n"); |
The arrival city. |
req.append("
<ota:ArrivalAirport
|
The vendor code for the airline. |
req.append("
<ota:MarketingAirline
Code= |
|
|
The booking class. |
req.append(" <BookingClass>\r\n"); |
req.append("
<Requested
Status= | |
req.append(" </BookingClass>\r\n"); | |
End of the flight segment request. |
req.append(" </FlightSegment>\r\n"); |
End of the flight request. |
req.append(" </Flight>\r\n"); |
End of the travel requests. |
req.append(" </InventoryItems>\r\n"); |
End of the Reservation Builder eBL request. |
req.append("</GWS_Trip>\r\n"); |
|
|
|
return Util.string2Element(req.toString()); |
|
} |
Creates a Booking Profile, which is required to book a segment. See the Profiles without TravelScreen sample. |
public Element CreateProfile() |
{ | |
StringBuffer profile = new StringBuffer(); | |
The namespace of the schemas. The namespace is defined in the WSDL, whether ns.galileo.com or webservices.galileo.com |
profile.append("<GWS_BookingProfile xmlns='http://ns.galileo.com' xmlns:ota='http://www.opentravel.org/OTA' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://ns.galileo.com' >\r\n"); |
Personal information of the primary traveler. The namespace is defined in the WSDL, whether ns.galileo.com or webservices.galileo.co |
profile.append(" <Primary Gender='Female' BirthDate='1970-10-14' CurrencyCode='USD' PassengerIdentificationCode='' TicketingIdentificationCode='' xmlns='http://ns.galileo.com' xmlns:ota='http://www.opentravel.org/OTA' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n"); |
Primary traveler's name. |
profile.append(" <PersonName ShareSynchInd='Yes' ShareMarketInd='Yes' NameType='Former'>\r\n"); |
profile.append(" <ota:NamePrefix>MS</ota:NamePrefix>\r\n"); | |
profile.append(" <ota:GivenName>PAM</ota:GivenName>\r\n"); | |
profile.append(" <ota:Surname>TEST</ota:Surname>\r\n"); | |
profile.append(" </PersonName>\r\n"); | |
Primary traveler's contact information. The CityAbbr field is a reference-only field for the travel agents that is required by the CRS. |
profile.append("
<Telephone
ShareSynchInd='Yes' ShareMarketInd='Yes' PhoneLocationType='Home' PhoneTechType='VOICE'
CountryAccessCode='000' AreaCityCode='303' PhoneNumber='1234561' Extension='0'
PIN='String' FormattedInd='false' C |
Primary traveler's address. Both the <Address> and <DeliveryAddress> elements are required, even if they are the same address. Unneeded fields (e.g., ShareSynchInd, ShareMarketInd, FormattedInd) may be omitted. |
profile.append(" <Address FormattedInd='false' ShareSynchInd='Yes' ShareMarketInd='Yes' Type='Home' DefaultInd='false' UseType='Delivery'>\r\n"); |
profile.append(" <ota:StreetNmbr PO_Box='String'>5350</ota:StreetNmbr>\r\n"); | |
profile.append("
<ota:AddressLine> | |
profile.append(" <ota:CityName>GREENWOOD VILLAGE</ota:CityName>\r\n"); | |
profile.append(" <ota:PostalCode>80111</ota:PostalCode>\r\n"); | |
profile.append(" <ota:County>DOUGLAS</ota:County>\r\n"); | |
profile.append(" <ota:StateProv StateCode='CO'>COLORADO</ota:StateProv>\r\n"); | |
profile.append("
<ota:CountryName
Code='US'>UNITED STATES OF AMERICA | |
profile.append(" </Address>\r\n"); | |
Credit card information that can be used to pay for travel. If the itinerary has at least one segment (air, car, or hotel), then your profile must have at least one form of payment. For more information, see Form of Payment. |
profile.append(" <FormOfPayment RPH='01'>\r\n"); |
profile.append("
<ota:PaymentCard
ShareSynchInd='Yes' ShareMarketInd='Yes' | |
profile.append("
<ota:CardHolderName> | |
profile.append(" <ota:CardIssuerName BankId='String'/>\r\n"); | |
profile.append(" <ota:Address FormattedInd='false' ShareSynchInd='Yes' ShareMarketInd='Yes' Type='Home'>\r\n"); | |
profile.append("
<ota:StreetNmbr | |
profile.append("
<ota:AddressLine> | |
profile.append(" <ota:CityName>GREENWOOD VILLAGE</ota:CityName>\r\n"); | |
profile.append(" <ota:PostalCode>80111</ota:PostalCode>\r\n"); | |
profile.append(" <ota:County>DOUGLAS</ota:County>\r\n"); | |
profile.append(" <ota:StateProv StateCode='CO'>COLORADO</ota:StateProv>\r\n"); | |
profile.append("
<ota:CountryName
Code='US'>UNITED STATES OF AMERICA | |
profile.append(" </ota:Address>\r\n"); | |
profile.append(" </ota:PaymentCard>\r\n"); | |
profile.append("
| |
End of the primary traveler information. |
profile.append(" </Primary>\r\n"); |
End of the Booking Profile. |
profile.append("</GWS_BookingProfile> |
|
|
|
return
Util.string2Element |
|
} |
|
|
The request. travelerProfile is the Booking Profile. |
public
Element doBooking( Element trip, |
|
{ |
Instantiates the locator. |
ReservationBuilderLocator bservice = new ReservationBuilderLocator(); |
|
Element response = null; |
|
try |
|
{ |
|
|
Uses the Web Service to get a stub that implements the SDI. |
ReservationBuilderSoapStub
bws = (ReservationBuilderSoapStub)bservice. |
The User Name and Password to access Galileo Web Services. |
bws.setUsername(USER_NAME); |
bws.setPassword(PASSWORD); | |
|
|
Books the trip. |
response = bws.bookTrip(HOSTACCESSPROFILE, true, travelerProfile, trip); |
|
} |
|
|
Exception handling. |
catch (Exception e) |
|
{ |
|
System.err.println(e.getMessage()); |
|
e.printStackTrace(System.err); |
|
} |
|
|
|
return response; |
|
} |
|
|
Parses the CRS date and time format (YYMMDD) into a Calendar object. |
private Calendar parseHostDate(String date, String time) |
{ | |
Calendar dt = Calendar.getInstance(); | |
int y = Integer.parseInt(date.substring(0,4)); | |
int M = Integer.parseInt(date.substring(4,6)); | |
int d = Integer.parseInt(date.substring(6,8)); | |
int h = Integer.parseInt(time.substring(0,2)); | |
int m = Integer.parseInt(time.substring(2,4)); | |
dt.set( y, M, d, h, m); | |
return dt; | |
} | |
|
|
Formats the Calendar object for use in the Web Service. |
private String formatBWSDate( Calendar dt) |
{ | |
StringBuffer sb = new StringBuffer(); | |
sb.append("{0,date,yyyy}-"); | |
sb.append("{0,date,MM}-"); | |
sb.append("{0,date,dd}T"); | |
sb.append("{0,date,hh}:"); | |
sb.append("{0,date,mm}:"); | |
sb.append("{0,date,ss}-00:00"); | |
return MessageFormat.format(sb.toString(), new Object [] {dt.getTime()}); | |
} | |
|
|
Declares the constants. Ensure URL is specific to your region or service level. |
public final String receivedFrom = "GWSSample"; |
private final String BWS_URL = "https://americas.copy-webservices.travelport.com/B2BGateway/service/ReservationBuilder"; | |
private final String USER_NAME = "UserName"; | |
private final String PASSWORD = "Password"; | |
private
final String HOSTACCESSPROFILE = | |
|
} |
The Apollo or Galileo CRS returns the following minimum data in a booking response.
Response. |
<Response Time="Wednesday, 25 September 2002 21:07:05" ServiceBuildVersion="1.0.39.0" xmlns="http://ns.galileo.com"> |
Information Context text fields are returned for each booked segment. |
<Information Context="Selling Air"> |
Air segments include text responses with the departure and arrival times and locations; vendor messages; and agency-related prompts, such as offering additional travel services. |
<Text> CARRY ON CRITICAL FLIGHT *</Text> |
<Text> ARRIVES ORD TERMINAL 1</Text> | |
<Text>DEN/0343CT/DPTS 1135A OT *</Text> | |
<Text>ORD/0343CT/ARVS 255P OT *</Text> | |
<Text>OFFER CAR/HOTEL !CAL· !CAQ· !HOA·</Text> | |
|
</Information> |
Information context for the stored fare quote includes rules for ticketing at the submitted fare. |
<Information Context="Storing Farequote"> |
<Text>LAST DATE TO PURCHASE TICKET: 26SEP02</Text> | |
|
</Information> |
The Success indicator contains the record locator for the PNR/BF. |
<Success>LC97W0</Success> |
|
</Response> |
In Sample 3, flight information is obtained from the air availability response in Step 1.