IBM Cloud Authors: Yeshim Deniz, Elizabeth White, Zakia Bouachraoui, Pat Romanski, Liz McMillan

Related Topics: IBM Cloud

IBM Cloud: Article

Creating XML - Based Web Applications Using IBM VisualAge for Java

Creating XML - Based Web Applications Using IBM VisualAge for Java

Since the mid-'90s we've seen the quality of Web programming paradigms mature at an astonishing rate: from static pages with animation, CGI-based programs, and JDBC connectivity to back-end relational databases and servlets processing requests on application servers. We commonly hear about Web pages being more interactive, likely using HTML forms, JavaScript, or Java applets.

Beyond the battle being waged on the first tier, the client, it's important to understand the drive toward scalable, platform-neutral technologies on the middle and back-end tiers. In particular, Java and XML set the stage for the growth of B2B Web marketplaces, where participants in supply chain management (SCM) and enterprise resource planning (ERP) will realize enormous gains in speed and access to data.

In this article we'll look at a simple application that uses Java and XML to manage data: the Conference Survey Web page. To develop complex Web pages, particularly pages based on a server-side programming model, programmer productivity is strongly affected by the tools used. We'll show how the IBM VisualAge for Java suite of tools can be used to develop, build, and test this page.

Conference Survey Web Page
At the end of the fictitious e-Business 2000 conference, participants are asked to fill in a survey to rate the various sessions and to provide comments and suggestions for future use. To ensure attendee responses aren't lost and don't need to be scanned or typed into a system, a Web page has been set up (see Figure 1).

Behind this HTML form is a three-tiered Web application (see Figure 2). The essential pieces of the application can be grouped as follows:

  • Tier 1: HTML form, JSP pages
  • Tier 2: Java servlet, JavaBeans, XML parser, all running under an application server
  • Tier 3: XML files

In our Conference Survey application we opted to use HTML on the client Web browser instead of XML for two reasons:

  1. HTML forms are prolific and drop-dead easy to implement. Simple forms support a thin-client model, in contrast to Java applets, which are too cumbersome as a data transfer mechanism.
  2. At this writing XML support in popular Web browsers is inconsistent. You don't want to find that your application isn't accessible because of the foibles of a browser.
The use of JSP pages allows us to dynamically build the HTML pages that are sent back to the user and to maintain a clear separation between presentation and business logic.

Tier 2, the middle tier, represents those parts of the application that run on an application server (e.g., IBM WebSphere Application Server). The servlet essentially acts as a traffic cop for the application flow: when the servlet receives a POST request, it records a survey response and updates the summary bean; when the servlet receives a GET request (from a private Web page requesting a summary status), it displays a statistical summary of all responses (see Figure 3). When the application starts, the summary is initialized from the summary file (on the back-end tier), if it exists. Beans for the responses and summary are used to store state data and write out XML to persistent files on the back end. To assist with the parsing of the XML data from the back-end tier, a SAX-based XML parser also runs on the application server. When the application is closed, the summary bean writes out its state data to the summary XML document.

By processing XML on the middle tier, the Conference Survey application is well placed to exchange data with other XML-based applications. If multiple applications reside on the same application server, events in one application could trigger listener beans in another application to read its state data and subsequently mine it differently. For example, suppose another application wanted to take the opinions voiced by a survey respondent to help build a customer profile. The data could be used to target specific kinds of Web advertising to users based on the preferences they cited in their survey response.

On Tier 3, using XML documents as the vehicle for persistent data, you maintain the flexibility to mine the data as you deem fit without being forced down any particular path in terms of how it will be presented. For the amount of data being represented here, using a relational database would be overkill, while using serialized beans is overly complex. Because XML is self-describing by definition, and XML parsers are readily available, using XML is preferable to a flat file (which might use, for example, name-value pairs), where the programmer is forced to write a custom parser.

The XML fragment in Listing 1 illustrates the data that's written out to a file for each response.

The technology used in the Conference Survey example provides a scalable model for building three-tier Web applications. If the amount of persistent data grows very large, XML files could be stored in a relational database. As additional kinds of data mining could be applied to the data, additional servlets and beans can be deployed to the application server. As popular Web browsers standardize on how to handle XML, then XML and XSL stylesheets could eventually replace HTML pages and JSP pages.

Although the application architecture is straightforward enough, the challenge remains to find a suite of tools that can work together to let you easily develop and test the end-to-end application. Enter VisualAge for Java.

