Java IoT Authors: APM Blog, Stackify Blog, XebiaLabs Blog, Liz McMillan, William Schmarzo

Related Topics: Java IoT

Java IoT: Article

Leasing and Flying

Leasing and Flying

Part 1 of this series appeared in JDJ June, Part 2 in JDJ July, Part 3 in JDJ September

This is the fourth in a series of articles focused on using Java and ColdFusion technologies to develop an Online Ticket Store application. As JDJ's September issue had an XML focus, we went with the flow and discussed data formatting aspects of our store and developed XML objects to pass date structures between the Merchant Server and Service Access tiers.

This month's article focuses on the online store portion of our application, beginning with a description of the business offerings of the store. This is followed by a use-case analysis of the store, a methodology similar to the one in the July issue. We then design the classes for implementing the use cases and discuss the code needed to make our store a "reality." We'll also make use of the XML objects developed in the September issue to facilitate data transfer for the online store transactions.

The Online Airline Store Business Model
In addition to serving as a virtual travel agent, our application has an online store through which it sells merchandise. This includes the products offered via airline catalogs as well as unique items offered exclusively through the travel agency - books, magazines, clothing, gifts, souvenirs and computer equipment, for example.

So far, our store is like any other virtual store on the Internet that also sells airline tickets. But here's where it gets interesting. A unique feature our store offers is the ability for passengers to lease equipment for the duration of the flight.
This equipment includes:

  • Books and magazines
  • Laptops for business or pleasure
  • Portable CD players and music CDs
  • Portable cassette players and audiotapes

The idea is that someone who uses our Online Store to book a flight and purchase a ticket can instruct the store to have the leased equipment available on the flight he or she will be taking. Although the scenario is fictitious, I'd like to develop it further. I can think of several different options for our leasing operation:

  1. The airline could keep an inventory of the equipment at the various airports and the passenger could pick up and drop off the equipment at the gate. The equipment may even be directly available on the flight. This, of course, would put a burden on the airlines to create the infrastructure and organization to support such a model.
  2. The online store could be affiliated with a leasing store at the airport that holds the inventory. The passenger could pick up the inventory from the physical store.
  3. The online store could have personnel who would be responsible for making the equipment available at the gate for the flight and picking it up at the other end of the flight.
If this kind of business becomes a reality, I can foresee airlines (Option 1) and independent agents (Options 2 and 3) competing for the business. However, one assumption we'll make for our application is that the equipment should always be leased via the online store. Thus, similar to a ticket purchase, payment for leased equipment would be made at the Merchant Server tier. The modules for this interaction (Shopping Cart, Catalog, Personal Profile Manager, Payment Manager, etc.) are thus implemented in ColdFusion and will be discussed in the December issue of ColdFusion Developer's Journal. For an explanation of the tiers of this application and the software modules, please refer to the previous three articles. Figure 1 shows the four tiers in our application for the current reference. This is the same as Figure 2 in Part 1 of this series.

You may wonder what modules of the store will be housed in the Service Access tier. After all, that's the Java middleware tier in this application. Well, though the merchandise will be ordered and paid for at the Merchant Server tier, this tier doesn't have any knowledge of the local inventory and availability of the merchandise. The Service Access tier is responsible for this function - and for making sure that the order, whether it's a merchandise purchase or lease, gets "delivered" to the customer. Delivery may constitute shipping the actual product, making it available at the gate or keeping it ready for the customer at the physical store in the airport.

The UI design for this application isn't a major part of our Java-based design. A sophisticated UI will be developed in parallel using ColdFusion in the corresponding issues of ColdFusion Developer's Journal (Vol. 1, issues 4 and 6, and Vol. 2, issues 1 and 2).

Online Store Requirements
The Online Store entertains two types of transactions - purchase and lease. Once the customer selects the merchandise (this is handled by the Merchant Server tier), the order is sent to the Service Access tier. This leads to a check for availability against the Application Services tier. Note that the function of this tier is different from that in the previous articles. In this article the tier is responsible for satisfying a merchandise order instead of booking an airline ticket. In both cases, however, the Application Service tier acts as the back office for services offered by the middle tiers. If the purchase or lease were made directly against the airline, the Application Services tier modules would reside in the airline's back offices.The application modules involved in this transaction are described in Table 1 and illustrated in Figure 2.

Once the "order" is placed, a confirmation is sent back to the Merchant Server tier, which is then responsible for getting the payment for the purchase. To keep the workflow simple, we're assuming a synchronous workflow through the system. In reality, part of this workflow will be asynchronous. The simplified workflow for this interaction is shown below:

  1. Accept the merchandise order from the Merchant Server tier.
  2. Determine whether it's a PURCHASE or LEASE.
  3. In the case of LEASE, search for availability of the merchandise.
  4. If not available, send back an exception.
  5. If available, place an order with the Application Services tier. For a PURCHASE operation, this would be an order for a shipment. For a LEASE operation, this would be the order to make the equipment available at the airport.
  6. Return the confirmation to the Merchant Server tier.

