95-733 Internet Technologies Tuesday September 1, 2015 Homework 1 Due: 11:59 PM Tuesday September 15, 2015 Programming with servlets, AJAX, JSON, and RSS ============================================== This project has several objectives. First, you will be exposed to building Java servlets and server side programming. Second, you will learn to use Javascript and HTML for client side programming. Third, you will need to learn about cookies and session handling and how several concurrent visitors may maintain state on the server. Fourth, you will work with a single page web application that uses AJAX for asynchronous calls. And finally, you will be exposed to RSS XML. 0) Read the article by Philip McCarthy on Ajax at: http://www.ibm.com/developerworks/library/j-ajax1/ The source code is available in a zip file at the bottom of the article. 1) 10 Points. Build a working Ajax shopping cart using the code from the article. So that the TA's have an easy time grading the assignments, Netbeans and Glassfish will be used as demonstrated in class. Name your project ACoolAJAXShoppingCart. Grading: The grader will test this and will be looking for solid documentation. That is, you must provide comments throughout the code. These comments will server to convince the grader that you have studied the code and understand it and that you are able to clearly and succinctly explain what it does. You are being asked to document code that you did not write. 2) 20 Points. Improve the application by adding a button to each item displayed so that the user may delete items from the shopping cart. Your delete button will behave like the add button, but will count down rather than up. If an item is not currently in the cart then a delete request will be ignored. If a delete request causes a quantity to go to zero then the deleted item will be removed from the cart and no longer displayed. Name your project ACoolAJAXShoppingCartImproved. Finally, add a new item to the shopping card catalog. This item will be of your own choosing. Grading. The documentation from the first part will be found within this code as well. In addition, be sure to document the modifications that you made. The application will be tested. 3) 30 Points. Modify your solution to part 2 so that it uses JSON rather than XML. You are required to use the Google JSON libray found here: http://code.google.com/p/json-sans-eval/. Note that your servlet will generate a content type of application/json and your XMLHttpRequest object will return JSON via the responseText property rather than the responseXML property. This part requires that you design a JSON string that corresponds to the XML shopping cart. Be sure to see Google's example at the link given above. Note the full example on the course schedule showing how JSON may be generated on the server and read on the client. For a careful description of JSON see http://www.json.org/ Note that there is a bug in this web application. Enter a few items into the shopping cart and then refresh the page. Only after an additional item is selected will the contents of the cart reappear. Make a simple modification to the index.jsp page to repair this bug. Name your project ACoolAJAXShoppingCartImprovedWithJSON Grading. The documentation from the second part will be found within this code as well. In addition, be sure to document the modifications that you made. How were you able to fix the bug? This should be clearly specified in the documentation. The application will be tested. You may choose to use a library to generate the JSON or you may choose to generate the JSON by hand coding - as the XML is hand coded in McCarthy's article. 4) 35 Points. Make the necessary changes to the web application in 3) so that it displays a catalog of RSS feeds rather than shopping items. The HTML table will display the following items: Name Source Add Remove America News NYT America News USA News NYT USA news New South Wales News Sydney Morning Herald New South Wales News IT Pro News Sydney Morning Herald IT Pro News Latin America BBC Latin American News Adelaide News Adelaide News from Adelaide Now Internally to your application, the Item class will contain fields for an item code, name, description and URL. Each field is a Java String. You will need to define a simple code so that items may be looked up and stored in the hash tables (one for the catalog and one for the cart). Internal to your application, each item will be associated with an RSS URL. The seven URL's are: NYT America News http://rss.nytimes.com/services/xml/rss/nyt/Americas.xml USA News http://rss.nytimes.com/services/xml/rss/nyt/US.xml New South Wales http://www.smh.com.au/rssheadlines/nsw/article/rss.xml IT Pro News http://feeds.smh.com.au/rssheadlines/itpro.xml Latin America http://feeds.bbci.co.uk/news/world/latin_america/rss.xml Adelaide News http://feeds.news.com.au/public/rss/2.0/anow_state_191.xml When examining the output from these URL's, be sure to use Firefox or Chrome. When an add button is pressed, a particular news source will be added to the cart. When a delete button is pressed, a particular new source will be removed from the cart. Obviously, there is no longer any price associated with these items and no longer any need to compute a total price for the cart. On the right hand side of the page, your program will display the name of each selected source in a bulleted list. If an add button is pressed more than once for the same item, only the first press will have any effect. If the delete button is pressed more than once for a particular item, only the first will have any effect. The bulleted list will grow and shrink as the user makes selections using the add and delete buttons. We will not have a total price field on the right side of the page. We will have a "Number of feeds selected" field. Initially, the number of feeds selected is 0 and this value goes up and down as the user adds and deletes feeds. Add a "Show Documents" button to your page. When pressed, it will cause an AJAX request to the server. The server will use a BufferedReader to read individual characters from each dereferenced RSS feed that is in this particular user's cart. A single String will be returned to the browser containing all of the RSS from each feed. Display this text on the browser (below where the selection table appears). Note that we are not using any XML parser on the server side. We are reading a character at a time from the dereferenced URL and returning a simple String from the server. We will visit parsing and transformations later in the course. Name your project ACoolAJAXShoppingCartImprovedWithJSONandRSS. Finally, add a new item to the RSS catalog. This item will be of your own choosing. Grading: The grader will be looking for solid documentation. That is, you must provide comments throughout the code. These comments will clearly and succinctly explain what the code does. NOTE: You are being asked to document code that you did not write. Submission Requirements 5 Points ================================ Place all of your work into a single directory named Homework1. This directory will contain the four Netbeans projects as named above. Zip this directory into a file named Homework1.zip. Submit your zip file to the Assignment section of Blackboard.