95-702 Distributed Systems Tuesday, May 11, 2010 Project 1 Due: Tuesday, May 25, 11:59:59 PM ========== ================================== This project has three objectives: First, the student is introduced to GlassFish. GlassFish is an open source application server that implements the JEE 5 specification. This tool is used throughout the course. The Netbeans integrated development environment is introduced and is used to build source code and interact with GlassFish. Second, the student builds his or her first set of distributed systems. The student builds three small web applications using Java Server Pages and servlets. Third, the student is introduced to the Android simulator. In this simple project, you will be using the simulator's browser capabilities. The simulator runs within the Eclipse IDE. A complete project will include a short paper (one or two pages in length). The paper will clearly and accurately explain the functional characteristics of the product in relation to the non-functional characteristics, demonstrating a nuanced comprehension of course content and explaining the technical aspects in relation to potential real-world applications. Several important characteristics of distributed systems will be discussed. For this project, the non-functional characteristics that must be considered include security, protocol layering and interoperability. In each part, documentation is required. The software that you write (HTML files, Java files and so on) must contain comments that describe what each significant piece of code is intended to accomplish. Points will be deducted if code is not well documented. Be sure to consult the rubric on the schedule for details on grading. For each of the three exercises below, submit a documented servlet and an index.jsp page. The documentation will include your name, a description of each piece of code and well-chosen variable names. There is an example on the schedule showing what we mean by "good documentation". In addition, you must submit screenshots that demonstrate your programs running. These screenshots will aide the grader in evaluating your project. Required Section 1. Write an index.jsp page that requests a user to enter a string of text data. Provide a submit button. When the submit button is pressed a servlet is executed. The servlet must be named ComputeHashes.java. The servlet will compute two cryptographic hash values from the text transmitted by the browser. One hash value will be computed using MD5 and the other using SHA-1. You will need to employ the Java crypto API to compute the MD5 and SHA1 hashes of the text. The original text will be echoed back to the browser along with the two hash values. The hash values will also be sent back to the browser and will appear as hexadecimal text and as text in base 64 notation. We will discuss the use of such hash values later in the course. To compute the MD5 and SHA-1 hashes, use these standard java packages: import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; To compute the Bas64 encoding, use the following package: import sun.misc.BASE64Encoder; The BASE64Encoder class is an internal non-documented class. BASE64Encoder objects have a method with the signature String encode(byte[]). It returns a base 64 sting encoding of an array of bytes. To compute the Hexadecimal representation of a byte array, use the following code: // From the web site "Real's How To" public String getHexString(byte[] b) throws Exception { String result = ""; for (int i=0; i < b.length; i++) { result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 ); } return result; } Be sure to provide a user friendly and attractive user interface. So that you may test your program, an example execution is provided. Computing hashes of Hello of length 5 SHA-1 (Hex):F7FF9E8B7BB2E09B70935A5D785E0CC5D9D0ABF0 SHA-1 (Base 64): 9/+ei3uy4Jtwk1pdeF4MxdnQq/A= MD5: (Hex): 8B1A9953C4611296A827ABF8C47804D7 MD5: (Base 64): ixqZU8RhEpaoJ6v4xHgE1w== 2. Write a simple web application that allows a user to perform one of three operations on two, possibly very large, integers. The operations will include addition and multiplication as well as an operation to determine if the two integers are relatively prime. A JSP page will present three input fields to the user. The first two will be used to collect the two integers. The third will be used to collect the operation type. The only operations supported will be "add", "multiply", and "relativelyPrime". Use drop down boxes in XHTML. A submit button will be provided and when it is hit a servlet will be visited. The servlet will be named BigCalc.java and will use the BigInteger class to perform the conversions from strings and the appropriate computation. The servlet will return the result to the browser marked up in HTML. You need to validate both integers and the operation. In the case of invalid input return an error message to the browser - but don't crash the server. The BigInteger class has multiply and add methods that will be used by the first two operations. For the operation that determines if the two integers are relatively prime use the gcd() method of the BigInteger class. If the greatest common divisor of the two integers is one then the two integers are relatively prime. Be sure to provide a user friendly and attractive user interface. Bonus Section 3. Write another web application using Netbeans. This application will determine if a string entered into a browser is a palindrome. A string is a palindrome if it is empty, has a singe character, or reads the same when reading from left to right or from right to left. Name your servlet Palin.java. Download and install the Android simulator from Google. Use the browser on the simulator to visit this web application. Produce a screen shot showing the simulator working on your web application. Notes: If you are not able to connect to localhost from your Android simulator, find the IP address of your machine and use that instead. Summary: There should be three projects in Netbeans. Each project will have its own index.jsp Each project will have a single servlet which would get called from the index.jsp The Netbeans projects will be named as follows: Project1Part1 Project1Part2 Project1Part3 The servlets will be named as follows: Project 1 - ComputeHashes.java Project 2 - BigCalc.java Project 3 - Palin.java We should visit Project1Part3 Palin.java servlet from an Android browser, so there is no Java coding in Android. Please include screenshots though. The submission should be a single zip file of all three projects plus screen shots.