Lab 6
Get started now

Objectives

Students are given the option of developing this assignment as a desktop app with Swing or as an Android app. You are only required to do one of the two.

Common To Both Swing and Android

  • Properly handle exceptions generated by an external class
  • Use exception logging to track the occurrence of exceptions

Swing App

  • Construct software which uses a GridBagLayout
  • Implement software with anonymous inner classes
  • Implement action listeners to detect events in text entry boxes
  • Integrate JOptionPane classes into the handling of exceptions

Android App

  • Install Android Studio development environment
  • Run Android application on emulator

Assignment

The web is a wonderful place. We've all used a web browser to do useful things. But what is a web browser in reality? A web browser is a software package that downloads and renders files. Some files are text. Some files are binary. Some files have specific meaning such as images. But, all in all, the web just consists of a bunch of files that are accessed using a web protocol. In future classes you will learn more of the details of the web protocol. In this assignment you will build a system which will allow you to monitor material on the web. In specific, this application will:

  1. Allow us to enter a URL
  2. Download the content of the URL
  3. Inform us of the filesize
  4. Inform us of the time it takes to download the material
  5. Indicate which port the download is using
  6. Indicate the name of the host

You will be able to enter a valid URL and change the timeout, or how long we wait for the connection to be made.

WebsiteTester Class

You are to make use of a provided class: WebsiteTester (javadoc). This class is prebuilt in provided in a lab6.jar file. This class connects with the web server and analyzes the connection.

Desktop Application Details

UML Class Diagram

You must write the WebsiteTesterUI class. You must use a GridBagLayout layout manager.

Desktop GUI

Android App Details

First you will need to install the Android development environment on your computer.

Android App

Students doing the Android app should download the lab6.zip file which contains the complete Android Studio project. All of the required changes are in the WebsiteTesterActivity class and identified with TODO comments. To load the project:

  1. Unzip the file and place the Lab6 folder at the root of the D: drive (D:\Lab6)
  2. Start Android Studio
  3. Select Open an existing Android Studio project
  4. Browse to D:\Lab6 and click OK
  5. Change Gradle project to D:\Lab6
    Gradle Dialog
  6. Ensure that Use default gradle wrapper (recommended) is selected
  7. Click OK and wait until the project opens and the gradle tasks complete
  8. Open the WebsiteTesterActivity class by expanding the app -> java -> edu.msoe.se1021 folder structure in the project pane
    Project Pane

Operation

Operation of the program begins with the user starting the program. The program will start with http://msoe.us/taylor/se1021/Lab6 as the default URL. The timeout will be set to the default value from the WebsiteTester class. The size, port, download time, and host entries will be blank, as well as the text area containing the text from the website.

The user can then enter different text into the URL dialog box. When the user presses the enter key, an event will cause the URL to be sent to the WebsiteTester instance.

Students implementing the Android version of the assignment should refer to the TODO comments in the WebsiteTesterActivity class to determine exactly what needs to be done.

Students implementing the desktop version of the assignment should refer to the sequence diagram below to determine exactly what needs to be done.

Sequence Diagram (click on figure for larger version)

Exception Handling

All exceptions generated shall be logged. The desktop application must use the Logger class. In specific, all exceptions shall be written to the file exceptions.log. The Android app must use the Log class.

Invalid URL in text field when user presses enter

In the event that the user enters an invalid URL in the text field and presses enter, a message dialog box shall be opened indicating that the text entered in the text field is invalid and the URL will be set to an empty string. Note: the Android app does not respond to enter being pressed in the URL text field, so this only applies to the desktop application.

Invalid Timeout

If the timeout is invalid when an attempt is made to set the timeout, a message dialog box shall be opened indicating that an invalid timeout has been entered by the user. When the dialog closes, the text in the text field shall revert to the timeout present in the WebsiteTester object.

Analyze Error

When the user clicks on Analyze, there is the potential for several errors to occur. First and foremost, there is the possibility that the URL is Malformed. If this is the case, a text entry indicating that the text in the box is invalid shall be issued and the url shall be set to a blank entry.

If there is a socket timeout exception, a confirmation dialog shall be opened indicating that the connection has timed out and asking if they would like to extend the timeout. If they would like to extend the timeout, then an input dialog shall be opened allowing the user to set the new timeout.

If the host cannot be found, a message shall be displayed indicating that the user has attempted to reach a host which does not exist.

If a general IO error occurs, a message shall be shown indicating that there was a problem reading from the given file.

The desktop application should use JOptionPane dialogs. The Android application should use the ErrorDialog and SocketDialog classes provided in the Android project.

Sample Error Dialogs

Error dialog when URL field is blank

Error dialog when URL is http://www.msoe.edv

Result when URL is http://www.taylor.us:80

Error dialog when Timeout is set to 10 ms and the user attempts to reach http://www.msoe.edu

Resulting dialog after user presses Yes on the Connection Timeout dialog

Error dialog when URL is http://www.msoe.edu/results.php

Error dialog when timeout is set to a negative value

Error dialog when URL is set to Hello World

Coding Standard Additions for Exceptions

The following additions to the coding standard must be observed when using expection handling.

  • General catch blocks (e.g., (Exception e) are avoided
  • Catch blocks with auto-generated code (e.g., e.printStackTrace() or // TODO) are not left unmodified
  • Exceptions are only caught when a sensible response is placed in catch blocks

Lab Deliverables

See your professor's instructions for details on submission guidelines and due dates.
Dr. Dennis' students: See Blackboard
See Dr. Rebenitsch for instructions
Dr. Taylor's students: See below
See Prof. Ung for instructions
If you have any questions, consult your instructor.

Acknowledgment

This laboratory assignment was developed by Dr. Walt Schilling. Prof. Baohuy Ung developed the Android implementation.

Monday, 09-Jan-2017 23:00:05 CST