comp9321 web application engineeringcs9321/15s2/lectures/lec08/lec-08.pdf · assignment 2 comp9321,...

51
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 8 1 COMP9321, 15s2, Week 8 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2411

Upload: others

Post on 03-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

COMP9321 Web Application EngineeringSemester 2, 2015

Dr. Amin BeheshtiService Oriented Computing Group, CSE, UNSW Australia

Week 8

1COMP9321, 15s2, Week 8

http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2411

Page 2: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Assignment 2

2COMP9321, 15s2, Week 8

Deadline Extended:

The due date for assignment2 is (end of Mid Semester Break): Sunday, October 4 2015, 23:59:59.

Demo: Week 10 (the week starting 5 October), during the lab times in

UNSW, CSE, Calendar:http://www.cse.unsw.com/about-us/organisational-structure/student-services/calendar/

Page 3: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

J2EE Design Patterns

3COMP9321, 15s2, Week 8

Last Week, Design Pattern Part I:

Model View Controller: • MVC is the J2EE BluePrints recommended architectural design pattern for

interactive applications.

Front Controller (Command): • For providing a central dispatch point to handle all incoming requests.

Page 4: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

J2EE Design Patterns

4COMP9321, 15s2, Week 8

This Week, Design Pattern Part II:

Service Locator: • Typically used in business layer for locating resources (such as database

connection)

Data Access Object: • A typical pattern for data access layer (linking the data storage layer with

the application)

Business Delegate: • A pattern to reduce coupling between presentation-tier clients and

business services.

Page 5: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

5COMP9321, 15s2, Week 8

Page 6: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

6COMP9321, 15s2, Week 8

ContextService lookup and creation involves complex interfaces and network operations.

Problem• The service locator pattern is a design pattern used in software development to

encapsulate the processes involved in obtaining a service with a strongabstraction layer.

• When J2EE clients interact with the server side components (EJB: EnterpriseJava Beans) or DataSources, clients must locate the service component, whichreferred to as a lookup operation in JNDI: Java Naming and Directory Interface.

• Locating a JNDI-managed service object is common to all clients that need toaccess that service object.

• It is easy to see that many types of clients repeatedly use the JNDI service, andthe JNDI code appears multiple times across these clients. This results in anunnecessary duplication of code in the clients that need to look up services.

Page 7: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

7COMP9321, 15s2, Week 8

Solution

• Using a central registry known as the "service locator", which on request returnsthe information necessary to perform a certain task.

• Service Locator object will abstract all JNDI usage to hide the complexities ofinitial context creation and lookup operations

• Multiple clients can reuse the Service Locator object to reduce code complexity,provide a single point of control

msdn.microsoft.com

Page 8: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

8COMP9321, 15s2, Week 8

To build a service locator pattern, we need:

Service Locator

InitialContext

ServiceFactory

BusinessService

Page 9: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

9COMP9321, 15s2, Week 8

To build a service locator pattern, we need:

Service Locator:The Service Locator abstracts the API lookup services, vendor dependencies, lookupcomplexities, and business object creation, and provides a simple interface to clients.

InitialContext

ServiceFactory

BusinessService

Page 10: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

10COMP9321, 15s2, Week 8

To build a service locator pattern, we need:

Service Locator:The Service Locator abstracts the API lookup services, vendor dependencies, lookupcomplexities, and business object creation, and provides a simple interface to clients.

InitialContext:The InitialContext object is the start point in the lookup and creation process.

ServiceFactory:

BusinessService:

Page 11: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

11COMP9321, 15s2, Week 8

To build a service locator pattern, we need:

Service Locator:The Service Locator abstracts the API lookup services, vendor dependencies, lookupcomplexities, and business object creation, and provides a simple interface to clients.

InitialContext:The InitialContext object is the start point in the lookup and creation process.

ServiceFactory:The ServiceFactory object represents an object that provides life cycle management forthe BusinessService objects. eg., The ServiceFactory object for enterprise beans is anEJBHome object.

BusinessService:

Page 12: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

12COMP9321, 15s2, Week 8

To build a service locator pattern, we need:

Service Locator:The Service Locator abstracts the API lookup services, vendor dependencies, lookupcomplexities, and business object creation, and provides a simple interface to clients.

InitialContext:The InitialContext object is the start point in the lookup and creation process.