Integrated Tools
Using VisualAge for Java, version 3.5, you can develop, test, and debug full-blown XML-based Web applications, all within the VisualAge for Java environment. Most development tool suites don't provide you with adequate integration. For example, you might have a great editor and compiler, but you need to deploy your code to a Web application server for testing and debugging. Unless these tools are integrated, you'll spend a lot of time redeploying code for testing rather than testing your code in a development environment. VisualAge for Java includes tools to create and run end-to-end Web applications like the Conference Survey application.

  • WebSphere test environment: This run-time environment is a version of the IBM WebSphere Application Server, Advanced Edition product, streamlined for use specifically inside VisualAge for Java. The environment includes tools to start, stop, and configure the server (see Figure 4). If server-side source code is changed, VisualAge for Java incrementally compiles the code and hotlinks it into a running program.

    You can run multiple, end-to-end Web application scenarios in this environment, such as e-commerce (store and customer applications) or B2B (supplier, vendor, and manufacturer applications). You can also pass data between the various applications, all from within the comfort of the WebSphere test environment.

  • Servlet wizard: The Create Servlet SmartGuide (see Figure 5) provides a quick way to create servlets and related Web resources files (HTML and JSP pages).

  • XML Parser for Java: This parser is a version of IBM's XML4J parser, which conforms to standards and recommendations for XML, DOM, SAX, and Namespaces support.

    In the Conference Survey application, the parser is used when the servlet starts. It reads the summary file, if it exists. If any responses aren't reflected in the summary file, the parser reads in those records and modifies the summary bean, as appropriate.

  • XML Generator: This tool generates sample XML documents based on a DTD you provide. While an application like the Conference Survey is too simple to require this tool, you could use the XML generator to generate a diverse range of test cases.
  • Integrated debugger: This debugger includes the features found in all good debuggers: breakpoint setting, variable inspection and modification, step into and through methods, multithread support, define expressions to watch as you step through programs, and so on. In addition, you can halt execution in the middle of a running program, change a variable value, and resume execution. In a complex scenario with multiple applications that pass data between each other, this debugging support can speed your development considerably. (see Figure 6).

  • JSP execution monitor: This tool provides an integrated run-time view of your JSP page, letting you quickly debug problems arising from JSP-generated code. As with a debugger, you can step through a JSP page and see both the generated intermediary Java source and the generated HTML (see Figure 7).

Setting Up the Application
To set up the end-to-end environment in VisualAge for Java, we need to follow these steps:

  1. Load all necessary projects into the workspace. Add the IBM WebSphere Test Environment, IBM XML Parser for Java, and Sun Servlet API. Of course, your application project will also need to be in the workspace.

    In the response bean an instance of IBM XML Parser for Java is created:

    String parserClass = "com.ibm.xml.parsers.SAXParser";
    parser = ParserFactory.makeParser(parserClass);

    Note that the SAX-based instance of this parser has been tested to work with the WebSphere Test Environment and is not guaranteed to work with other application servers.

  2. Edit the WebSphere Test Environment's servlet initialization file. On server start-up, you can specify that the WebSphere Test Environment initialize a specific servlet instance with particular parameters. In the default_app.webapp XML file, we've added a servlet entity for the SurveyServlet servlet. The entity specifies the directory where the application will be writing an XML file for each survey response (see Listing 2).
  3. Add all client-side Web resources (HTML, JSP, GIF) to the WebSphere Test Environment's default Web directory. In the Conference Survey application we add the HTML and JSP pages, and all associated artwork files, to the \ide\project_ resources\IBM WebSphere Test Environment\hosts\ default_host\default_ app\web directory.
Running the Application
Now you're ready to run the application.
  1. Start the servlet engine in the Servlet Engine page of the WebSphere Test Environment Control Center. The Console window provides status information on the servlet engine as it starts.
  2. Open a Web browser to the server-based URL (not file-based!) where the survey Web client resides (see the URL in Figure 1). The WebSphere Test Environment uses port 8080 as the default port. In our example, the URL is http://localhost:8080/survey/survey.html.
  3. Fill in the survey and submit it. When you receive the "success" message in the browser, you've essentially gone to the back end of the application and back: the servlet processed the submission and created an instance of a response bean; the bean wrote out response information to an XML response document (in the directory specified in default_app.webapp); and a JSP page returned a status message back to the browser.
Without having to bother with deployment, we've been able to test a server-based application end to end using VisualAge for Java. But what if something goes wrong? Is there integrated debug support?

Debugging the Application
Problems inevitably arise during development - even to the best of us! Perhaps the code that creates the summary bean isn't properly storing the data it's parsing from an XML response document. In Figure 6, we've set a breakpoint where the summary bean is assigning values to a variable that holds parsed comment text. We step into the setComments() method and find the problem: instead of appending comments in the comment summary, the comment summary contents are replaced with current XML document contents. Modify the method and retest.

Consider a situation in which the summary page displayed in the Web browser isn't quite right. You need to debug your JSP file, but how? Notice that in the Control Center (see Figure 4) when we started the servlet engine we enabled the "JSP source debugger." This lets us debug the JSP source using the IDE debugger. You can inspect variables generated dynamically from the JSP source. On another page of the Control Center, the JSP Execution Monitor Options page, select the "Enable monitoring JSP execution" option, and the JSP Execution Monitor will appear the next time the JSP page is invoked. With the JSP Execution Monitor we can step through JSP code to see the corresponding generated Java source and generated HTML (see Figure 7).

