Java EE 5, How to Utilize Project GlassFish? 2007/02/24 Wonseok Kim Agenda • • • • • • • • • Java EE 5 Intro Project GlassFish Business Logic and Data Access Web Tiers XML and Web Services Tools Big Picture How to participate in Project GlassFish? Summary Java EE 5 Intro Java EE 5 Introduction ● ● ● ● ● ● Theme: Ease of development! POJO-based programming model Extensive use of metadata @annotations and defaults ● Simple and developer-friendly declarative model ● Reduced need of Deployment Descriptors Simplified API Dependency Injection New APIs and frameworks Java EE 5 Major changes ● ● ● ● ● ● ● EJB 3.0 JPA(Java Persistence API) 1.0 JSP 2.1, JSTL 1.2 JSF 1.2 Servlet 2.5 JAX-WS 2.0, JAXB 2.0, WSM 2.0, ... StaX J2EE 1.4 vs Java EE 5 Application Item Measured Adventure Number of classes Builder Lines of code Number of classes Lines of code RosterApp Number of XML files Lines of XML code J2EE 1.4 67 3,284 17 987 9 792 Java EE 5 43 2,777 7 716 2 26 Improvement 36% Fewer classes 15 % fewer lines 59% fewer classes 27% fewer lines 78% fewer files 97% fewer lines Table: Sample Comparison between J2EE 1.4 and Java EE 5 Java EE 5 Products • • • • • • GlassFish (open-source) Sun Java System Application Server 9 TmaxSoft Application Server JEUS 6 SAP NetWeaver Application Server BEA WebLogic Server 10 Tech Preview JBoss AS 5.0 Beta Project GlassFish Project GlassFish https://glassfish.dev.java.net/ • Open Source (CDDL, GPLv2) Project > Main GlassFish Project and Sub-projects • Java EE 5 RI(Reference Implementation) > Base of Java EE 5 SDK > Base of Sun Java System AppServer 9 > Code base for other Projects • Participation from > Sun, TmaxSoft, Oracle, BEA and Individuals • GlassFish v1 is released • GlassFish v2 will be released soon Timeline of Project GlassFish Tomcat Jasper Catalina JSTL Struts JAXB JAX-RPC Crimson JSF XSLTC Xalan Xerces J1'04 June 2004 V2 M4 GlassFish (current) Launch V1 final V2 final V1UR1 V2 Beta J1'05 June 2005 J1'06 May 2006 Jan 2007 Apr 2007 Releases in Project GlassFish • GlassFish v1 > Java EE 5 Compliance > UR1 - bug fixes • GlassFish v2 > New WS stack, performance, startup time > Load balancing, cluster management, failover > Some scripting support(Phobos) > Community, Transparency, Adoption • GlassFish v3 > Larger architectural changes > Better modularization, better scripting support GlassFish Major Technologies • Business Logic and Data Access > EJB 3.0 Container > Java Persistence(JPA) RI – TopLink Essentials • Web Tier > Servlet 2.5/JSP 2.1 Container > JSTL 1.2 > JavaServer Faces(JSF) 1.2 RI > JSF Extensions, jMaki (Ajax) > Phobos(scripting) > Grizzly NIO Framework GlassFish Major Technologies • XML and Web Services > JAX-WS 2.1 RI > JAXB 2.1 RI > WSIT (Tango) – WS Inteoperability > Fast InfoSet > StAX Parser - SJSXP • Misc > JMS > Shoal - Clustering framework > JavaMail 1.4 Business Logic and Data Access - EJB 3.0 and Java Persistence (JPA) EJB 3.0 ● ● POJO style Simplified API Simplified configuration ● ● ● ● ● ● Metadata Annotation - declarations on the code Extensive use of defaults - Configuration by exception ejb-jar.xml descriptor is now optional Dependency Injection – IoC Interceptor – cross-cutting concerns Container do more things for developer! Hello EJB // Business interface @Remote public interface Hello { public String sayHello(); } // Bean class @Stateless public class HelloBean implements Hello { public String sayHello(){ return "Hello EJB!"; } } // No Home interface // No ejb-jar.xml Dependency Injection @Stateless public class PayrollBean implements Payroll { @Resource SessionContext sc; @Resource UserTransaction ut; @Resource DataSource oracleDB1; @EJB Calculator calc; @Resource private void setOracleDB2(DataSource db){...} @PostConstruct private void init(){ connection = oracleDB1.getConnection(); } } How to Utilize EJB 3.0? • When to use Session Bean? > Transactional business logic > Data access logic (DAO) for JPA, others > Web Service Endpoint > IIOP communication with other systems • When to use MDB? > Asynchonous logic - JMS/JCA message handler • POJO? > Make test beans outside container (some tools will help) > Convert a POJO logic into beans • Benefit? Portable across vendors (JCP standard!) Java Persistence(JPA) • Persistence layer based on JDBC • Similar to existing ORM solution > Hibernate, TopLink • Replacement of EJB Entity Bean(CMP) • POJO style persistence model > No more remote component, but local object > No more EJB container-dependent > Unit-testable outside container > Usable as DTO(Data Transfer Object) • Explicit persistence operations are required > EntityManager API Java Persistence(JPA) • Rich O-R mapping > Inheritance, multiple-table, composite keys, locking > Standard mapping through annotations/XML • Object-level Java Persistence Query Language • SQL is generated for each type of database • Runtime performance - Minimize SQLs > Lazy fetching, Changeset, Batch update > Caching (effective for most read operations) • Pluggability of third-party persistence providers • Support for Java EE and Java SE Entity domain class @Entity @Table(name="CUST") public class Customer implements Serializable { @Id @GeneratedValue @Column(name="CUST_ID") protected Long id; protected String name; @Embedded protected Address address; @OneToMany(mappedBy="customer") protected Set<Order> orders; public Customer() {} public public public public ... } Long getId() { return id; } String getName() { return name; } void setName(String name) { this.name = name; } Address getAddress() { return address; } EntityManager Operations @PersistenceContext EntityManager em; //persist public Order addNewOrder(Customer customer, Product product) { Order order = new Order(product); customer.addOrder(order); em.persist(order); return order; } //find public Customer findCustomer(Long customerId) { Customer customer = em.find(Customer.class, customerId); return customer; } EntityManager Operations //update order.setDeliveredDate(date); bean.updateOrder(order); ... public Order updateOrder(Order order) { return em.merge(order); } //remove public void deleteOrder(Long orderId) { Order order = em.find(Order.class, orderId); em.remove(order); } Queries //Dynamic Query Query query = em.createQuery("select c from Customer c where c.name=:name"); query.setParameter("name", name); List list = query.getResultList(); //Static Query @Entity @NamedQuery(name="findCustomerByName", query="select c from Customer c where c.name=:name") public class Customer {..} Query query = em.createNamedQuery("findCustomerByName"); query.setParameter("name", name); List list = query.getResultList(); JPA RI Project - TopLink Essentials https://glassfish.dev.java.net/javaee5/persistence/ • Oracle contributed the initial code • Co-work from Oracle, Sun and TmaxSoft • Used in various products > GlassFish, Java EE 5 SDK, Sun Application Server 9 > Oracle AS 10.1.3.1 > TmaxSoft Appliation Server JEUS 6.0 > JOnAS EJB 3.0 Container – EasyBeans > Spring 2.0 > NetBeans 5.5 > ... How to Utilize TopLink Essentials? • JDBC coding is inefficient way and not portable > Persistence framework is necessarily needed > Most 90% RDB applications can benefit from this • Migration from EJB CMP, Hibernate, TopLink • Pluggable in > GlassFish > Tomcat, Geronimo, JBoss, ... other containers > J2EE 1.4 containers > General Java SE application • Spring 2.0 JPA Support Pack is useful for applications not based on Java EE 5 container Web Tiers JSP 2.1, JSTL 1.2 https://glassfish.dev.java.net/javaee5/webtier/webtierhome.html • A new unified expression language (EL) > JSP and JSF are consolidated into the unified EL. • JSTL 1.2 is now part of the Java EE platform • Support for Dependency Injection - tag handlers and tag library event listeners. • Minor updates... • GlassFish v2 > Can use JSR-199 (Javac APIs in Mustang) > 10x performance improvement on Java SE 6 JSF(JavaServer Faces) 1.2 RI Project https://javaserverfaces.dev.java.net/ • Alignment with JSP – Unified EL • Managed Beans support Dependency Injection • Minor updates... • GlassFish v2 > Performance enhancement > Dependency Injection mechanism for other containers Unified EL JSF 1.1 + JSP 2.0 could not do... <c:forEach var="color" items="${colorList}"> <h:inputText value="#{color.name}"/> </c:forEach> Both JSF 1.2 + JSP 2.1 can use unified EL - deferred expressions #{...} <c:forEach var="color" items="#{colorList}"> <h:inputText value="#{color.name}"/> </c:forEach> How to Utilize JSF RI? • Why JSF for web framework? > JSF is flexible and extensible framework > JSF is the standard supported by various vendors > JSF is gaining more and more popularity and adoption > More reusable Components and Tools > GlassFish itself using JSF for Admin Console • Good combination with AJAX • Pluggable in > GlassFish or other web containers – Tomcat • Participate in Extensions projects JSF and AJAX • Easy to make AJAX-enabled UI using JSF • DynaFaces/JSF Extensions Project > https://jsf-extensions.dev.java.net/ • Ajax4JSF Project > https://ajax4jsf.dev.java.net/ • AJAX-enabled JSF components > Sun Blueprint AJAX components, Oracle ADF Faces, Project Woodstock... • jMaki for existing Widgets • Demo - Pet Store 2.0 > http://webdev1.sun.com/petstore/faces/index.jsp jMaki – Ajax Framework Project https://ajax.dev.java.net/ • JavaScript Wrapper framework for Java EE • Common programming model for using widgets from multiple AJAX toolkits • Model for reusable Ajax-enabled widgets > your own design or extending existing toolkits > Bundled Dojo, Flickr, Google, Yahoo widgets... • Java Developers use JSP/JSF for widgets > Also supports Embedded JavaScript (Phobos), PHP 5.x • GlassFish or other web containers – Tomcat, PHP • IDE support - NetBeans plugin jMaki with JSP <%@ taglib prefix="a" uri="http://java.sun.com/jmaki" %> ... <a:ajax id="cb1" name="dojo.combobox" service="comboBoxData.js" /> <a:ajax name="flickr.search" args="{ topic:'flickrSearch', columns:3, count:9 }" service="xhp"/> jMaki with JSF <%@taglib prefix="a" uri="http://java.sun.com/jmaki-jsf" %> ... <h:form id="thisForm" onsubmit="return false;"> <a:ajax id="cbl" name="dojo.combobox" selected="#{ComboBoxBean.country}" value="#{ComboBoxBean.completeCountry}"/> <input type="button" value="Show Selected Value" onclick="alert(jmaki.attributes.get('thisForm:cb1').getV alue()); return false;"> </h:form> Grizzly – NIO Framework Project https://grizzly.dev.java.net/ • NIO HTTP Connector/Listener for GlassFish • Evolved into generic NIO Framework > Support multi protocols (HTTP, UDP, etc.) > Blocking, Non-blocking, Plain or SSL > High-performance APIs for socket communications • Extensible > From the management of low level byte buffer to thread management • Used in GlassFish, Tango(WSIT), OpenESB(JBI), Jetty, AsyncWeb, ... • Still Evolving Project Grizzly Performance Grizzly/GlassFish APR/Tomcat Coyote/Tomcat Static Small Static Medium Static Large Scalability Test Throughput Tests Servlets JSP Balanced Load XML and Web Services StAX (SJSXP) Project https://sjsxp.dev.java.net • Streaming event-driven, pull-parsing XML API • Why another XML API? > DOM API requires large memory and is slow > SAX API is fast, but we cannot control the process due to the push model > StAX is similar to SAX, but requires much simpler programming model and we can control (pull model)! • Benefits? > More control to applications - pausing/resuming/skipping > Easier to code than SAX > Bidirectional - read and write XML documents StAX comparison Feature API Type Ease of Use XPath Capability CPU and Memory Efficiency Forward Only Read XML Write XML Create, Read, Update, Delete StAX Pull, streaming High SAX Push, streaming Medium DOM In memory tree High TrAX XSLT Rule Medium No No Yes Yes Good Yes Yes Yes Good Yes Yes No Varies No Yes Yes Varies No Yes Yes No No Yes No Table XML Parser API Feature Summary http://www.developer.com/xml/article.php/3397691 StAX Example //Get the factory instace first. XMLInputFactory factory = XMLInputFactory.newInstance(); //create the XMLEventReader, pass the filename for any relative resolution XMLEventReader r = factory.createXMLEventReader(filename, new FileInputStream(filename)); //iterate as long as there are more events on the input stream while (r.hasNext()) { XMLEvent e = r.nextEvent(); System.out.println(e.toString()); //...PROCESSING LOGIC... } How to Utilize StAX? • • • • Also a part of Java SE 6 - JAXP 1.4 Can be used as a standalone tool/library Being used internally within JAXB and JAX-WS RI Use Adapters for existing applications > StAX Utilities Project - https://stax-utils.dev.java.net/ • Try StAX for performance/usability in new apps • Other similar projects > StAX RI Project - http://stax.codehaus.org > BEA StAX Parser - http://dev2dev.bea.com/xml/stax.html > Oracle StAX Parser - http://www.oracle.com/technology/tech/xml/ JAXB 2.0/2.1 RI Project https://jaxb.dev.java.net/ ● ● ● ● ● ● ● ● Java Architecture for XML Databinding (JAXB) High-level programming model for XML documents Ease of Development ● Typed access to XML content ● Leverage Java SE 5 features 100% XML Schema support XML -> Java or Java -> XML Schema binding Databinding for JAX-WS 2.0 Schema Evolution Partial Updateable Binding JAXB 2.0 Generated Code... @XmlAccessorType(FIELD) @XmlType(name = "", propOrder = {"x","y"}) @XmlRootElement(name = "point") public class Point { protected float x; protected float y; public float getX() { return x; } public void setX(float value) { this.x = value; } public float getY() { return y; } public void setY(float value) { this.y = value; } } <point> <x>1</x> <y>2</y> </point> Java Based Classes <=> XML Schema @XmlType(name=”Employee”, propOrder=”name, id”) public class Employee { public String getName(){ ... } public void setName(String ) {...} public long getId() {...} public void setId(long ) {...} } <xs:complexType name=”Employee”> <xs:sequence> <xs:element name=”name” type=”xs:string” minOccurs=”0”/> <xs:element name=”id” type=”xs:long”/> ... How to Utilize JAXB 2.0/2.1 RI? • Also a part of Java SE 6 • Can be used as a standalone tool/library • High-level XML processing tool for applications > XML Configuration processing > Data transfer through XML • JAX-WS is using JAXB as XML-Java binding • Participate in other Projects > XJC Plugins - https://jaxb2-commons.dev.java.net/ > HyperJAXB3 - relational persistence for JAXB objects > JAXB-Workshop - tool for launching XJC / visualization JAX-WS 2.0/2.1 RI Project https://jax-ws.dev.java.net/ • Next generation of JAX-RPC 1.0 • Core Java Web Service/SOA technology • Two types of APIs: > High-level: Strongly typed (Java-based) > Low-level: Loosely typed (XML-based) • Embrace POJO concepts via annotations • Descriptor-free programming • Layered architecture > Encoding, Protocol and Transport independence • Integrated data binding via JAXB 2.0 • Support for traditional and RESTful WS POJO Web Service @WebService public class Calculator { public int add(int a, int b) { return a+b; } } • Public methods become web methods • Or use @WebMethod annotations • http://myserver/myapp/MyService?WSDL Web Service Consumer $ wsimport http://myserver/myapp/MyService?WSDL > generates CalculatorService, Calulator, JAXB classes... CalculatorService svc = new CalculatorService(); Calculator proxy = svc.getCalculatorPort(); int answer = proxy.add(35, 7); • No need to use factories! • Use of dynamic proxies to hide complexity • XML is completely hidden from programmer New in JAX-WS 2.1 RI (GFv2) • JAX-WS 2.1 API compliance (WS-Addressing) • Complete re-architecture and re-write of JAX-WS 2.0 for Performance and Extensibility • Extensions > WSIT, Spring support > Pluggable Transport - In-VM transport, Servlet transport, JMS transport, SOAP/TCP > FastInfoset • • • • Data binding - JAXB 2.1 Server Side Asynchrony - AsyncProvider Stateful Web Services Hosting API WS Performance in GF V2 GF V1 GF V2 JAX-WS 2.1 vs. Axis2 http://weblogs.java.net/blog/kohsuke/archive/2007/02/jaxws_ri_21_ben.html WSIT (Project Tango) https://wsit.dev.java.net/ • WSIT(Web Services Interoperability Technologies) > Interoperability with Microsoft WCF (.NET 3.0) > Implementation of WS-* specifications > Foundation for building SOA • Programming Model > No runtime APIs for Tango > Developer writes consumers/providers via JAX-WS and EJB APIs > Developer/deployer supplies config file to enable/control Tango components (by hand or Tool) Web Services Stack Transactions in Action @javax.jws.WebService @javax.ejb.Stateless @javax.ejb.TransactionManagement(CONTAINER) public class Wirerer { } @javax.jws.WebMethod @javax.ejb.TransactionAttribute(REQUIRED) void wireFunds(...) throws ... { websrvc1.withdrawFromBankX(...); websrvc2.depositIntoBankY(...); } WSIT Server Programming Model 109 Deployment META-INF/wsit-*.xml WSIT NetBean Module By Hand Other IDEs WSIT Config File wsit.xml Service Servlet Deployment WEB-INF/wsit-*.xml WSIT Client Programming Model 109 Service WSIT NetBean Module By Hand Other IDEs MEX/ GET WSIT Config File wsit-*.xml Client Artifacts WDSL MEX/ GET Wsimport How to Utilize JAX-WS RI/WSIT? • Also a part of Java SE 6 • High usability, secure and transactional WS! • Endpoint Deployment > In GlassFish > With Light weight HTTP server > On JDK 1.5 through http.jar distributed with the JAX-WS 2.1 RI bundle > Bundled with JDK 6 > In any web containers such as Tomcat... • Participate in other Projects > JAX-WS Plugins and Extensions Project https://jax-ws-commons.dev.java.net/ Useful Tools • NetBeans 5.5/5.5.1 - http://www.netbeans.org > 5.5.1 is for GlassFish v2 > Enterprise Pack - full support of Java EE 5 development > Visual Web Pack for JSF > jMaki plugin > WSIT plugin • Eclipse - https://glassfishplugins.dev.java.net/ > Eclipse plugin based on WTP 1.5 > Dali Project (JPA Tool) - http://www.eclipse.org/dali/ • Hudson Build System - https://hudson.dev.java.net/ > Continuous Build (like CruiseControl) NetBeans 5.5.1 Eclipse Dali Hudson How to participate in GlassFish? The Aquarium – News on GlassFish blogs.sun.com/theaquarium GlassFish Community • As Users > The Aquarium – News and Blogs > Forums: https://glassfish.dev.java.net > Mailing Lists: [email protected], ... • As Contributors > Share ideas – Tips, Howtos, Adoption stories,... > Blogging! > Samples, applications > Documentation: http://www.glassfishwiki.org > Issues(Bugs and RFEs) report: Issue Trackers > Code patch: Submit on Issue Trackers and Mailing Lists GlassFish Projects • • • • • • • • • • • • • • GlassFish Core&Container: JSP, Servlet, EJB... TopLink Essentials: JPA RI JSF: Java Server Faces RI, JSF Extensions jMaki : AJAX Framework Grizzly : NIO Framework SJSXP: Sun Java Streaming XML Parser(StAX) JAXB: Java API for XML Binding JAXP: Java API for XML Parsing JAXR: Java API for XML Registry JAX-RPC: Java API for XML RPC JAX-WS: Web Services JAX-WS Commons: Plugins and Extensions SAAJ: The Standard Implementation for SAAJ WSIT(Tango): Web Service Interoperability Technology GlassFish Projects • Phobos: A lightweight, scripting-friendly, web application environment(server-side JavaScript) • Fast Infoset: Binary encoding for the XML Information Set • Shoal: Java based clustering framework • Glassfish-Corba: CORBA ORB that is used in the GlassFish • Glassfish-plugins: Plugins for both NetBeans and Eclipse • Blueprints solution catalog: Guidelines and best practices for Java EE applications • Glassfish-samples: Sample applications to demonstrate Java EE • First Cup: A short tutorial for new Java EE developers GF technologies Big Picture UI AJAX WSIT Web Services JAX-WS JSF NIO Framework Grizzly Business Logic JAXB StAX Other Systems Tools EJB 3.0 NetBeans Data Access JPA TopLink Essentials Eclipse Hudson XML DB Summary & Conclusion • Java EE 5 has new/enhanced technologies • Open Source Project GlassFish is the central place for Java EE 5 and derived technologies • Many technologies/impl can be used independently – in other web containers or general Java SE app • GlassFish v2 has lots of improvements, check it out! • GlassFish has lots of interesting Sub-Projects • Find out your flavor and try to use it • You can also participate in Project! References ● Java EE Official Site – Find out Java EE 5 materials http://java.sun.com/javaee/ ● Article: An Introduction to the Java EE 5 Platform http://java.sun.com/developer/technicalArticles/J2EE/intro_ee5/ ● ● Magazine: MicroSoftware 2006 July Cover Story – Java EE 5 Java EE 5 Tutorial – Learn how to use each technology http://java.sun.com/javaee/5/docs/tutorial/doc/ ● 2006 JavaOne Online Technical Sessions – Audio, PDFs http://developers.sun.com/learning/javaoneonline ● ● Project GlassFish https://glassfish.dev.java.net Author(Wonseok Kim)’s Blog http://weblogs.java.net/blog/guruwons/ Help Improve This Presentation The copyright of this speech is licensed under a creative commons license. Some rights are reserved. ©2007 Wonseok Kim, Eduardo Pelegri-Llopart See http://creativecommons.org/licenses/by-nc-sa/2.5/ If you want to contribute, keep attribution and maintain license. We would also appreciate notifying us of the changes. More related presentations are kept at the Presentations page of the GlassFish Wiki. http://www.glassfishwiki.org/gfwiki/Wiki.jsp?page=Presentations
© Copyright 2024