This is a simple workflow that runs through the system in sequential fashion. We'll implement this workflow in our system, ignoring other functionality such as canceling an order. The idea is to demonstrate how data flows through our Online Store from the end customer to the back office and back. Figure 3 illustrates the use cases for the Broker. Workflows are illustrated in Figure 4. The main difference between the two flows is that the Leasing Order workflow has a constraint on time because the items need to be booked for the flight and thus need to be at the airport at a specific time. Note also that the Leasing Order workflow follows in sequence from the Ticket Booking workflow described in the July JDJ article - that is, the items are leased only after the tickets have been reserved. The Purchase Order workflow is independent of any interaction the customer may have with the ticket reservation system. We assume that for a Purchase Order the customer will accept delivery whenever the merchandise can be sent by the system. This is similar to the regular catalog orders that state "Allow 4-6 weeks for delivery."

Data Interchange Formats
The following data objects were introduced in the September JDJ. Some of the description is repeated here to put things in the appropriate context:

  • Lease Order
  • Lease Confirmation
  • Purchase Order
  • Purchase Confirmation
Let's go ahead and define the attributes of goods sold in the store. An item that may be offered by the store will have the following fields. Example values are assigned to the fields:

ITEM_ID ="cd30056"

An order for the purchase of an item (or items) will also need information about the person making the purchase. This will consist of the following fields:

NAME="Clark Kent"
ADDRESS="123 Tiny Lane, Smallville, Kansas, 12345"

The fields listed above are common for both purchase and lease options. The lease operation requires one additional field. This is the reference number of the confirmed flight, and is required because it's the reference for the store to make the equipment available at the airport.


The hierarchy of the XML documents in DOM for the PURCHASE/lease was illustrated in the September JDJ. The XML files are shown in Listing 1. I won't go into a detailed description of the code for the XML parsing for these objects as it's similar to the mechanism described for the ticket reservation part of our application as shown in September.

Class Design
Now let's define the classes involved in this set of transactions. For now, we'll forgo discussion on the UI and assume that the user's input somehow arrives at the Broker. In designing the store I'm restricting the discussion to an RMI-based connection to the back office. The previous articles have discussed the flexibility of using different transport protocols like CORBA, TCP/IP, etc. That design can easily be applied to our store. The classes for the store are described in the following sections. Figure 5 illustrates the class relationships.