ServiceFactory: The ServiceFactory object represents an object that provides life cyclemanagement for the BusinessService objects. eg., The ServiceFactory object forenterprise beans is an EJBHome object.

BusinessService: is a role that is fulled by the service that the client is seeking toaccess. The BusinessService object :• is created or looked up or removed by the ServiceFactory.• in the context of an EJB application is an enterprise bean.• the context of JDBC is a DataSource.

Page 13: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Service Locator Pattern

13COMP9321, 15s2, Week 8

Page 14: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Identifying Service Locator Pattern in the phonebook lab

14COMP9321, 15s2, Week 8

Page 15: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Identifying Service Locator Pattern in the phonebook lab

15COMP9321, 15s2, Week 8

Page 16: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Identifying Service Locator Pattern in the phonebook lab

16COMP9321, 15s2, Week 8

Page 17: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Dependency Injection

17COMP9321, 15s2, Week 8

Page 18: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Dependency

18COMP9321, 15s2, Week 8

Page 19: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

SAX Books Parser Example

19COMP9321, 15s2, Week 8

Page 20: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

What is "dependency injection" ?

20COMP9321, 15s2, Week 8

• In software engineering, dependency injection is a software designpattern that implements inversion of control forresolving dependencies.

• Dependency injection means giving an object its instance variables.

• Dependency injection provides the ability to pass by reference (or"inject"), service objects into a client (a class or a delegate) atdeployment time.

• This is a top-down approach, in contrast to a bottom-up one whereinthe clients discover or create service objects on their own.

Page 21: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Benefits of "dependency injection" …

21COMP9321, 15s2, Week 8

Page 22: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Data Access Object

22COMP9321, 15s2, Week 8

Page 23: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Data Access Object

23COMP9321, 15s2, Week 8

Context

• Access to data varies depending on the source of the data. Access to persistentstorage, such as to a database, varies greatly depending on the type of storage(relational databases, object-oriented databases, flat files, and so forth) and thevendor implementation.

Problem

• For many applications, persistent storage is implemented with differentmechanisms, and there are marked differences in the APIs used to access thesedifferent persistent storage mechanisms. Other applications may need to access datathat resides on separate systems.

• An example is where data is provided by services through external systems such asbusiness-to-business (B2B) integration systems, credit card bureau service, and soforth.

http://www.oracle.com/technetwork/java/dataaccessobject-138824.html

Page 24: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Data Access Object

24COMP9321, 15s2, Week 8

Solution

• Use a Data Access Object (DAO) to abstract and encapsulate all access to the data source. The DAO manages the connection with the data source to obtain and store data.

http://www.oracle.com/technetwork/java/dataaccessobject-138824.html

Page 25: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Data Access Object: Sequence Diagram

25COMP9321, 15s2, Week 8

http://www.oracle.com/technetwork/java/dataaccessobject-138824.html

Page 26: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Business Delegate

26COMP9321, 15s2, Week 8

Page 27: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Business Delegate

27COMP9321, 15s2, Week 8

Context

• A multi-tiered, distributed system requires remote method invocations to send andreceive data across tiers. Clients are exposed to the complexity of dealing withdistributed components.

Problem

• Presentation-tier components interact directly with business services. This directinteraction exposes the underlying implementation details of the business serviceapplication program interface (API) to the presentation tier.

• As a result, the presentation-tier components are vulnerable to changes in theimplementation of the business services: When the implementation of the businessservices change, the exposed implementation code in the presentation tier mustchange too.

http://www.oracle.com/technetwork/java/businessdelegate-137562.html

Page 28: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Business Delegate

28COMP9321, 15s2, Week 8

Solution

• Use a Business Delegate to reduce coupling between presentation-tier clients andbusiness services.

• The Business Delegate hides the underlying implementation details of the businessservice, such as lookup and access details of the EJB architecture.

• Using a Business Delegate reduces the coupling between presentation-tier clientsand the system's business services.

• Another benefit is that the delegate may cache results and references to remotebusiness services. Caching can significantly improve performance, because it limitsunnecessary and potentially costly round trips over the network.

http://www.oracle.com/technetwork/java/businessdelegate-137562.html

Page 29: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Business Delegate

29COMP9321, 15s2, Week 8

http://www.oracle.com/technetwork/java/businessdelegate-137562.html

• Client: requests the BusinessDelegate to provide access to theunderlying business service.

