APPENDIX B

Google App Engine Code Examples

By using Google App Engine’s Eclipse plugin, the basic structure, including the connectivity between the application and Google’s cloud, is automatically generated upon the creation of a new project. The initial project generated by the plugin is a fully deployable “Hello, world” application that can be pushed to the cloud through a straightforward dialog in Eclipse. Google’s “Getting Started” guide walks users through their first application. From there, Vogel’s tutorial [43] was used to create the To Do application, although several alterations were made along the way.

Due to the use of tutorials and the number of files involved, only selections from the GAE code are included below. As the purpose of this book was to focus on the TaaS tools, this appendix only aims to offer a brief overview of the code, rather than an in-depth explanation. The initial overview of the system under test was given in Section 4.3.3. The basic structure of the non-Google-generated code is shown below:

•  “src” - Source folder

º  “dao” – Data Access Object (DAO) folder

5.5.1. Dao.java

• EMFService.java

º  “model” – The model classes folder

• Todo.java

• User.java

º  CreateTodoServlet.java

º  LoginServlet.java

º  LogoutServlet.java

º  RemoveTodoServlet.java

•  “war” - Web Archive (WAR) folder

º  “css”

• main.css

º  TodoApplication.jsp

The “model” folder contains the classes used for storing data. Both files contain associated variables and the necessary accessor and mutator methods. Additionally, “Todo.java” contains converters for the date format required as by the create and due date fields. The “dao” folder allows data to be accessed by the application. “EMFService.java” simply sets up the instance used by “Dao.java” to query the datastore. The excerpt below is from “Dao.java” and shows how the “To Do” items are added, removed, and retrieved for the user.

Excerpt from Dao.java

Images

Images

The servlets are used to transport data between the application and the datastore. The servlets are defined in the “web.xml” file within the “WEB-INF” folder (part of the WAR). Below is the definition of the “CreateTodo” servlet, used to create the actual “To Do” record. The next code section shows the actual “CreateTodoServlet.java” file, which calls the DAO to complete the addition.

Excerpt from web.xml

Images

CreateTodoServlet.java

Note: The package and imports were removed to conserve space.

Images

Images

Within the “war” folder, the only new files are the actual webpage and the associated style sheet. The JavaServer Page (JSP) allows the creation of dynamically generated web pages, using a combination of technologies; in this case, “TodoApplication.jsp” is written in HTML and Java. The following excerpts show how the “To Do” list is obtained and displayed and how new items can be added.

Excerpts from TodoApplication.jsp

The following excerpt shows how the DAO is called to get the current user and obtain the list of “To Do” items for the user.

Images

The next excerpt shows how the table of “To Do” items is generated using the “todoList” object created in the previous excerpt.

Images

The final excerpt shows the form used to add new records. The form action is defined in “web.xml” (shown previously). The data in each input field is retrieved by the servlet and sent to the DAO.

Images

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.74.211