B2B with XML

TDP Module Uses the XSQL Servlet

August 2000
Oracle8i

The Travel Discount Provider (TDP) module supplies the Hotel Reservation System (HRS) with data about discounts offered by hotels to members of certain groups. For example, a hotel could offer Diner's Club members a 15 percent discount on room rates. When a customer reserves a room, the HRS contacts the TDP to find out if the customer is eligible for a discount. The TDP returns the discount rate in an XML document, and the HRS parses the XML and calculates the cost of the room.

The TDP itself is not a servlet, but it uses the Page Processor component of the Oracle XSQL Servlet. The XSQL Servlet takes as input an XML document containing embedded SQL queries, and it outputs the result set as XML. It uses the XML Parser for Java and the XML SQL Utility to perform many of its operations. The following code from a2afiles\xsqlfiles\TDP.xsql defines a query for the TDP (XSQL is the extension that triggers the XSQL Servlet). It takes the membership ID and hotel ID as parameters.

<?xml version="1.0"?>
<xsql:query connection="HRS" xmlns:xsql="urn:oracle-xsql">
  select discount_rate from tdp_discounts 
  where membership_id={@m_id} and hotel_id={@h_id}
</xsql:query>

The following code from xmla2a.hrs.HRSServlet.service shows how the HRS gets discount rates from the TDP. This code executes within a FOR loop that processes each item in a customer's shopping cart. Note: If you run this sample app from JDeveloper, the TDP module is not invoked (JDeveloper only runs one servlet at a time). Instead, the HRS uses a flat discount rate of 10 percent; see xmla2a.hrs.HRSServlet.reserveLocalHotels for an example.

public void service(HttpServletRequest p_request, 
                    HttpServletResponse p_response)
                      throws ServletException, IOException {


 ...

  // Process the contents of the shopping cart.
  if (l_reqType.equals("Continue_Cart")) {
try{
... String l_discountRate = null;
...
if (ConnectionParams.s_tdpUrl != null){ for(int i=0; i < l_noOfReservations; i++){
String l_membership=l_session.m_userDetails.m_membership;
int l_membershipId=getMembershipId(l_membership);
l_resvDetails=(ReservationDetails)l_session.m_cartInfo. m_noOfBookings.elementAt(i);
l_hotelId=l_resvDetails.m_hotelID;
m_hotelIdForFS=l_hotelId; // Contact the TDP XSQL Servlet. String l_urlString = ConnectionParams.s_tdpUrl + "xsqlfiles/TDP.xsql?m_id=" + l_membershipId + "&h_id=" + l_hotelId;
URL l_urlOfServlet=new URL(l_urlString);
URLConnection l_urlConnection=l_urlOfServlet.openConnection();

BufferedReader l_inputStream = new BufferedReader(new InputStreamReader(
l_urlConnection.getInputStream())); // Parse the XML document to get the discount rate.
DOMParser l_parser=new DOMParser();
l_parser.parse(l_inputStream);
XMLDocument l_document=l_parser.getDocument();
Node l_docRoot=l_document.getLastChild();
NodeList l_discount=l_docRoot.getChildNodes();
int l_length=l_discount.getLength(); for(int m = 0; m < l_length; m++){
Node l_discountNode=l_discount.item(m);
l_discountRate=l_discountNode.getFirstChild(). getFirstChild(). getNodeValue();
}
l_inputStream.close(); ...
}
}
} else { ... } }

At runtime, the flow of events is:

  1. Customer makes reservations, then submits shopping cart.
  2. HRS processes shopping cart, contacts TDP to get discount data.
  3. TDP queries the database and returns the results in an XML document.

For example, the XML document below shows the discount rate (5 percent) for a Diner's Club member (membership ID 1) at Hyatt Regency Paris (hotel ID 5799), which the HRS requests from the TDP by submitting a URL like the following:

http://localhost:7070/xsql/TDP.xsql?m_id=1&h_id=5799

<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<DISCOUNT_RATE>5</DISCOUNT_RATE>
</ROW>
</ROWSET>


< Back to Introduction


Questions or comments? Post a message in OTN's Sample Code discussion forum or send email to the author.

Travel Discount Provider: B2B with XML
Author: Robert Hall, Oracle Corporation
Date: August 2000

This document is provided for information purposes only and the information herein is subject to change without notice. Please report any errors herein to Oracle Corporation. Oracle Corporation does not provide any warranties covering and specifically disclaims any liability in connection with this document.

Oracle is a registered trademark and Enabling the Information Age is a trademark or registered trademark of Oracle Corporation. All other company and product names mentioned are used for identification purposes only and may be trademarks of their respective owners.

Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
U.S.A.

Worldwide Inquiries:
+1.650.506.7200
Copyright © Oracle Corporation 2000
All Rights Reserved


E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy