aspect-oriented programming for web controller layer

29
Aspect-Oriented Programming for Web Controller Layer Keiji Hokamura, Kyushu Institute of Technology Naoyasu Ubayashi, Kyushu Institute of Technology Shin Nakajima, National Institute of Infomatics Akihito Iwai, DENSO CORPORATION 1

Upload: others

Post on 16-Oct-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Aspect-Oriented Programming for Web Controller Layer

Aspect-Oriented Programming for Web

Controller LayerKeiji Hokamura, Kyushu Institute of Technology

Naoyasu Ubayashi, Kyushu Institute of TechnologyShin Nakajima, National Institute of Infomatics

Akihito Iwai, DENSO CORPORATION

1

Page 2: Aspect-Oriented Programming for Web Controller Layer

Aspect:

module of CCC

Pointcut: specifies "where"

Crosscutting concerns (CCC)

(e.g. logging)

Todayʼs talk

2

AOP [Kiczales1997]

• AspectJ-based AOP- Insufficient support for

Web-specific CCC- Program-execution-

based pointcut (call, etc.)

Our approach

• AOWP (Web-specific AOP mechanism)- Web protocol-based

pointcuts (request, pflow, etc.)

- Web protocol-based aspect instantiation

ServerClient

Client

Aspect

Pointcut

Page 3: Aspect-Oriented Programming for Web Controller Layer

Outline

• Motivation

• AOWP

• Practical example

• Conclusion & Future work

3

Page 4: Aspect-Oriented Programming for Web Controller Layer

Motivation

4

Page 5: Aspect-Oriented Programming for Web Controller Layer

Top page

Business store

Education store

Notebook PC

Work station

Notebook PC

Work station

Confirmation

page

Example:

PC sale on EC-site

• Prices in the business store and the education store are different

• To use the education store, users have to access the confirmation page first and read explanation of the store

5

Page 6: Aspect-Oriented Programming for Web Controller Layer

Example:

PC sale on EC-site

6

Top page

Busines store

Education store

Notebook PC

Work station

Notebook PC

Work station

Confirmation

page

• However, some users access the education store without the access to the confirmation page

from userʼs bookmark

from search result

A pointcut for the CCC captures the page requests if the users did not access the confirmation page

forward to the confirmation page➡crosscutting

××

Page 7: Aspect-Oriented Programming for Web Controller Layer

Modularize CCC with AspectJ-based AOP

7

Top page

Busines store

Education store

Notebook PC

Work station

Notebook PC

Work station

Confirmation

page

call (void Edu*.doAction()) &&if (!ConHistory.isAccessed())

Pointcut

ConHistory.accessed();

save history of the accessto the confirmation page

add to the original code

EduNoteAction

+ void doAction()

EduWSAction

+ void doAction()

A page request to education store fires a doAction method if the classes have

a ʻEdu-ʼ prefix

• In AspectJ-based AOP, the pointcut captures program execution points which relate to the page requests

➡Programmers are required to deeply understand the original code

Page 8: Aspect-Oriented Programming for Web Controller Layer

page requestpage request flow

per Web applicationper session

pre page requestAOWP

Our approach

8

method callfield reference and set

control flowetc.

singletonper object

per control flow

points capturedby pointcuts aspect instantiation

AspectJ-based AOPAspectJ [Kiczals2001]AOPHP [Stamey2005]

phpAspect [phpaspect.org]

based on program execution

based on Web-protocol ➡Web protocol-based aspects

Page 9: Aspect-Oriented Programming for Web Controller Layer

Modularize CCC with AOWP

request(ʻ/edu/.*ʼ) &&!pflow(ʻ/eduConf.phpʼ)

Pointcut

9

Top page

Busines store

Education store

Notebook PC

Work station

Notebook PC

Work station

Confirmation

page

• Captures page requests which do not come via the confirmation page

➡Does not depend on the original code

