Cedric Dumoulin (C) The Java EE 7 Tutorial http://docs.oracle.com/javaee/7/tutorial/doc/
Webographie The Java EE 7 Tutorial http://docs.oracle.com/javaee/7/tutorial/doc/ Les slides de cette présentation sont des extraits de ce tutorial
Overview The Java EE platform is developed through the Java Community Process (JCP) Java EE platform uses a simplified programming model. Developer can simply enter the information as an annotation XML deployment descriptors are optional. Dependency injection can be applied to all resources
Java EE Application Model Use Java Designed to support applications that implement enterprise services for customers, employees, suppliers, partners, and others who make demands on or contributions to the enterprise Such applications are inherently complex, potentially accessing data from a variety of sources and distributing applications to a variety of clients The business functions to support these various users are conducted in the middle tier. The middle tier is typically run on dedicated server hardware and has access to the full services of the enterprise.
Java EE Application Model The Java EE application model defines an architecture for implementing services as multitier applications that deliver the scalability, accessibility, and manageability needed by enterpriselevel applications This model partitions the work needed to implement a multitier service into the following parts: The business and presentation logic to be implemented by the developer The standard system services provided by the Java EE platform The developer can rely on the platform to provide solutions for the hard systems-level problems of developing a multitier service. permet de se concentrer sur le domaine de l application
Distributed Multitiered Applications Java EE platform uses a distributed multitiered application model for enterprise applications. Application logic is divided into components according to function Components are installed on various machines
Exemple Application multitier 4 couche/tiers 2 applications 3 machines
Securité Les contraintes de sécurités peuvent être définies lors du déploiement Une application JEE est portable sur un grand nombre d impléméntation de la sécurité Tout en protégeant le développeur des problèmes d impléméntation de sécurité JEE fournit un mécanisme standard de déclaration des contrôles d accès JEE fournit des mécanismes standard de login
Composants JEE Une application JEE est faites de composants Un composant JEE est une unité de code qui communique avec d autre composants JEE définit les composants suivants: Composants client Application clients et applets tournent sur le client Composants web Java Servlet, JavaServer Faces, et JavaServer Pages (JSP) Tournent sur le serveur. Ex: un servlet Composants EJB (composants business) Classes Java Tournent sur le serveur. Ex: SessionBean
Clients JEE Client lourds client application Sur la machine client Accès directe aux EJB possible Client léger web client Browser (machine client )+ couche de présentation (sur le server web) Uniquement la présentation, délègue le business à la couche appropriée Applets Sur machine client Nécessite une machine Java
Clients JEE : Communications avec le serveur
Composants Web Sur le serveur web Communique avec les EJB Dans le même serveur Ou dans un serveur différent
Composants EJB (ou business) Dans le serveur EJB Peuvent être distribuées Ex: Entities, BeanSession, MDB
Container Contient des composants Fournit La gestion des composants (cycle de vie, injection, ) Les services de «bas niveaux» Sécurité, transaction, JNDI, injection, communication inter container, RMI, Pour fonctionner, un composant doit être Dans un Package (.war,.ear,.jar) Puis déployé dans un container
Les types de containers Application Client Applet Web EJB JEE server regroupe les container WEB et EJB
Communications possibles entre les container
API disponibles dans les différents containers
Javaeetutorial7 - chap 3
Qu est-ce qu une ressource? Un objet qui fournit une connexion à un sous-système tel que Un Système de base de données Un système implémentant JMS Un Serveur mail Les ressources sont déclarés au niveau du serveur JEE Par des fichiers de configuration Par la console d administration Appli1 Ressources R1 BDx Appli1 R2 BDy
Ressources et JNDI Naming Une ressource peut être/doit être associée à un nom JNDI (Java Naming Directory Interface) Fait par un administrateur Avec des fichiers de configuration Par la console d administration Une application utilise une ressource par injection Utilise le nom JNDI @Resource DataSource ds; // utilise nom par défaut?
A quoi sert une ressource A découpler l application du système implémentant la ressource L application utilise une interface (Resource, DataSource, ) dans le système, et spécifie un nom JNDI Le serveur associe un nom JNDI à une implémentation de la ressource Au démarrage, le serveur injecte la ressource dans l application. L application peut être réutilisée avec différentes implémentation Appli1 Ressources R1 BDx Appli1 R2 BDy
Creating Resources Aministratively Avant de déployer une application Il faut parfois créer les ressources requises Une application peut inclure un fichier (serveur dépendant) permettant de créer les ressources requises Ex: glassfish glassfish-resources.xml
Javaeetutorial7 - chap 4
Injection Mechanisms that enable your objects to obtain references to resources and other dependencies without having to instantiate them directly. You declare the required resources and other dependencies in your classes by decorating fields or methods with one of the annotations that mark the field as an injection point. The container then provides the required instances at run time. 2 types of injections: Resource Injection Dependency Injection Injection simplifies your code and decouples it from the implementations of its dependencies.
Resource Injection Enables you to inject any resource available in the JNDI namespace into any container-managed object, (servlet, enterprise bean, managed bean, ). public class MyServlet extends HttpServlet { @Resource(name="java:comp/DefaultDataSource") private javax.sql.datasource dsc;... }
Dependency Injection enables to turn regular Java classes into managed objects and to inject them into any other managed object The code declare any dependency to a managed object The container automatically : provides instances of these dependencies at the injection points at run time, manages the lifecycle of these instances @javax.enterprise.context.requestscoped public class CurrencyConverter {... } Declare un «managed bean» injection public class MyServlet extends HttpServlet { @Inject CurrencyConverter cc;...}
Ressource vs Dependency Injection L un par nom JNDI; l autre par type L un est typé, l autre pas
Javaeetutorial7 - chap 5
Packaging Une application JEE est paquagée dans une ou plusieurs unité standard Type d unité: ear, war, jar, rar Permet le déploiement sur n importe quel système JEE Chaque unité contient au moins un composant fonctionnel (enterprise bean, web page, servlet, ou applet), Et un descripteur de déployment optionel qui décrit le contenu (fichier xml). Application JEE Livrée dans un ear, un war ou un jar
EAR Permet d assembler des modules JEE
Paquager des EJBs.jar Module EJB, dans un fichier «jar» Approche conseillé
Paquager des EJBs dans un war C est possible Approche déconseillée Simplifie le déploiement Mais mauvaise réutilisation Mettre le jar des ejb dans WEB-INF/lib
WAR Représente un module «web»
RAR Resource Adapter Archive (RAR) file stores XML files, Java classes, and other objects for Java EE Connector Architecture (JCA) applications. A resource adapter can be deployed on any Java EE server, much like a Java EE application. A RAR file can be contained in an Enterprise Archive (EAR) file, or it can exist as a separate file. The RAR file contains: A JAR file with the implementation classes of the resource adapter An optional META-INF/ directory that can store an ra.xml file and/or an application server-specific deployment descriptor used for configuration purposes. A RAR file can be deployed on the application server as a standalone component or as part of a larger application. In both cases, the adapter is available to all applications using a lookup procedure.
Voir chap 26 avaeetutorial7
Les différents type d Enterprise Bean Voir chap 26 avaeetutorial7
Lectures The Java EE 7 Tutorial http://docs.oracle.com/javaee/7/tutorial/doc/ chap 1 à 5 chap 26 Enterprise Beans
Webographie The Java EE 7 Tutorial http://docs.oracle.com/javaee/7/tutorial/doc/