• BusinessDelegate: uses a LookupService to locate the requiredBusinessService component.

Page 30: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Business Delegate Sequence Diagrams

30COMP9321, 15s2, Week 8

http://www.oracle.com/technetwork/java/businessdelegate-137562.html

Page 31: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Business Delegate, API, and API Engineering

31COMP9321, 15s2, Week 8

What is API?• Application programming interface (API) is a set of routines, protocols, and tools

for building software applications.

• An API expresses a software component in terms of its operations, inputs, outputs, and underlying types.

• An API defines functionalities that are independent of their respective implementations.

• A good API makes it easier to develop a program by providing all the building blocks. A programmer then puts the blocks together.

What is API Engineering?

• API engineering is an application of engineering to the design, development, and maintenance of APIs.

Page 32: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Business Delegate, API, and API Engineering

32COMP9321, 15s2, Week 8

Web APIs?• Web APIs are the defined interfaces through which interactions happen

between an enterprise and applications that use its assets.

• When used in the context of web development, an API is typically defined as a set of HTTP request messages, along with a definition of the structure of response messages, which is usually in an XML or JSON (JavaScript Object Notation) format.

Page 33: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Business Delegate, API, and API Engineering

33COMP9321, 15s2, Week 8

Web APIs?• While "web API" historically has been virtually synonymous for web service,

the recent trend (so-called Web 2.0) has been moving away from Simple Object Access Protocol (SOAP) based web services and service-oriented architecture (SOA) towards more direct representational state transfer (REST) style web resources and resource-oriented architecture (ROA).

• Part of this trend is related to the Semantic Web movement toward Resource Description Framework (RDF).

• Web APIs allow the combination of multiple APIs into new applications known as mashups.

http://www.programmableweb.com/

Page 34: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

API Engineering

34COMP9321, 15s2, Week 8

Will be covered in COMP9322

API Engineering Seminar

Speaker: Prof. Boualem Benatallah

Date: Thu 8/10/2015Time: 15:00 - 17:00 (2 hours)Room: K17_113Reason: COMP9322 Open Lecture

Please Attend!

Page 35: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

More Patterns

35COMP9321, 15s2, Week 8

Core J2EE Patterns Catalog:

http://www.oracle.com/technetwork/java/index-138725.html

On this site, you will find the entire Java 2 Platform, Enterprise Edition (J2EE) Pattern catalog from the book Core J2EE Patterns: Best Practices and Design Strategies

authored by architects from the Sun Java Center.

Page 36: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

A few more things to consider

36COMP9321, 15s2, Week 8

Page 37: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Guarding a View

37COMP9321, 15s2, Week 8

Page 38: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Guarding a View

38COMP9321, 15s2, Week 8

Page 39: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Guarding a View

39COMP9321, 15s2, Week 8

Page 40: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Guarding a View

40COMP9321, 15s2, Week 8

Page 41: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Guarding a View

41COMP9321, 15s2, Week 8

Page 42: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Duplicate Form Submissions

42COMP9321, 15s2, Week 8

Page 43: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Duplicate Form Submissions

43COMP9321, 15s2, Week 8

Page 44: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Duplicate Form Submissions

44COMP9321, 15s2, Week 8

Page 45: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Synchronizer Token

45COMP9321, 15s2, Week 8

Page 46: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Synchronizer Token

46COMP9321, 15s2, Week 8

Page 47: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Background Tasks

47COMP9321, 15s2, Week 8

Page 48: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Background Tasks

48COMP9321, 15s2, Week 8

Page 49: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

Background Tasks

49COMP9321, 15s2, Week 8

Page 50: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

References

50COMP9321, 15s2, Week 8

• Core J2EE patterns, Deepak Alur, John Crupi and Dan Marlks, Prentice Hall• http://www.oracle.com/technetwork/java/index-138725.html• Patterns of Enterprise Application Architecture, Martin Fowler, Addison-Wesley• http://java.sun.com/blueprints/patterns/• http://www.oracle.com/technetwork/articles/javase/index-142890.html

Page 51: COMP9321 Web Application Engineeringcs9321/15s2/lectures/lec08/Lec-08.pdf · Assignment 2 COMP9321, 15s2, Week 8 2 Deadline Extended: The due date for assignment2 is (end of Mid Semester

51COMP9321, 15s2, Week 8