Java Sample 2:
Booking an Air Reservation

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.

  1. 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
    .

  2. 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:

 

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
("TAU/{0,date,dMMM}", new Object []
{ tomorrow.getTime()}).toUpperCase();

 

 

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 +
"' Ticketing='" + ticketString + "' PaymentAuthorize='false'>\r\n");

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='" +
formatBWSDate(departDateTime) + "' ");

The arrival date.

req.append("ArrivalDateTime='" +
formatBWSDate(arriveDateTime) + "' ");

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
LocationCode='" + arriveAirport + "' />\r\n");

The vendor code for the airline.

req.append("                <ota:MarketingAirline Code=
'" + airline + "' />\r\n");

 

 

The booking class.
If the booking class is Requested, the Status element is required.

req.append("                <BookingClass>\r\n");

req.append("                    <Requested Status=
'NN-Need Need' ResBookDesigCode='Y' />\r\n");

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
ityAbbr='DEN'/>\r\n");

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>
S VALENCIA WAY</ota:AddressLine>\r\n");

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
</ota:CountryName>\r\n");

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'
CardType='Credit' CardCode='AX-American Express' CardNumber='300000000000000' SeriesCode='0' EffectiveDate='0101' ExpireDate='1005'>\r\n");

profile.append("                <ota:CardHolderName>
PAM TEST</ota:CardHolderName>\r\n");

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
PO_Box='String'>5350</ota:StreetNmbr>\r\n");

profile.append("                    <ota:AddressLine>
S VALENCIA WAY</ota:AddressLine>\r\n");

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
</ota:CountryName>\r\n");

profile.append("                </ota:Address>\r\n");

profile.append("            </ota:PaymentCard>\r\n");

profile.append("        
</FormOfPayment>\r\n");

End of the primary traveler information.

profile.append("    </Primary>\r\n");

End of the Booking Profile.

profile.append("</GWS_BookingProfile>
\r\n");

 

 

 

return Util.string2Element
(profile.toString());

 

}

 

 

The request. travelerProfile is the Booking Profile.

public Element doBooking( Element trip,
Element travelerProfile)

 

{

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.
getgwsBookingSoap(new java.net.URL
(BWS_URL));

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 =
"HostAccessProfile";

 

}

 

  1. 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>

 

  1. In Sample 3, flight information is obtained from the air availability response in Step 1.