1 / 15

Sviluppo e collaudo di una webapp mediante IoC e AOP

Sviluppo e collaudo di una webapp mediante IoC e AOP. Alessandro Franchi - 0000219521 Reti di Calcolatori L-S A.A. 2007/2008. Introduzione. JavaBeans Troppo semplici per applicazioni di livello enterprise J2EE

illias
Télécharger la présentation

Sviluppo e collaudo di una webapp mediante IoC e AOP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sviluppo e collaudo di una webapp mediante IoC e AOP Alessandro Franchi - 0000219521 Reti di Calcolatori L-S A.A. 2007/2008

  2. Introduzione • JavaBeans • Troppo semplici per applicazioni di livello enterprise • J2EE • Disaccoppiamento tra Presentation Layer (JSP e servlet) e Business Logic (EnterpriseJavaBeans) • Servizi middleware • EJB troppo complessi • Implementazione complessa • Molto invasivo • Difficili da testare Nuovi pattern di programmazione

  3. Inversion of Control (IoC) ShoppingCart ShoppingCart injected new ShoppingCart() ShoppingCartService ShoppingCartService BookService <<interface>> BookService <<interface>> • Librerie vs. Framework IoC • Dependency Injection • Loose coupling • Testabilità • Manutenibilità ShoppingCart BookService ShoppingCart BookService injected new BookServiceMock() injected BookServiceMock BookServiceMock ShoppingCart new BookServiceImpl() BookServiceImpl BookServiceImpl new ShoppingCart() ShoppingCartService ShoppingCart BookServiceImpl JNDI lookup BookServiceImpl

  4. Aspect Oriented Programming (AOP) • Servizi ortogonali alla business logic: TRANSAZIONI S I C U R E Z Z A L O G G I N G TRANSAZIONI SICUREZZA BookService Shopping CartService BookService ShoppingCartService UserService UserService • Cross-cutting concerns come aspect: Advice Pointcut flusso di esecuzione Joinpoint

  5. Spring Framework • Architettura: • Spring Web Flow • Flusso • stati, eventi e transizioni ORM Hibernate … DAO JDBC Transazioni JEE Remoting JMS EJB … Web MVC Integrazione con altri framework AOP Core IoC Container (ApplicationContext)

  6. Architettura della Webapp • Applicazione web per la gestione di uno shop online • Three-tiered architecture: Security Layer Presentation Layer Application Layer Persistence Layer Web Browser … Database

  7. Presentation Layer (Client-Side Logic) Handler Mapping Page Controllers: Dispatcher Servlet (Front Controller) Service Layer HomeController Request: login.htm LoginController ModelAndView FlowController FlowExecutor View Resolver FlowRegistry hello.jsp login.jsp buy.jsp Views: … … …

  8. Flow di Acquistocon carrello della spesa virtuale buyFlow (main flow) buy checkout update database thank you start end warn not in stock search (subflow) removeFromCart (subflow) addToCart (subflow)

  9. Application Layer (Business Logic) • Gestione domain objects • Ambiente multiutente • Un “carrello della spesa” virtuale per utente injected ShoppingCartService scoped-proxy ShoppingCart Shopping Cart HTTP Session ---- Shopping Cart injected

  10. Persistence Layer (Database Logic) • Object-Relational Mapping • Hibernate • Data Access Object (DAO) • Gestione transazioni come “aspect” • Spring AOP: • proxy-based • method joinpoint Inizia transazione Risultati proxy txAdvice BookDao BookService saveBooks() updateBooks() getBooks() Termina transazione (commit o rollback) Esegue business logic

  11. Testing • Supporto di Spring alla fase di testing • Unit Testing di controller Spring MVC • Verifica che il model contenga certi oggetti • Verifica che la view ritornata sia quella giusta • Testing di flow definiti con Spring Web Flow • Verifica della correttezza degli stati e delle transizioni • Integration Testing dell’applicazione • Verifica del funzionamento dell’applicazione o di parti di essa caricando l’ApplicationContext • Transactional Testing dei componenti per l’accesso al database • Verifica delle operazioni di accesso e modifica del database • Ogni test è wrappato in una transazione • EasyMock • Per implementazioni mock dei service objects nel caso di Unit Test

  12. Deploy distribuito … network P R O X y Book Service (interfaccia del servizio remoto) Controller MVC BookService invocazione metodo Presentation Layer Application Layer Persistence Layer JRMP, HTTP JRMP, HTTP Web Browser BookDao crea proxy ProxyFactoryBean (crea proxy specifici per RMI, HTTP Invoker…) Database

  13. Conclusioni • Spring Framework: • Componenti loosely coupled, riutilizzabili e facilmente testabili • Servizi ortogonali (transazioni) applicati come aspect • Architettura scalabile • Futuri sviluppi dell’applicazione • Data source • estratta da directory JNDI • che ottiene connessioni da un pool di connessioni • Load balancing • Gestore a livello applicativo • Load balancer a livello HTTP • Java Message System

  14. Bibliografia • C. Walls and R. Breidenbach, Spring in Action, Manning, 2005. • Java Beans (http://java.sun.com/javase/technologies/desktop/javabeans/index.jsp) • Sun Microsystems (http://www.sun.com/) • Java (http://java.sun.com/) • Java 2 Platform, Enterprise Edition (J2EE) (http://java.sun.com/j2ee/overview.html) • Enterprise JavaBeans Technology (http://java.sun.com/products/ejb/) • M. Fowler, “Inversion of Control,” 2005 (http://martinfowler.com/bliki/InversionOfControl.html) • SpringSource.org - Spring Framework (http://www.springsource.org/) • M. Fowler, “Inversion of Control Containers and the Dependency Injection pattern,” 2004 (http://martinfowler.com/articles/injection.html) • SpringSource.org - Spring Web Flow (http://www.springsource.org/webflow) • Acegi Security - Acegi Security System for Spring (http://www.acegisecurity.org/) • Hibernate (http://www.hibernate.org/) • Remote Method Invocation Home (http://java.sun.com/javase/technologies/core/basic/rmi/index.jsp) • Hessian Binary Web Service Protocol (http://hessian.caucho.com/) • Burlap XML Web Service Protocol(http://www.caucho.com/resin-3.0/protocols/burlap.xtp)

  15. Fine

More Related