Listing 1 shows the StoreServlet class. This class receives a merchandise order request ("PURCHASE" or "LEASE") from the Merchant Server, packages it into a LeaseOrder (LEASE) or PurchaseOrder (PURCHASE) object, passes it on to the Order Manager and gets a confirmation (or an exception if it's a LEASE operation), and returns the result to the Merchant Server. The input to the servlet is in the form of an HTTP POST that carries one of the following XML data structures:


The LEASE structure is used only after the customer has purchased a ticket. The StoreServlet first checks to see whether it has a reference to the clientManager_ object. If not, it constructs a new StoreClientManager object. The request and response streams are copied into request_ and response_ variables for future use. Next, the method processParameters() is called. This method parses the input parameters and creates the appropriate Java object. The XML processing for this application is done in the XMLProcessor class. The methods for the LEASE and PURCHASE operations are shown in Listing 1. (The code for the ticket reservation objects is stubbed out to conserve space.) The StoreServlet first creates a new instance of the XMLProcessor object. The complete listing may be obtained from www.JavaDevelopersJournal.com. It then calls the initParser() method on the XMLProcessor class. The servlet's input stream is passed in as a parameter for parsing the XML document that the servlet received in its input stream. The XMLProcessor class is shown in Listing 2. The code for XMLParser.java is not discussed here, as it's similar to the code in the September article.

Next, the method getOperationType() is called on the XMLProcessor reference (xp) to check what kind of an operation was invoked on the StoreServlet. If the type is a "Purchase," the method processPurchase() is called on the object xp. This method returns a PurchaseOrder object from the XML document. This object is passed to the doPurchase() method, which in turn calls the doPurchase() method on the clientManager_. If the type is "Lease," the method processLease() is called on the object xp. Following this, the local method doLease() is called, which in turn calls the method doLease() on the clientManager_.

This is a very simplified version of an order. A real order would have greater detail, including telephone number and method of shipment.

The following methods were added to this class as compared to the September listing:

The complete code for these methods is given in Listing 2. The remainder of the listing was provided in September and thus is not repeated here. One new operation used in the parsing is the processListTag() utility method, which is used to obtain an array of item objects from the XML input file (submitted via the POST). This is used in both processLease() and processPurchase() methods. The processConfirmation() method is relatively simple in comparison to the processTicketQuote() method described in September. The complete listing for this file is available at www.JavaDevelopersJournal.com.

The next four classes - Item, PurchaseOrder, LeaseOrder and Confirmation - are shown in Listing 3.

This class encapsulates an item. Basically, it consists of the following data fields and the getter and setter methods for them:

  • name  
  • sku  
  • quantity

    This class encapsulates an item purchase order. It consists of the following fields and the corresponding getter and setter methods:

  • list of Items  
  • customerName  
  • address

    This class encapsulates an item leasing order. It consists of the following fields and the corresponding getter and setter methods:

  • list of Items  
  • customerName
  • address  
  • referenceNo

    The LeaseOrder class inherits its first three fields from PurchaseOrder. The last field is the reference number of the associated tickets purchased.

    This class encapsulates the result of an order for a purchase or a lease. It consists of the following fields and the corresponding getter and setter methods:

  • status (confirm/reject)
  • reference number

    The last four classes - StoreClientManager, RMIStoreService, RMIStoreClient and RMIStoreServer - are shown in Listing 4.

    This class receives a PurchaseOrder or a LeaseOrder from the StoreServlet, forwards it to the RMIStoreClient, gets back a Confirmation object and sends it back to the StoreServlet. It's also responsible for actually placing the order or arranging for the lease. This functionality is stubbed out in the application. It has two main methods - doPurchase() and doLease(). The doLease() method delegates the operation to the RMIStoreClient's doLease() method.

    This is the interface for the services offered by the Application Services tier. It provides a single method, getLeaseAvailability().

    This is accessed by the StoreServlet for submitting the request to a Ticket Server. It provides the stub for the method getLeaseAvailability().

    This class processes a PurchaseOrder (or LeaseOrder) object and sends back a Confirmation object. It implements the method getLeaseAvailability(). The code always returns a "true" for availability. In a real application this would go against a local availability engine that would check whether the item was available in the store.

    Running the Programs
    The StoreServlet can be accessed via any client that can post the corresponding file for either the LEASE or the PURCHASE operation. I've included the files required to access the servlet from ColdFusion. Readers may use HTML, Java clients or VB clients. The code for this article is available at www.JavaDevelopersJournal.com. The code was compiled and tested on a Windows NT 4.0 workstation. To run the programs you'll need the following:

    • JDK 1.1.x
    • JSDK 2.0 (Java Servlet Development Kit)
    • Your servlet engine and Web server

    Developing this application has been a fun task for me. My intention was to provide a template for building n-tier applications in e-commerce. In essence, the idea was to decouple the Web storefront from the back-office services. If you undertake the development of such applications, the business logic for accessing back-office services may reside in middleware components written in EJB or COM. In that case you may end up using two categories of application servers - the Web storefront application server like ColdFusion and a middleware application server such as Netscape Application Server or WebLogic's application server.

    As mentioned earlier, this article series has generated a lot of feedback from readers - so much so that I plan to include the concepts discussed here in a book I'm currently writing. I hope it's been a useful exercise for all of you too.

    I'd like to bring up a few interesting issues related to this article series. For one thing, the first article generated more feedback than I expected. It's been a pleasant surprise to know that some companies actually have airline store sites developed in ColdFusion similar to the fictitious one we've developed here. I also received some e-mail that indicated folks took this application more seriously than I thought they would. These readers concluded that this is a real-world application. While the design of the application outlines a real-world architecture for a business problem and serves as a template for a real-world solution, it's not a production-level system.

    Another interesting development was that LiveSoftware (the makers of JRun) was acquired by Allaire Corporation (the makers of ColdFusion). This happened during the week of June 14, when JavaOne was in progress. It was my pleasure to talk to Jeremy Allaire (ColdFusion) and Paul Colton (JRun) at JavaOne regarding this development. In my opinion this has been a very smart move on Allaire's part. A few months ago Allaire acquired Bright Tiger Technologies, a company that specializes in clustering technology. The acquisition of JRun makes Allaire's app server story complete. ColdFusion is a great product and I've always felt they needed a story on the Java side. That was part of the motivation for building the Online Ticket Store. Coincidentally, the August issue of ColdFusion (Vol. 1, issue 4) has two features with two individual CF_SERVLET tags - the professional one from LiveSoftware and my own humble contribution.

  • More Stories By Ajit Sagar

    Ajit Sagar is Associate VP, Digital Transformation Practice at Infosys Limited. A seasoned IT executive with 20+ years experience across various facts of the industry including consulting, business development, architecture and design he is architecture consulting and delivery lead for Infosys's Digital Transformation practice. He was also the Founding Editor of XML Journal and Chief Editor of Java Developer's Journal.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

    @ThingsExpo Stories
    In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
    "There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
    "Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
    Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
    "Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    "MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
    "IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
    SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
    "Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
    It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
    WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
    A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
    SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
    Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
    To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
    An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...
    When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things’). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing? IoT is not about the devices, it’s about the data consumed and generated. The devices are tools, mechanisms, conduits. In his session at Internet of Things at Cloud Expo | DXWor...