130 likes | 263 Views
JBoss at Work JAW Motors Application Chapter 1-3. Jeff Schmitt October 9, 2006. JAW Motors Application. Fictitious automobile dealership Each chapter progressively adds a new J2EE technology that solves a specific business problem Viewing cars – JSP
E N D
JBoss at WorkJAW Motors ApplicationChapter 1-3 Jeff Schmitt October 9, 2006
JAW Motors Application • Fictitious automobile dealership • Each chapter progressively adds a new J2EE technology that solves a specific business problem • Viewing cars – JSP • Storing cars (persistence) – JDBC or Hibernate • Credit check -- JMS message and JavaMail response • Purchasing – transactional support using Stateless Session Beans • Sharing data between dealerships – Web Services
JBoss – Application server • Compiled Java code runs inside JVM • Java classes need a container to provide an infrastructure, a framework to handle low-level details • An application server is a loosely coupled collection of containers (or "services") that correspond to the various parts of the J2EE API. • JBoss is an open-source J2EE 1.4 standards compliant application server
Java Management ExtensionsJMX • JBoss is a thin JMX (Java Management Extensions) microkernel • JMX is a framework that allows you to interact with live, running code • Start and stop services • Gather metrics • Change parameters • Services that implement the JMX interface are called Managed beans or Mbeans • MBeans that run inside JBoss include: Log4J, Tomcat, Hibernate
Tools needed • Java JDK – J2SE 1.4 or higher • Ant – to compile, package and deploy Java code • XDoclet – to generate deployment descriptors, web.xml and various other J2EE configuration files. • XDoclet is a combination of custom Ant tasks and special attributes that you include in your source code.
JAW Motors Application • Use Tomcat servlet container • JBoss is an application server, but includes Tomcat • 3-tier application • Presentation – JSP and servlets • Business logic – EJB and MDB’s • Persistence – relational database • Components in each tier • Highly cohesive – components do only one thing • Loosely coupled – components have no dependences across tiers
Model View Controller • View – HTML, JSP, CSS and JSTL produce the screen contents • Model – POJO (Plain Old Java Objects), Java Beans • Controller – mediates communication between the view and the model -- a servlet • Framework – many design decisions already made for you – this book is framework-neutral – uses its own controller servlet
View • carList.html • carList-jstl.jsp – with JSTL tags – JSP scriplet defines data: carList[] • carList.jsp – with stylesheet: default.css – data saved in pageContext
Model and Controller • Model • CarBean is a POJO, is a JavaBean • carList.jsp uses JSP EL • Controller • ControllerServlet • Action parameter indicates page indirectly • To access carList.jsp we use: <a href=“controller?action=viewCarList”> • Controller translates action=viewCarList to access carList.jsp
JBoss Deployment • Applicatioin Assembly • Web Archive file – a collection of presentation tier files (HTML, JSP, Servlets, etc) • EAR – Enterprise Archive (EJB’s) • SAR – Service Archive (Web Services) • Use “jar” command to bundle them into a single file • Application Deployment • Hot deployment -- While JBoss is running, copy the WAR, EAR or SAR file to $JBOSS_HOME/server/default/deploy/ • Cold deployment – stop JBoss, copy the file, restart JBoss – this is the recommended deployment
EAR Deployment • EAR – Enterprise Archive • Similar to WAR – Web Archive • bundles together the pieces of a full J2EE application • keeps things organized • unpacked by server • Contains three “modules” • Web Module – a war file for presentation • EJB Module – an EJB jar file • Java Module – Java classes jar file • Application.xml – in META-INF directory -- a packing list – tells where you can find each file relative to the root
Data Access Object - DAO • A layer of abstraction • Hides the actual persistence details behind a common interface • For this chapter, a simple ArrayList • In subsequest chapters, Hibernate, an Object-Relational Mapper (ORM) for relational DB • CarDAO.java • Constructor creates ArrayList of CarDTO objects • findAll() – method to return all cars • CarDTO.java – a Car JavaBean • ControllerServlet.java – creates CarDAO and forwards to carList.jap
Automated Deployment • Ant can • compile and create WAR/EAR (build process) • Create/delete directories • Copy files • Call XDoclet tasks • XDoclet – to generate config files (web.xml) and/or java code during the build process • Cold deploy uses Ant task: cleandeploy • Visit http://localhost:8080/jaw