TDDD05: Application frameworks Ola Leifler, IDA, Linköpings universitet torsdag 27 februari 14

advertisement
TDDD05: Application
frameworks
Ola Leifler, IDA, Linköpings universitet
torsdag 27 februari 14
Component
frameworks
”A component framework is a software entity that supports components conforming to certain standards
and allows instances of these components to be plugged into the component framework” [p. 425]
Domain-agnostic
torsdag 27 februari 14
Application frameworks
”A framework is a set of classes that embodies an abstract
design for solutions to a family of related problems, and supports reuses at a
larger granularity than classes.”
Ralph Johnson and Brian Foote. Designing Reusable Classes. Journal of Object-Oriented Programming.
SIGS, 1, 5 (June/July. 1988), 22-35.
Domain-specific
torsdag 27 februari 14
Agenda
• Case studies in Application Frameworks:
torsdag 27 februari 14
Agenda
• Case studies in Application Frameworks:
torsdag 27 februari 14
Agenda
• Case studies in Application Frameworks:
Web application frameworks
torsdag 27 februari 14
Domain specific
Agenda
• Case studies in Application Frameworks:
Web application frameworks
Spring
torsdag 27 februari 14
Domain specific
Domain agnostic
Web application
frameworks
torsdag 27 februari 14
Web application
frameworks
•Template language
•Caching
•Connecting Javascript to
Controller code
torsdag 27 februari 14
Web application
frameworks
•ORM/Persistence,
•Data validation,
•Localization
torsdag 27 februari 14
•Template language
•Caching
•Connecting Javascript to
Controller code
Web application
frameworks
•Routing,
•Controller wiring,
•HTTP filtering,
•Response encoding
•Parameter parsing
•ORM/Persistence,
•Data validation,
•Localization
torsdag 27 februari 14
•Template language
•Caching
•Connecting Javascript to
Controller code
Web application
frameworks
•Routing,
•Controller wiring,
•HTTP filtering,
•Response encoding
•Parameter parsing
HTTP request
requests HTML
HTTP response
Controller
View
rendered HTML
•Template language
•Caching
•Connecting Javascript to
requests objects
•ORM/Persistence,
•Data validation,
•Localization
torsdag 27 februari 14
Controller code
Model
Web application
frameworks
•Routing,
•Controller wiring,
•HTTP filtering,
•Response encoding
•Parameter parsing
HTTP request
requests HTML
HTTP response
Controller
View
rendered HTML
•Template language
•Caching
•Connecting Javascript to
requests objects
•ORM/Persistence,
•Data validation,
•Localization
Controller code
Model
Lifecycle management
Dependency resolution
torsdag 27 februari 14
Web application
frameworks
•Routing,
•Controller wiring,
•HTTP filtering,
•Response encoding
•Parameter parsing
HTTP request
requests HTML
HTTP response
Controller
View
rendered HTML
•Template language
•Caching
•Connecting Javascript to
requests objects
•ORM/Persistence,
•Data validation,
•Localization
Controller code
Model
Lifecycle management
Dependency resolution
torsdag 27 februari 14
Domain
agnostic
Web application
frameworks
•Routing,
•Controller wiring,
•HTTP filtering,
•Response encoding
•Parameter parsing
HTTP request
requests HTML
HTTP response
Controller
View
rendered HTML
Domain specific
•ORM/Persistence,
•Data validation,
•Localization
•Template language
•Caching
•Connecting Javascript to
requests objects
Controller code
Model
Lifecycle management
Dependency resolution
torsdag 27 februari 14
Domain
agnostic
Routing
• Declarative mapping of requests to
controller methods
GET
GET
DELETE
POST
torsdag 27 februari 14
/user/?
/user/{<[0-9]+>id}
/user/{<[0-9]+>id}
/user/add/?
userController.listAll
userController.showUser
userController.deleteUser
userController.createUser
Parameter parsing
• Converts HTTP request header/body data
to parameter values through pluggable
mechanisms
• Usually supports all built-in types, with
support for custom or convention-based
conversions
torsdag 27 februari 14
Lifecycle management
(Java frameworks)
• Controllers are singletons (Java Servlets,
Struts)
• Each page is a singleton (Tapestry)
• Application contexts specific to session,
request or page, and beans belong to an
application context
torsdag 27 februari 14
Spring
torsdag 27 februari 14
Spring
• dependency injection,
• testing
torsdag 27 februari 14
Spring
• dependency injection,
• testing
• authentication,
• authorization
• protection against
• session fixation,
• clickjacking,
• cross site request
forgery
torsdag 27 februari 14
Spring
• dependency injection,
• testing
• dynamic programming
language for the JVM
• authentication,
• authorization
• protection against
• session fixation,
• clickjacking,
• cross site request
forgery
torsdag 27 februari 14
Spring
• dependency injection,
• testing
• dynamic programming
language for the JVM
• authentication,
• authorization
• protection against
• session fixation,
• clickjacking,
• cross site request
forgery
torsdag 27 februari 14
•Support for event- and
data-driven applications
Spring
torsdag 27 februari 14
Spring
•Object mapping to non-relational databases such as
•key-value stores,
•document databases,
•graph-based storage
•integration with map-reduce frameworks, and
•REST publishing
torsdag 27 februari 14
Spring
torsdag 27 februari 14
Spring
• Messaging patterns
• Web service invocation
• Advanced Dependency Injection
torsdag 27 februari 14
Spring
• Messaging patterns
• Web service invocation
• Advanced Dependency Injection
•Transaction management
•Chunk-based processing
•Declaritive I/O
•Start/Stop/Restart
•Retry/Skip
torsdag 27 februari 14
Spring
• Messaging patterns
• Web service invocation
• Advanced Dependency Injection
•Transaction management
•Chunk-based processing
•Declaritive I/O
•Start/Stop/Restart
•Retry/Skip
torsdag 27 februari 14
• Distributed data
ingestion to big data
stores
•Real-time analytics at
ingestion time
•Workflow management
via batch jobs as well as
Hadoop operations.
•High throughput data
export
Spring
• Messaging patterns
• Web service invocation
• Advanced Dependency Injection
•Transaction management
•Chunk-based processing
•Declaritive I/O
•Start/Stop/Restart
•Retry/Skip
torsdag 27 februari 14
• MVC support for web applications
• Web application contexts
• Distributed data
ingestion to big data
stores
•Real-time analytics at
ingestion time
•Workflow management
via batch jobs as well as
Hadoop operations.
•High throughput data
export
Spring Example
Model
torsdag 27 februari 14
Spring Example
Controller
torsdag 27 februari 14
Spring Example
Controller
torsdag 27 februari 14
Spring Example
Controller
torsdag 27 februari 14
Spring Example
Controller
torsdag 27 februari 14
Spring Example
Web App
torsdag 27 februari 14
Spring Example
Web App
Server initialized with port: 8080
Startup log
Mapped "{[/greeting], ... }" onto public rest.Greeting rest.GreetingController.greeting(java.lang.String)
torsdag 27 februari 14
Spring Example
Web App
Server initialized with port: 8080
Startup log
Mapped "{[/greeting], ... }" onto public rest.Greeting rest.GreetingController.greeting(java.lang.String)
lap-161:~ olale$ curl http://localhost:8080/greeting
{"id":1,"content":"Hello World!"}
lap-161:~ olale$ curl http://localhost:8080/greeting
{"id":2,"content":"Hello World!"}
lap-161:~ olale$ curl http://localhost:8080/greeting?name=Ola
{"id":4,"content":"Hello Ola!"}
torsdag 27 februari 14
Spring Example
Web App
Server initialized with port: 8080
Startup log
Mapped "{[/greeting], ... }" onto public rest.Greeting rest.GreetingController.greeting(java.lang.String)
lap-161:~ olale$ curl http://localhost:8080/greeting
{"id":1,"content":"Hello World!"}
lap-161:~ olale$ curl http://localhost:8080/greeting
{"id":2,"content":"Hello World!"}
lap-161:~ olale$ curl http://localhost:8080/greeting?name=Ola
{"id":4,"content":"Hello Ola!"}
torsdag 27 februari 14
Spring Example
Web App
Server initialized with port: 8080
Startup log
Mapped "{[/greeting], ... }" onto public rest.Greeting rest.GreetingController.greeting(java.lang.String)
lap-161:~ olale$ curl http://localhost:8080/greeting
{"id":1,"content":"Hello World!"}
lap-161:~ olale$ curl http://localhost:8080/greeting
{"id":2,"content":"Hello World!"}
lap-161:~ olale$ curl http://localhost:8080/greeting?name=Ola
{"id":4,"content":"Hello Ola!"}
torsdag 27 februari 14
Spring Example
Web App
Server initialized with port: 8080
Startup log
Mapped "{[/greeting], ... }" onto public rest.Greeting rest.GreetingController.greeting(java.lang.String)
lap-161:~ olale$ curl http://localhost:8080/greeting
{"id":1,"content":"Hello World!"}
lap-161:~ olale$ curl http://localhost:8080/greeting
{"id":2,"content":"Hello World!"}
lap-161:~ olale$ curl http://localhost:8080/greeting?name=Ola
{"id":4,"content":"Hello Ola!"}
torsdag 27 februari 14
Spring Example 2
Required
dependency
torsdag 27 februari 14
Spring Example 2
Required
dependency
torsdag 27 februari 14
Spring Example 2
Implementation
of
MessageService
torsdag 27 februari 14
Spring Example 2
Implementation
of
MessageService
torsdag 27 februari 14
Spring Example 2
Autowiring by type from bean name 'messagePrinter' to bean named 'getMockMessageService'
Finished creating instance of bean 'messagePrinter'
this is just a fake message service
torsdag 27 februari 14
Spring Example 3
@Entity
public class User extends AbstractPersistable<Long> {
!
private static final long serialVersionUID = -2952735933715107252L;
!
@Column(unique = true) private String username;
Getters and setters !
!
omitted
torsdag 27 februari 14
private String firstname;
private String lastname;
!
!
!
public User() {
!
this(null);
}
!
!
!
!
!
!
/**
* Creates a new user instance.
*/
public User(Long id) {
!
this.setId(id);
}
!
!
!
!
!
!
/**
* Returns the username.
*
* @return
*/
public String getUsername() {
!
!
!
}
return username;
Spring Example 3
public interface SimpleUserRepository extends CrudRepository<User, Long> {
!
/**
!
* Find all users with the given lastname. This method will be translated into a query by constructing it directly
!
* from the method name as there is no other query declared.
!
*
!
* @param lastname
!
* @return
!
*/
!
List<User> findByLastname(String lastname);
!
!
!
!
!
!
!
!
!
/**
* Returns all users with the given firstname. This method will be translated into a query using the one declared in
* the {@link Query} annotation declared one.
*
* @param firstname
* @return
*/
@Query("select u from User u where u.firstname = ?")
List<User> findByFirstname(String firstname);
}
torsdag 27 februari 14
Spring Example 3
public interface SimpleUserRepository extends CrudRepository<User, Long> {
!
/**
!
* Find all users with the given lastname. This method will be translated into a query by constructing it directly
!
* from the method name as there is no other query declared.
!
*
!
* @param lastname
!
* @return
!
*/
!
List<User> findByLastname(String lastname);
What would be required to achieve this?
!
!
!
!
!
!
!
!
!
/**
* Returns all users with the given firstname. This method will be translated into a query using the one declared in
* the {@link Query} annotation declared one.
*
* @param firstname
* @return
*/
@Query("select u from User u where u.firstname = ?")
List<User> findByFirstname(String firstname);
}
torsdag 27 februari 14
Download