jee – design patternsa78khan/cs446/additional... · “presentation-tier request handling...

28
WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE JEE – Design Patterns JEE – Design Patterns Front Controller Front Controller Intercepting Filter Intercepting Filter Transfer Object Transfer Object CS 446/646 ECE452 Jun 13 th , 2011 IMPORTANT NOTICE TO STUDENTS These slides are NOT to be used as a replacement for student notes. These slides are sometimes vague and incomplete on purpose to spark class discussions

Upload: others

Post on 08-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

JEE – Design PatternsJEE – Design PatternsFront ControllerFront Controller

Intercepting FilterIntercepting FilterTransfer ObjectTransfer Object

CS 446/646 ECE452Jun 13th, 2011

IMPORTANT NOTICE TO STUDENTS

These slides are NOT to be used as a replacement for student notes.These slides are sometimes vague and incomplete on purpose to spark class discussions

Page 2: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

2WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Overview

JEE Core Design Patterns

PresentationTier

BusinessTier

IntegrationTier

Intercepting Filter

Front Controller

Context Object

App Controller

View Helper

Composite View

Service to Worker

Dispatcher View

Service Locator

Session Facade

Application Service

Business Object

Business Delegate

Composite Entity

Transfer Object

TO Assembler

Value List Handler

Data Access Object

Service Activator

Domain Store

Web Service Broker

Page 3: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

3WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Front ControllerIntent● provide a single point for processing user requests

http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html

Page 4: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

4WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Front ControllerMotivation● single processing point for all

client requests– across views & session– can be used to inject cross-cutting concerns

● logging● security

– can we have multiple controllers?– we can map multiple requests to the same controller?

http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html

Page 5: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

5WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Front ControllerMotivation● separation of concerns

– business code from presentation code

http://www.corej2eepatterns.com/Patterns2ndEd/FrontController.htm

Page 6: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

6WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Front Controller

http://www.corej2eepatterns.com/Patterns2ndEd/FrontController.htm

Page 7: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

7WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Front ControllerMotivation● provides resource mapping

– physical● http://server/resource.jsp

– virtual/logical● http://server/servlet/resourceController● http://server/servlet/page1.help● logical partitioning of application views?

Page 8: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

8WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Front ControllerMotivation● organic growth

– controllers can be specialized (sub-classing)● GWTServlet

● reusability– declarative vs. non-decalrative mapping– what is declarative mapping?– why do we care?

Page 9: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

9WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterIntent● common mechanism for pre & post processing of user

requests

Page 10: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

10WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting Filter

filter1 filter2

request

response

controllerrequest request

response

response

Filter chain

how is this different from traditional pipes & filters?

how is this different from batch pipes & filters?

what type of data flows through the pipes?

Page 11: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

11WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting Filter

* http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html

Context● “presentation-tier request handling mechanism receives many

different types of requests, which require varied types of processing”*

Common Examples*● has the client been authenticated?● does the client have a valid session?● is the client's IP address from a trusted network?● does the request path violate any constraints?● what encoding does the client use to send the data?● do we support the browser type of the client?

Page 12: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

12WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterEasy Solution● if-then-else in the controller (why not?)

An Elegant Solution● common reusable processing● easy to add/modify/delete filtering functionality

– even better if declarative

Page 13: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

13WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterSounds like Decorator (how?)

http://en.wikipedia.org/wiki/Decorator_pattern

Page 14: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

14WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterSounds like Decorator

http://msdn.microsoft.com/en-us/library/ff647251.aspx

Page 15: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

15WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting Filter

http://msdn.microsoft.com/en-us/library/ff647251.aspx

Page 16: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

16WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterWhat is the different between the two?● structure

– FilterChain is no longer required

● runtime behaviour

● take another look at the diagram

Page 17: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

17WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting Filter

http://msdn.microsoft.com/en-us/library/ff647251.aspx

Page 18: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

18WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting Filter

http://msdn.microsoft.com/en-us/library/ff647251.aspx

Page 19: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

19WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterEvolution

Page 20: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

20WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterEvolution

What is the impact of this?

Page 21: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

21WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterEvolution

What is the impact of this?

Page 22: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

22WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting Filter

List some drawback of this design?

Page 23: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

23WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Intercepting FilterMotivation● functionality injection● improved reusability

– filter chains can be defined in a number of ways● declarative configuration

Difficulties● information sharing● fault-tolerance

Page 24: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

24WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Transfer ObjectIntent● to transfer multiple data elements over a tier

http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html

Client BusinessComponent

getUserName()

getUserAge()

getUserPrefs()

Looks harmless??

User

Page 25: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

25WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Transfer ObjectSolution● use a

Transfer Object to encapsulate the data

http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html

Page 26: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

26WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Transfer Object

http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html

Page 27: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

27WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Transfer ObjectsScope & Complexity?● can we have multiple types of

transfer objects to represent data (a user)?● create the transfer

objects required● how complex?

Page 28: JEE – Design Patternsa78khan/cs446/additional... · “presentation-tier request handling mechanism receives many different types of requests, which require varied types of processing”*

28WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Transfer ObjectConsequences● simplified remote interface● fewer remote calls● stale objects: very common problem for web apps

– what are stale objects?– how would you deal with it?

● serialization over the wire?