Lab 4 Java-based Backend Authors: Sahand Sadjadee Alexander Kazen Gustav Bylund Per Jonsson Tobias Jansson Spring 2014 TDDI15 Advanced Programming and Interactivity on the WWW http://www.ida.liu.se/~TDDD24/ Department of Computer and Information Science (IDA) Linköping University Sweden 1. Introduction In this fourth lab, you will use Java to rewrite the Twidder backend previously developed in lab 2. The new version of backend shall contain all the functionality previously implemented in lab 2, as well as some new one. Once you are finished with this lab, you will present your work to your responsible lab assistant. For more specific information about the presentation and evaluation process of lab 4, please check section 4: Presentation and Evaluation. For more general information about the presentation and examination process, please check the course page. 2. Development tools Eclipse We shall use Eclipse in this lab, as Google has provided the Google Plugin for Eclipse which provides the whole API and tools required for developing web applications which can be uploaded and hosted by Google App Engine. Eclipse is available as an addable module on IDA Solaris systems. You can add it to your environment using the following command: module add prog/eclipse/4.2.1 once done you can run Eclipse by executing the following command: eclipse& Google Plugin In this lab, we will use Google Plugin which integrates Google App Engine SDK and Eclipse and helps us not directly work with GAE SDK. Google Plugin is pre­installed with Eclipse Juno on IDA computers. More information on Google Plugin can be found at the following links: Please keep in mind that although the App Engine has support for Python, we will be using Java in this lab. Note: As we developed the Twidder front­end directly using HTML/Javascript/CSS, we will not use GWT which has been designed for front­end development using Java language. We recommend that you have a look at GWT once you are done with this lab series and explore how it works. Once you intend to create a new web application project, please remember to unmark Google Web Toolkit and on IDA Solaris systems change the version of Google App Engine from 1.3.4 to 1.7.4. Google Plugin for Eclipse https://developers.google.com/appengine/docs/java/tools/eclipse A Quick Start https://developers.google.com/eclipse/ 3. Lab instructions As specified in the following, you at least need to fulfill the requirements for grade 3 to pass this course. For grade 4 and 5 more functionality is requested which are explained afterwards. Grade 3, All the server­functions implemented in lab 2 using Python will be re­implemented using Java Servlets. As Google App Engine provides only Google Channel API for full­duplex communication, you will use it to implement the auto refreshing mechanism for the Home tab wall. As Google uses a cloud environment to store all your application data, You will use the Datastore API, including JDO and JPA libraries, available as part of Google App Engine to implement the data­handling layer. Once you are done, your application shall be uploaded on Google App Engine. Please notice that your static files will be assigned arbitrary URLs which make them accessible from the client­side. the client.html shall be loaded and displayed as the application is opened by the user. What is Google App Engine https://developers.google.com/appengine/docs/whatisgoogleappengine https://developers.google.com/appengine/training/intro/whatisgae Google App Engine Introduction https://developers.google.com/appengine/docs/java/gettingstarted/introduction Google Channel API for Java https://developers.google.com/appengine/docs/java/channel/ Google Datastore API https://developers.google.com/appengine/docs/java/datastore/ Java Servlet Technology http://docs.oracle.com/javaee/6/tutorial/doc/bnafd.html Google App Engine API Javadoc https://developers.google.com/appengine/docs/java/javadoc/ Oracle Servlet API Javadoc http://docs.oracle.com/cd/E17802_01/products/products/servlet/2.5/docs/servlet­2_5­mr2/ Note: All the implemented server­functions shall be implemented exception free, in a way to be able to stand any possible input. Note: Please remember you will use Servlets built­in session handling mechanism. Grades 4 and 5 For receiving grade 4, you need to implement one of the following two functionalities. For grade 5, you must implement both functionalities. Media Handling As an extra functionality to what you have done for grade 3, you shall add the functionality by which a user will be able to upload a photo for his/her profile as he/she signs up. The uploaded image for each user shall be displayed in the following cases: 1. In the home tab along with other personal information as the user signs in. 2. In the browse tab, the image of viewed user shall be displayed along with his/her other information. 3. For each post, the image of the user posting the message will be displayed along with his/her name. The uploaded image shall be stored in the database using Datastore API and will be sent to the client as needed. In order to stream down the image to the client, you need to create a servlet named (for example) “/image” which takes a unique id, like the email of the owner of image, and streams the image from the database to the client. You can also use Base64 binary­text encoding for embedding the image as returned from the server as a text string and display it using <img> tag. Note: for creating dynamic images using a Servlet, the Servlet should return the image content read from the database with an appropriate MIME type. Base64 binary­text encoding on Wikipedia http://en.wikipedia.org/wiki/Base64 Java Server Pages As an extra task, you need to add a new functionality to your application by which the signed­in user can see all the messages he/she has posted on other users’ walls. For doing that you shall use a Java Server Page, which is accessible to the signed­in user via an additional link or button located in the home tab. The specified Java Server Page shall open in a new window displaying the whole history of the posted messages. Please remember that you will not use JSP built­in session handling mechanism. Java Server Pages are used for performing server­side rendering against what we have been doing through the whole lab series. As our Twidder application has been a Single Page Application, we avoided using cookies as cookies are exchanged among the client and server continuously. Using Java Server Pages in Google App Engine https://developers.google.com/appengine/docs/java/gettingstarted/usingjsps Java Server Pages Syntax Reference http://www.oracle.com/technetwork/java/syntaxref12­149806.pdf Note: The sent token to the Java Server Page shall not be displayed in the address bar. 4. Presentation and Evaluation Once you are finished with lab 4, you will present your work to your responsible lab assistant during a scheduled lab session. The result of your work is evaluated based on what you have been required to do and how you have achieved it.