Abteilung Verteilte Systeme Projektgruppe AspectIX Universität Ulm Fakultät für Informatik AVID-Übung 3 EJB mit JBoss und Eclipse 17. Juni 2004 Andreas I. Schmied (schmied@inf...)
AVID-Übung 3 Aufgabenstellung Sun's J2EE 1.4 Tutorial durcharbeiten 8^] ggf. Kapitel überspringen (XML-Basics,...) JBoss-IDE Eclipse-Plugin: guter Tutorial Guide als Einstieg integrierter XDoclet-Support! integriertes Packaging und Deployment! JBoss-Server Management! JBoss-Debugging! JBoss Application Server eigenes Tutorial: Anpassungen für Sun's Tutorial nächste Übung 24.6. Fragen zum Tutorial und eigene EJB-Aufgabe Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 2/21
AVID-Übung 3 Sun's J2EE Tutorial Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 3/21
Sun's J2EE Tutorial AVID-Übung 3 Inhalt Einstieg: JBoss-IDE Tutorial Guide bearbeiten Reihenfolge für die Übung zuerst Overview Getting Started, Servlets Enterprise Beans danach JSP Duke's Bank Case Study später Transactions,... (aus Sun's J2EE Tutorial) Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 4/21
AVID-Übung 3 JBoss Open-Source J2EE Application Server Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 5/21
Installation Auspacken des JBoss-Tarballs/Zips: bin Skripte: run.sh/bat, shutdown.sh/bat client Client-JARs, -Configuration docs Dokumentation und DTD/Schemata lib Server-JARs server verschiedene Server-Konfigurationen (all, minimal, default) Danach JBoss-IDE in Eclipse integrieren (IDE Installation Guide) automatisch im Eclipse Update-Service manuell entpackter Tarball in eclipse/plugins, eclipse/features Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 6/21
Konfigurationen Startskript: bin/run.sh [-c <userconf-dir> minimal all] Verzeichnisse pro Konfiguration in./server/<conf-dir>: conf u.a. jboss-service.xml data Daten von eingebetteter Hypersonic DB und JBossMQ deploy packed/unpacked JAR/WAR/EAR files lib weitere JARs, JDBC-Provider, etc. work Tomcat Arbeitsverzeichnis (für JSPs) (Auswahl) Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 7/21
Management Default-Webadresse: http://localhost:8080 bzw. http://127.0.0.1:8080 JBoss Server-Struktur: kleiner Minimal-Kern, Funktionalität ausgelagert in... Managed Beans (MBeans) der Java Management Extensions (JMX) Deployment: JARs mit besonderem Aufbau: EAR bzw. WAR automatisch: Archiv in <config>/deploy kopieren zur Laufzeit mittels Deployer MBean in Eclipse Web Management Konsolen http://localhost:8080/jmx-console Info, Konfiguration, direkter Methodenaufruf an MBeans http://localhost:8080/web-console - Statistiken (in Arbeit) Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 8/21
Screenshot: Web-Konsole Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 9/21
JBoss-IDE Tutorial: Fibonacci-SessionBean Aufruf via <FORM> in http://localhost:8080/fibo/index.html Servlet Compute wird als Form-Action aufgerufen instantiiert Home und Bean aktiviert Bean und erzeugt Ergebnis als dyn. HTML-Seite Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 10/21
JBoss-IDE Tutorial: Einzelschritte Java-Projekt erzeugen Build-Path inkl.: javax.servlet.jar, jboss-j2ee.jar Bean und Servlet implementieren Projekt-Properties für XDoclet: EJB- und Servlet-Konfiguration HTML-Seite verfassen Deployment Descriptors (EJB, Web), EJB-Interfaces generieren Application Descriptor verfassen Packaging-Skript verfassen und ausführen für..ejb.jar,..ejb-client.jar,..web.war,..app.ear JBoss starten und Deployment Tests und Debugging,... Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 11/21
HTML-Formular und Ausgabe Formular Ausgabe Getestet mit: Eclipse 3M9, JDK 1.4.2, JBoss 3.2.3, JBoss-IDE 1.2.43 Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 12/21
Bean-Quellcode package tutorial.ejb; import java.rmi.remoteexception; import javax.ejb.*; /** @ejb.bean name = "Fibo" * display-name = "Fibo EJB" * description = "EJB that computes Fibonacci suite" * view-type = "remote" * jndi-name = "ejb/tutorial/fibo" */ public class FiboBean implements SessionBean {... /** @ejb.create-method */ public void ejbcreate() throws CreateException {} /** @ejb.interface-method view-type = "remote" */ public double[] compute(int number) {... } } public void ejbactivate() throws EJBException,... {} public void ejbpassivate() throws EJBException,... {} public void ejbremove() throws EJBException,... {} public void setsessioncontext(sessioncontext sc)... {} Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 13/21
Servlet-Quellcode package tutorial.web; import tutorial.interfaces.fibo;...fibohome; /**... */ public class ComputeServlet extends HttpServlet {... FiboHome home; String title; protected void dopost(httpservletrequest request, HttpServletResponse response)... { response.setcontenttype("text/html"); PrintWriter out = response.getwriter(); out.println("<html><head>..."+title+"...<body>"); int limit = "(int)" request.getparameter("limit"); Fibo bean = home.create(); double[] result = bean.compute(limit); bean.remove(); } } printresulthtml(out, result); out.println("</body></html>"); out.close(); Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 14/21
Servlet-Quellcode: Bean-Home initialisieren public class ComputeServlet extends HttpServlet {... FiboHome home; String title; public void init() throws ServletException { Context context = new InitialContext(); title = (String) context.lookup("java:/comp/env/title"); Object ref = context.lookup("java:/comp/env/ejb/fibo"); home = (FiboHome) PortableRemoteObject.narrow(ref, FiboHome.class); } } JNDI-Objekte java:/comp/env/... via Deployment definiert suche Component Environment über Einträge im Verzeichnisdienst Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 15/21
Servlet-Quellcode: XDoclet-Tags /** * @web.servlet name = "ComputeServlet" * display-name = "Computation Servlet" * description = "Servlet that computes..." * * @web.servlet-mapping url-pattern = "/Compute" * * @web.env-entry name = "Title" * type = "java.lang.string" * value = "Fibonacci computation" * description = "Example of Env Entry" * * @web.ejb-ref name = "ejb/fibo" * type = "Session" * home = "tutorial.interfaces.fibohome" * remote = "tutorial.interfaces.fibo" * description = "Reference to Fibo EJB" * * @jboss.ejb-ref-jndi ref-name = "ejb/fibo" * jndi-name = "ejb/tutorial/fibo" */ public class ComputeServlet extends HttpServlet {... } Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 16/21
Application Descriptor <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd"> <application> <display-name>sum Application</display-name> <module> <ejb>fiboejb.jar</ejb> </module> <module> <web> <web-uri>fiboweb.war</web-uri> <context-root> /fibo </context-root> </web> </module> </application> Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 17/21
Eclipse JBoss-IDE Screenshots (1) Projekt-Kontext EAR-Kontext Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 18/21
Eclipse JBoss-IDE Screenshots (2) XDoclet-Konfigurationen Packaging-Skript Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 19/21
AVID-Übung 3 Anhang Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 20/21
Anhang AVID-Übung 3 Literatur und Installation Lokaler Mirror auf der AVID-Webpage! Sun's J2EE Tutorial http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html inkl. Sourcen JBoss Application Server 3.2.3/4 http://www.jboss.org/downloads/index IDE 1.2.43 (Eclipse Plug-in) -> Pool? http://jboss.sourceforge.net/jbosside/updates Anpassung von Sun's J2EE Tutorial http://www.jboss.org/docs/jbossj2ee-src.zip => siehe auch Literaturlinks der letzten Übung Copyright 2004 Andreas I. Schmied (schmied@inf...), Abteilung Verteilte Systeme, Universität Ulm 21/21