request URL: /edu/notebook.phprequest URL: /edu/ws.php

request URL: /eduConf.php

Page 10: Aspect-Oriented Programming for Web Controller Layer

AOWP

10

Page 11: Aspect-Oriented Programming for Web Controller Layer

Client (Bob)

Server

Ann's

session data

Bob's

session data

cokkie data

Client (Ann)

cokkie dataform data

form data

form data

form data

time

request history

time

request history

Pointcut designators and aspect instantiation in AOWP

11

points captured bythe request pointcut

context information

page request

history per user

(used by the pflow

pointcut and etc.)

per-session

aspect

per-request

aspect

per-application

aspect

per-request

aspect

per-request

aspect

per-request

aspect

per-session

aspect

Page 12: Aspect-Oriented Programming for Web Controller Layer

Web server

/eduConf.php

/edu/note.php

/edu/ws.php

Ann

Bob

pflow pointcut

/edu/note.php

Ann:

Bob:

• Pflow captures page requests based on the page history (if multiple requests in history are used, the pagehistory pointcut is used)

• These pointcuts are based on trace-based AOP [Douence2004, Walker2004, Allan2005], but AOWP is different in that the history is managed per user

/eduConf.php /edu/ws.php /edu/note.php

/edu/ws.php/eduConf.php

12

pflow(/eduConf.php)Pointcut

Pointcut!pflow(/eduConf.php)

Page 13: Aspect-Oriented Programming for Web Controller Layer

AOWP/PHP

• A proof-of concept implementation in PHP• Class-based AOP framework• Aspects are described as subclass of

AOWP_Aspect class• Pointcuts and advice are described in the

constructor of the aspect class

13

Page 14: Aspect-Oriented Programming for Web Controller Layer

Aspect description in AOWP/PHP

class EduAccessConAspect extends AOWP_Aspect {

public function __construct() { $requestPC = new AOWP_RequestPointcut(ʻ/edu/.*ʼ); $pflowPC = new AOWP_PFlowPointcut(ʻ/eduConf.phpʼ); $pflowPC->Not(); $requestPC->addAnd($pflowPC);

$advice = new AOWP_BeforeAdvice(); $advice->setPointcut($requestPC); $advice->setAdviceBody(ʻforwardToConʼ, $this); $this->addAdvice($advice); }

public function forwardToCon() { forward(ʻ/eduConf.phpʼ); }}

Definition of the pointcutrequest(ʻ/edu/.*ʼ) &&

!pflow(ʻ/eduConf.phpʼ)

Definition of the advice

14

Page 15: Aspect-Oriented Programming for Web Controller Layer

AOWP/PHPʼs pointcut designators

Designator Descriptionrequest Select page requests

pflow Select based on the flow of page requests

accessnum Select based on the number of access users

functioncall Select points of a function call

globalvariableget Select points of reading global variable

globalvariableset Select points of writing global variable

scriptexecution Select points of a script file execution

methodcall Select points of a method call

if Select if a specified condition is true

15

Aspects which use only Web-protocol-based pointcut designatorsmay be applicable to multiple web applications.

Web-protocol-based

AspectJ-based

AspectJ-based(PHP-specific)

Page 16: Aspect-Oriented Programming for Web Controller Layer

Practical example

16

Page 17: Aspect-Oriented Programming for Web Controller Layer

Login aspect

request(ʻ.*ʼ) && !if(loginedID == null)Pointcut

Authenticate a user with form data.Success: write the userʼs loginID to the loginedID fieldFailure: forward to login page

Advice

Aspect (per session)

loginedID = nullField

• Execute login authentication before page requests

• The aspect is instantiated per user (per session)

• The aspect is applicable to multiple web applications

Blog system

Wiki

17

Page 18: Aspect-Oriented Programming for Web Controller Layer

Future work & Conclusion

18

Page 19: Aspect-Oriented Programming for Web Controller Layer

Conclusion