Extending the Application
Other information can be mined from the survey data:

  • Calculate survey scores for each response based on some kind of weighting system. Store the score as part of the XML data for each response. Write a separate servlet that extracts the comment text from the high-scoring responses. The conference organizers could then look for inspiring quotations they could use next year.
  • In the same manner, calculate session scores for the summary. The results provide information on which sessions and speakers were popular - and which should be avoided!
What if you want to add more entities to the XML response documents but don't want to go back through the data to pad the records? Just write out the new entity into new records and add some code to any bean handlers to assume a default value if the entity doesn't exist in a given XML document.

Using Java and XML, our sample application remains extensible. Using VisualAge for Java, you can quickly prototype Web applications. Servlets, JSP pages, an XML parser, and XML files can be used together in the VisualAge for Java development environment, making development and debugging a snap.

More Stories By Arthur Ryman

Arthur Ryman is a Senior Technical Staff Member and Development Manager at the IBM Toronto Lab. He is currently the lead of the Web Standard Tools subproject of the Eclipse Web Tools Platform project. His previous development projects include Rational Application Developer, WebSphere Studio Application Developer, and VisualAge for Java. He is a member of the W3C Web Services Description Working Group and is an editor of the Web Services Description Language 2.0 specification. He is a co-author of the book, "Java Web Services Unleashed".

More Stories By Luc Chamberland

Luc Chamberland is a development manager in the IBM Toronto Lab, where his team develops XML parsing technology, including the XML4J and XML4C parsers. He
previously worked on the VisualAge for Java team and has authored several papers on VisualAge for Java.

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.

IoT & Smart Cities Stories
Atmosera delivers modern cloud services that maximize the advantages of cloud-based infrastructures. Offering private, hybrid, and public cloud solutions, Atmosera works closely with customers to engineer, deploy, and operate cloud architectures with advanced services that deliver strategic business outcomes. Atmosera's expertise simplifies the process of cloud transformation and our 20+ years of experience managing complex IT environments provides our customers with the confidence and trust tha...
Intel is an American multinational corporation and technology company headquartered in Santa Clara, California, in the Silicon Valley. It is the world's second largest and second highest valued semiconductor chip maker based on revenue after being overtaken by Samsung, and is the inventor of the x86 series of microprocessors, the processors found in most personal computers (PCs). Intel supplies processors for computer system manufacturers such as Apple, Lenovo, HP, and Dell. Intel also manufactu...
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Apptio fuels digital business transformation. Technology leaders use Apptio's machine learning to analyze and plan their technology spend so they can invest in products that increase the speed of business and deliver innovation. With Apptio, they translate raw costs, utilization, and billing data into business-centric views that help their organization optimize spending, plan strategically, and drive digital strategy that funds growth of the business. Technology leaders can gather instant recomm...
OpsRamp is an enterprise IT operation platform provided by US-based OpsRamp, Inc. It provides SaaS services through support for increasingly complex cloud and hybrid computing environments from system operation to service management. The OpsRamp platform is a SaaS-based, multi-tenant solution that enables enterprise IT organizations and cloud service providers like JBS the flexibility and control they need to manage and monitor today's hybrid, multi-cloud infrastructure, applications, and wor...
The Master of Science in Artificial Intelligence (MSAI) provides a comprehensive framework of theory and practice in the emerging field of AI. The program delivers the foundational knowledge needed to explore both key contextual areas and complex technical applications of AI systems. Curriculum incorporates elements of data science, robotics, and machine learning-enabling you to pursue a holistic and interdisciplinary course of study while preparing for a position in AI research, operations, ...
After years of investments and acquisitions, CloudBlue was created with the goal of building the world's only hyperscale digital platform with an increasingly infinite ecosystem and proven go-to-market services. The result? An unmatched platform that helps customers streamline cloud operations, save time and money, and revolutionize their businesses overnight. Today, the platform operates in more than 45 countries and powers more than 200 of the world's largest cloud marketplaces, managing mo...
Trend Micro Incorporated, a global leader in cybersecurity solutions, helps to make the world safe for exchanging digital information. Our innovative solutions for consumers, businesses, and governments provide layered security for data centers, cloud workloads, networks, and endpoints. All our products work together to seamlessly share threat intelligence and provide a connected threat defense with centralized visibility and investigation, enabling better, faster protection. With more than 6,00...
Tapping into blockchain revolution early enough translates into a substantial business competitiveness advantage. Codete comprehensively develops custom, blockchain-based business solutions, founded on the most advanced cryptographic innovations, and striking a balance point between complexity of the technologies used in quickly-changing stack building, business impact, and cost-effectiveness. Codete researches and provides business consultancy in the field of single most thrilling innovative te...