Top Banner
An Empirical Study & Implementation of UI Layer In A J2EE Application: A Case Study (Starred Paper Defense) By, Maqbool Khan Committee Members Dr. Donald Hamnes (advisor) Dr. Richard Heath (advisor) Dr. Sarnath Ramnath
40

Committee Members Dr. Donald Hamnes (advisor) Dr. Richard Heath (advisor) Dr. Sarnath Ramnath

Jan 12, 2016

Download

Documents

madra

An Empirical Study & Implementation of UI Layer In A J2EE Application: A Case Study (Starred Paper Defense) By, Maqbool Khan. Committee Members Dr. Donald Hamnes (advisor) Dr. Richard Heath (advisor) Dr. Sarnath Ramnath. Presentation Goals. Outline the goals of this paper - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

An Empirical Study & Implementation of UI Layer In A J2EE Application: A Case Study

(Starred Paper Defense)By,

Maqbool Khan

Committee Members

Dr. Donald Hamnes (advisor)Dr. Richard Heath (advisor)

Dr. Sarnath Ramnath

Page 2: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 2

Presentation Goals Outline the goals of this paper Introduce Servlets and JSPs from 8,850

meters Discuss Struts and JSF, again from 8,850

meters Substantiate the development of a new

framework Layout the framework features

Page 3: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 3

Presentation Goals (continued) Tutorial on how to use the framework, via a

case study (Web Store) Demonstration, again via the help of the Web

Store app High-level discussion on framework design Subliminally underscore the importance of this

paper

What not to expect: An in depth discussion or tutorial on the technologies referred in the paper

Page 4: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 4

Starred Paper Goals Study J2EE web application development:

Technology (JSP & Servlets) Web application design Frameworks (Struts & JSF)

Design and develop a J2EE web application framework Provide a cooks tour to the design of the framework

Disclaimer: The paper discusses the shortcomings of Struts and JSF and proposes a new framework

to resolve them. However, it is not the intention of this paper to better or compete with either of these frameworks. In other words, it does not claim to be a replacement for these frameworks or superior to them in any ways or means.

Page 5: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 5

Technology - Servlets A J2EE component, which runs inside a Servlet

container Acts as an intermediary between any HTTP clients and

your server side application Provides the developer with the capability to extend the

web server Part of J2EE specification Not limited to HTTP clients or Web servers

Page 6: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 6

Technology – Servlets (continued) Implements the javax.servlet.Servlet interface Not thread safe Often times pooled (depends on the application server) Below is a simple example which returns the current Date:

public class DateServlet extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

out.println(<body>);

out.println(<b> Date: </b>);

out.println(new Date());

}

}

Page 7: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 7

Technology – Servlets (continued)

Strengths (not exhaustive): Servlets are nothing but Java objects and are very good at

invoking business logic.

Weaknesses: Can’t see the generated markup Intermixing of markup and Java code complicates

maintenance and also internationalization Promotes poor division of responsibility among the

developers

Page 8: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 8

Technology - JSP A templating approach to web application development Part of the J2EE specification Below is an example which displays the current date on the

browser:<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">

<jsp:directive.page contentType="text/html"/>

<jsp:directive.page import="java.util.Date"/>

<html>

<head><title>Today’s date</title></head>

<body> <b>Date: </b> <%=new Date( ) %> </body>

</html>

</jsp:root>

Page 9: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 9

Technology – JSP (continued)Strengths:

Template approach makes it simple and productive for markup developers to create dynamic web pages

Weaknesses: Use of scriplets makes it difficult to see the generated markup Scriplets are hard to test and cannot be reused Intermixing of markup and Java code makes it difficult to both

develop and maintain web applications Pure JSP approach makes it harder to understand the

application flow

Page 10: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 10

Struts Open source J2EE web application

framework First and the most popular (about 30k

downloads/month) Based on MVC paradigm Available from the house of Apache

Page 11: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 11

Struts – Flow

Page 12: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 12

Struts – Strengths Most mature J2EE web application framework

available today Very good support Simple to use The tag libraries are very good Simple to introduce in an existing application

Page 13: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 13

Struts – Weaknesses ActionForm approach is a pain (redundant

work) No native support for view technologies other

than JSPs Promotes implementation inheritance No native support for AJAX

Page 14: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 14

JSF Component oriented server side user interface

framework It is a standard (not an implementation) Part of J2EE specification Sun’s and other industry heavy weights take on

J2EE web application frameworks Based on MVC paradigm

Page 15: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 15

JSF - Flow

Page 16: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 16

JSF - Strengths Part of the J2EE standard Due to its component nature, it works very

well with the tools Supports multiple clients like browser,

mobile phones, etc. Good navigation support

Page 17: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 17

JSF – Weaknesses Too many tags to learn No one standard implementation Still immature Lack of good and detail documentation like

Struts No native support for AJAX

Page 18: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 18

Why Another Framework? Lack of one good web framework for J2EE web

application development No good web framework available for Web 2.0

development Need for a pragmatic reference My profound interest in framework and OO

development

Page 19: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 19

Framework Features MVC based with more

emphasis on controller Easy to learn and

simple to use Pattern oriented Simplifies unit testing

Keeps the UI layer thin Avoids XML and

embraces annotations Supports generics Extensible Simple code base

Page 20: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 20

Framework Features (continued) Automatic validation of

request parameters Does not force the client

code into implementation inheritance

Automatic request parameters to domain object binding

Supports multiple view technologies and not just JSPs

Declarative navigation Scope set up (setting

variables automatically in request or session scope)

Page 21: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 21

Case Study – Web Store A simple web site where you can go browse the products

available for sale but not buy them (helps to keep the business strong regardless of the economy and market )

Use cases:1. The user visits the application and is asked for authentication. If authorized,

the user enters the web store and browses the list of products available in his area of residence (same zip code)

2. The user browses the complete products list (not filtered by zip code)3. The user selects a product from the list and views its details4. The user adds a product to the catalog (needs to be audited) 5. The system should ensure that a single user cannot add more than 5 items

in one week6. The system should also ensure that the product name must be in between 3

and 40 characters and its price must be between $100 and $10000

Page 22: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 22

Case Study – Web Store (Model)

Page 23: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 23

Framework Tutorial Let’s take use case #4 and see how it will be

implemented We will implement this in 4 steps

Step 1: Write your domain object class and annotate the fields in order for validation to be performed on them

Step 2: Write your service class and annotate your action handling method

Step 3: Write your JSP by following the naming conventions

Step 4: Write your interceptors, if you need any (Optional)

Page 24: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 24

Framework Tutorial – Step 1 Code the product class and define the validator annotations:

public class Product {@AStringValidator(isNullAllowed = false, maxLength = 20, minLength = 3, errorMessage = "The product name has to be in between 3 and 20")private String name;private String productDescription;

@ADoubleValidator(max = 100000, min = 100,errorMessage = "the product price has to be in between 100 and 100000")private double price;private User seller;private Date addedOn;

//accessors left out for the sake of brevity}

Page 25: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 25

Framework Tutorial – Step 2 Code the product service class and define the control flow :

@AExpose(expose = true, allow= {"add", "showDetails", "showAll"})public class ProductService {

@ADomainObject(clazz = Product.class, scope = EScope.REQUEST)@AValidate(method="canAdd")@AInterceptor(interceptors = {Audit.class})@AView(resourceName = "productList", errorResourceName = "addProduct")@AScope(key="productList")public List<Product> add(Product product) {

ProductList.getInstance().add(product);return ProductList.getInstance().displayList(product.getZipCode());

}

Page 26: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 26

Framework Tutorial – Step 2 (continued)public boolean canAdd(Product product){

boolean isNotAvailable = product.isNotAvailable();if(!isNotAvailable){

WebUtils.setExecutionError("Product name", "A product with a similar name already exists. Please choose a different name.");

return false;}

Calendar calendar = Calendar.getInstance();calendar.add(Calendar.DAY_OF_MONTH, -5);Date fromDate = calendar.getTime();if(ProductList.getInstance().getProductCountByUser(product.getSellerName(),

fromDate) >= 5){WebUtils.setExecutionError("BuisnessLogic", "You have already added 5

products in the " + "last one week and can't go beyond that. Please try adding next week");

return false;}return true;

}

Page 27: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 27

Framework Tutorial – Step 3 Code the JSP page following the naming conventions:

<%@ taglib uri="/WEB-INF/tld/webframework.tld" prefix="webframework" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <HTML><HEAD><TITLE>Add Product</TITLE></HEAD><BODY><center><h1>Web Store</h1></center><form action="examples.webstore.service.ProductService.add.invoke" method="post"><table width="100%"> <tr width="100%" align="right">

<td align = "right"> <c:url value="examples.webstore.service.LoginService.logout.invoke" var="logout“ /> <a href= "${logout}"> logout </a></td></tr>

</table><webframework:erros/><h3>Add Product</h3><table><tr><td> Product Name: </td> <td> <input name="name"/> </td> </tr><tr><td> Price: </td> <td> <input name="price" id="price"/> </td> </tr><tr><td> Description: </td> <td> <input type="text" name="productDescription"/> </td> </tr><tr><td></td><td> <input type="submit" value="Save"/> </td></tr></table></form></html>

Page 28: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 28

Framework Tutorial – Step 4 Code the Audit interceptor:

public class Audit implements IInterceptor< Product > {public EInterceptorFlow preProcess(Product product, ServletRequest request, ServletResponse response) {

//TODO: Add request info to the audit logreturn EInterceptorFlow.SKIP_POST_PROCESSING;

}public EInterceptorFlow postProcess(Product product, ServletRequest request, ServletResponse response) {

//would be skipped because preProcess returned SKIP_POST_PROCESSING

return EInterceptorFlow.CONTINUE;}

}

Page 29: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 29

Framework DesignReceive HTTP

request

Create Action context

Abort processing

[ Not allowed ]Perform type

conversion

[ Allowed ]

Perform validation

Populate domain object

Perform business validation

Render View

Check invocation

[ conversion errors ]

[ No conversion errors ]

Pre-process interceptors

Invoke Action

Post-process interceptors

[ failed ] [ success ]

[ DO population errors ]

[ no errors ]

[ abort further processing ]

[ continue ]

Page 30: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 30

Framework Design (continued)

Page 31: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 31

Framework Design - Components Controller:

Receives the HTTP request Creates the request flow with the help of annotations Validates the parameters and populates the domain object.

This requires help from both the converter and validator components

Invokes the business logic along with the interceptors Delegates further processing to the appropriate view

technology handler

Page 32: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 32

Framework Design – Components (Continued) Annotations: Defines the flow of a request and also how

the various other components will interact.

Converter: Converts the HTTP request parameters from String type to the appropriate domain object attribute type.

Validators: Validates the HTTP request parameters using the validations rules defined by the domain object.

Page 33: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 33

Framework Design – Components (Continued)

View: Generates the markup using the information available in the view context and domain object

Interceptor: Common pieces of code which should be executed before and after the action invocation

Context: Defines the message using which the framework’s components communicate

Page 34: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 34

Framework Design (continued)

Page 35: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 35

Framework Design (continued)

Page 36: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 36

Future Improvements Compile time annotations Client side validation Action chaining Internationalization Integration with Spring IOC Cluster compliant context caching strategy Basic implementation of view technology handlers

Page 37: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 37

Acknowledgements Sincere thanks to all my committee members, Dr.

Donald Hamnes, Dr. Richard Heath and Dr. Sarnath Ramnath for letting me choose this topic and helping me write this paper.

Thank you all for your help!!!

Page 38: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 38

Bibliography Java language specification, http://java.sun.com/docs/books/jls / Java 2 Platform Enterprise Edition (J2EE), Platform specification, version 1.3, http://java.sun.com/j2ee/ Servlet, http://java.sun.com/products/servlet / JSP, http://java.sun.com/products/jsp / Unified expression language, http://java.sun.com/products/jsp/reference/techart/unifiedEL.html JSF specification, http://java.sun.com/j2ee/javaserverfaces/ HTTP: Hyper Text Transfer Protocol IETF Standard, RFC: 2616, http://www.ietf.org/rfc/rfc2616.txt HTML specification, http://www.w3.org/TR/REC-html40/ XML specification, http://www.w3.org/TR/REC-xml/ JavaScript specification, http://www.ecma-international.org/publications/standards/Ecma-262.htm Java Bean Specification, http://java.sun.com/products/javabeans/docs/spec.html Tag Libraries. http://java.sun.com/products/jsp/taglibraries.html . The Cascading Stylesheet Language, http://www.w3.org/Style/CSS/. AJAX patterns, http://ajaxpatterns.org / Portland Pattern Repository, http://c2.com/ppr/ How to use design patterns, http://www.artima.com/lejava/articles/gammadp.html Web tier application framework and design, http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html Jeff Offutt, "Quality Attributes of Web Software Applications," IEEE Software, vol. 19, no. 2, Mar/Apr,  2002, IEEE. Yu Ping, Kostas Kontogiannis and Terence C. Lau, “Transforming Legacy Web Applications to the MVC Architecture”, Eleventh Annual International Workshop on

Software Technology and Engineering Practice, 2003, IEEE. M. Fowler, “Is design dead?”, http://www.martinfowler.com/articles/designDead.html Dabo Sun, Kenny Wong, Daniel Moise, “Lessons Learned in Web Site Architectures for Public Utilities”, 5th International Workshop on Web Site Evolution, 2003. Ralph Johnson, “Patterns of thought”, http://citeseer.ist.psu.edu/gamma93design.html Kent Beck and Ralph Jhonson, “Patterns generate architectures”, European Conference on Object Oriented Programming, July 1994. Springer-Verlag. Eric Gamma, Richard Helm, Ralph Johnson, John Vissides, “Design Patterns: Abstraction and reuse of object oriented designs”, Lecture Notes in Computer Science,

1993, http://citeseer.ist.psu.edu/gamma93design.html Erich Gamma and Kent Beck, “JUnit a Cook’s tour”, http://junit.sourceforge.net/doc/cookstour/cookstour.htm What is Web 2.0, http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html Struts, http://struts.apache.org/userGuide / Log4J, http://logging.apache.org/log4j/docs/ JUnit, http://www.junit.org/index.htm Cactus, http://jakarta.apache.org/cactus/index.html Java Reflection, http://java.sun.com/docs/books/tutorial/reflect/ Threads, http://java.sun.com/docs/books/tutorial/essential/threads/

Page 39: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 39

Bibliography (continued) James Turner and Kevin Bedell, Struts kick start, Sams, Dec 2002 David Geary and Cay Horstmann, Core Java server faces, Prentice Hall PTR, June 2004 Martin Fowler, Patterns of enterprise application architecture, 1st edition, Addison-Wesley Professional, November 2002 Eric Gamma, Richard Helm, Ralph Johnson, John Vissides, Design Patterns, Elements of reusable object – oriented software, 1st edition, Addison-Wesley Professional,

January 1995 DeepakAlur, John Crupi and Dan Malks, Core J2EE Patterns, Best Practices and Design Stratergies, 2nd edition, Prentice Hall PTR, May 2003 Mark Grand, Patterns in Java: A Catalog of Reusable Design Patterns Illustrated with UML, 2nd Edition, Volume 1, Wiley, September 2002 Rod Johnson, Expert one-on-one J2EE design and development, New Ed edition, Wiley, October 2002 Ira R. Forman, Nate Forman, Java Reflection in Action (In Action series), Manning Publications, October 2004 Chopra, Eaves, Jones, Li and Bell, Beginning Java Server Pages, Wrox, February 2005 Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlac and Micheal Stal , Pattern oriented software architecture – A system of patterns, volume 1, John Wiley &

Sons, August 1996 Ralph Johnson, “Documenting frameworks using patterns”, Object Oriented Programming Systems, Languages and Applications Conference Proceedings, October 1992, ACM press.

Erich Gamma and Kent Beck, Contributing to Eclipse: Principles, Patterns and Plugins, 1st edition , Addison-Wesley Professional, October 2003 Setve McConell , Code Complete, 2nd Edition, Microsoft Press, June 2004 Andrew Hunt and David Thomas, Pragmatic programmer, The: From journeyman to master, 1st edition, Addison-Wesley Professional, October 1999 Eric Freeman and Elisabeth Freeman, Head first design patterns, O'Reilly Media, October 2004 Spring framework, http://www.springframework.org/ Direct Web Remoting (DWR), http://getahead.ltd.uk/dwr/ Joshua Kerievsky, Refactoring to patterns, Addison-Wesley Professional, August 2004 Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts, Refactoring: Improving the Design of Existing Code, 1st edition, Addison-Wesley Professional, June

1999 Derek C. Ashmore, The J2EE Architects Handbook, DVT Press, May 2004 Joshua Bloch, Effective Java™: Programming Language Guide, 1st edition, Addison-Wesley Professional, June 2001 Ted Neward, Effective Enterprise Java, Addison-Wesley Professional, August 2004 Martin Fowler, Inversion of Control Containers and the Dependency Injection pattern, January 2004 Kent Beck, Test driven development by example, 1st edition, Addison-Wesley Professional, November 2002 Annotations, http://java.sun.com/docs/books/tutorial/java/javaOO/annotations.html Martin fowler and James Rumbaugh, UML distilled, 3rd edition, Addison-Wesley Professional, September 2003 Jason Hunter, Java Servlet programming, 2nd edition, O'Reilly Media, January 2001 JSP Specification 0.92, http://www.kirkdorffer.com/jspspecs/jsp092.html Matt Raible, “Java Web Frameworks”, open source landscape series, http://www.virtuas.com/osl-jwf-01.pdf Comparing Web frameworks, www.chariotsolutions.com/ slides/osconf2005-webframeworks.pdf Java Web Framework Sweet Spots - By Matt Raible, http://www.virtuas.com/articles/webframework-sweetspots.html

Page 40: Committee Members Dr. Donald Hamnes  (advisor) Dr. Richard Heath  (advisor) Dr. Sarnath Ramnath

(Starred Paper Defense) 40

Q & A