• AOWP: Web-specific AOP mechanism- Web-protocol-based pointcut designators- Web-protocol-based aspect instantiation

• We can modularize the Web-specific crosscutting concerns as Web-protocol-based aspects

19

Page 20: Aspect-Oriented Programming for Web Controller Layer

Future work

• More case studies and evaluation

• Self-* systems implemented with AOWP- Self-* systems [Kramer2007] automatically

reconcile themselves with changes- They are suitable for continuous systems and open

systems (e.g. web applications)- Monitor aspect + AOP-based evolution

20

Page 21: Aspect-Oriented Programming for Web Controller Layer

Thank you

Page 22: Aspect-Oriented Programming for Web Controller Layer

Spair slides

22

Page 23: Aspect-Oriented Programming for Web Controller Layer

PHP file

Weaving forWeb-specific pointcut

<?php // The original code?>

Server

Program

Session data

Client software

Cookie data

Form data(GET or POST)

HTTP request

• The Web-specific events are related to the points at the PHP source code

• Page requests-Execution the PHP file

• Read form data-Read $_GET or $_POST

• Read/write cookie data-Read/write $_COOKIE

• Read/write session data-Read/write $_SESSION

Weave to the aspect before the page requestAspect

Relate

<?phprequire_once('/aowp/include.php');$aspect = AOWP_AspectInstanceManager::getInstance('SomeAspect');$context = new AOWP_Context();if ($aspect->runtimeMatch(0, $context)) { $aspect->executeAdvice(0, $context);}AOWP_AspectInstanceManager::releaseInstance($aspect);?><?php // The original code?>

23

Page 24: Aspect-Oriented Programming for Web Controller Layer

Web-specific aspect instantiation

• Aspect instances are automatically created- Where is the instance created or destroyed?

• In current AOP- issingleton, perthis, pertarget, percflow,

percflowbelow

• In web applications- perrequest: Cut across a request- persession: Cut across a user session- perapplication: Cut across the entire web

application

24

Page 25: Aspect-Oriented Programming for Web Controller Layer

Web-specific trace-based pointcut

• In Web application- The trace is managed per a user session - The web-specific trace-based pointcut- pagehistory, sessionhistory, cookiehistory, etc.

Time

Aspect

Decide applying aspects based on the history of the program execution[Walker2004, Douence2004, Allan2005]

25

Page 26: Aspect-Oriented Programming for Web Controller Layer

Web serverWeb client

HTTP request

For educational people

Notebook PC

Work station

HTTP request

HTTP request

URL: /gen/note.php

URL: /edu/note.php

URL: /edu/ws.php

For general people

Notebook PC

How AspectJ-based AOP handle page requests

function eduNoteAction() { // View the detail of // notebook PC}eduNoteAction();

function eduWSAction() { // View the detail of // work station PC}eduWSAction();

function genNoteAction() { // View the detail of // notebook PC}genNoteAction();

To select the page requests to pages for educational people

Pointcutexec (edu.*Action)

➡ we should specify the point in the original code related to the requests

want to selectby the pointcut

26

Page 27: Aspect-Oriented Programming for Web Controller Layer

Web-specific aspect instantiation (in new ver.)

Client

Client

Server

Aspect instances are automatically created.- Where is the instance

created or destroyed?

Aspect instantiation in AOWP

- per request- per session- per application

instanceper session

instanceper request

instanceper application

27

Page 28: Aspect-Oriented Programming for Web Controller Layer

Implementation

Original code

Parse

ASTs

Weave

Aspects

Traslate

Woven ASTs

Woven code

• Weaver implemented in PHP

• All the original code is translated into ASTs (implemented with the extended PEAR PHP_Parser)

• Aspects are woven as modifying the ASTs

• The woven ASTs are translated into the woven code

28

Page 29: Aspect-Oriented Programming for Web Controller Layer

Weaving of login aspect

a number of files line codes weaving time

PukiWiki

WordPress

29