Java EE 6 workshop at Dallas Tech Fest 2011

Preview:

DESCRIPTION

Java EE 6 workshop at Dallas Tech Fest 2011

Citation preview

1

Java EE 6 = Less Code + More Power

Arun Gupta, Java EE & GlassFish Guyblogs.oracle.com/arungupta, @arungupta

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions.

The development, release, and timing of any features or functionality described for Oracle's products remains at the sole discretion of Oracle.

The Java EE 6 Platform

Servlets 3.0

JSP 2.2

JSF 2.0

EJB 3.1 Lite

JTA 1.1 ManagedBeans 1.0

JPA 2.0

CDI 1.0

BeanValidation1.0

Interceptors1.1

JAX-WS

JAX-RS

JAXB

EJB 3.1

JASPIC

JDBC

JNDI

JMS

JAXP

JAX-RPC . . .

SAAJ

JACC

JavaMail

StAX

New Updated Contributed by RedHat Web Profile 1.0

● Java EE 6 Web Profile● Pruning

● Pruned today, means– Optional in the next release– Deleted in the subsequent releases

● Technologies marked in Javadocs– EJB 2.x Entity Beans, JAX-RPC, JAXR, JSR 88

Light-weight

● EJB-in-WAR● No-interface EJB● Optional

“web.xml”/”faces-config.xml”

● Annotation-driven● @Schedule● @Path● @Inject● . . .

<web-fragment> <filter> <filter-name>wicket.helloworld</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>...</param-value> </init-param> </filter>

<filter-mapping> <filter-name>wicket.helloworld</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-fragment>

From the real users ...Developers can concentrateon business logic, Java EE 6 is providing a standard for the infrastructure.

Jigsaw puzzle, Modular, standard, less xml, easy, easy, have I said easy?

Higher integrated specs,simple and annotation driven,single-classloader WARs,next level of industry standard

Standards compliance, vendor independence, milliseconds and kilobyte deployment

http://blogs.oracle.com/arungupta/tags/community+feedback

Faster development, less frameworks, less complexity, more great code shipped

Not your fat grandfather's enterprise Java anymore, enterprise Java renaissance

Definite excuse to avoid Spring forever

Simplified Java Development, Focus on building great products

Compatible Java EE 6 Impls

Today:

Announced:

Web Profile Only

3.1 Overview

● Built on GlassFish 3● Modular and Extensible HK2 Kernel

● ~260+ modules● OSGi/Java EE Hybrid Apps

● Clustering and High Availability● HTTP, EJB, IIOP, SSO, Metro

● Containers start on demand● End-to-end extensibility

Sample App Overview

DatabaseEJB

CLI

Servlet

JSFJAX-RSCDI

JPA

What will we do ?

1. Generate JPA Entities from the database table

2. Refactor generated entities for a more intuitive O/R mapping

3. Create an EJB for querying the database

4. Create a Servlet for testing the EJB and displaying values from the database table

5. Enable CDI and make the EJB EL-injectable

6. Display the values in JSF2/Facelets-based view

7. Expose JPA entities as a RESTful resource by using JAX-RS

What will we use ?

Generate JPA EntitiesAnd customize them

DatabaseEJB

CLI

Servlet

JSFJAX-RSCDI

JPA

Java Persistence API 2● Improved O/R mapping● Type-safe Criteria API● Expanded and Richer JPQL● 2nd-level Cache● New locking modes

● PESSIMISTIC_READ – grab shared lock● PESSIMISTIC_WRITE – grab exclusive lock● PESSIMISTIC_FORCE_INCREMENT – update version

● Standard configuration options● javax.persistence.jdbc.[driver | url | user | password]

Create an EJBFor querying the database

DatabaseEJB

CLI

Servlet

JSFJAX-RSCDI

JPA

Create an EJB – Sample CodeFor querying the database

@PersistenceContextEntityManager em;

public List<Customer> getCustomers() {return (List<Customer>)em.createNamedQuery("Customer.findAll").getResultList();}

EJB 3.1● Simplified Packaging● No interface view – one source file per bean● Embeddable API● @Singleton

● Initialization in @PostContruct● Simplified Cron-like syntax for Timer● Asynchronous Session Bean● Portable Global JNDI Name

Create a ServletFor testing EJB and display values from the database

DatabaseEJB

CLI

Servlet

JSFJAX-RSCDI

JPA

Create a Servlet – Sample CodeFor testing EJB and display values from the database

@EJB CustomerSessionBean ejb;

out.println(ejb.getCustomers());

http://localhost:8080/JavaEE6SampleApp/TestServlet

Servlets 3.0● @WebServlet, @WebListener, @WebFilter, …● Asynchronous Servlets

● @WebServlet(asyncSupported=true)● Plugin libraries using web fragments● Dynamic registration of Servlets● WEB-INF/lib/[*.jar]/META-INF/resources

accessible in the root● Programmatic authentication login/logout● Default Error Page● . . .

Enable CDIMake the EJB EL-injectable

DatabaseEJB

CLI

Servlet

JSFJAX-RSCDI

JPA

Enable CDI – Sample CodeMake the EJB EL-injectable

@javax.inject.Named

Contexts & Dependency Injection

● Standards-based Dependency Injection● Type-safe – Buids on @Inject API● Context/Scope management● Strong Typing, Loose Coupling● Includes ELResolver

@Inject @LoggedIn User user

RequestInjection What ?

(Type)Which one ?

(Qualifier)

@Inject @LoggedIn User

CDI

● Qualifiers● Events● Stereotypes● Interceptors● Decorators● Alternatives● . . .

Display the valuesIn JSF2/Facelets-based view

DatabaseEJB

CLI

Servlet

JSFJAX-RSCDI

JPA

Display the values – Sample CodeIn JSF2/Facelets-based view

http://localhost:8080/JavaEE6SampleApp/faces/index.xhtml

<h1>Java EE 6 Sample App</h1>

<center>Powered by GlassFish!</center>

<h:dataTable value="#{customerSessionBean.customers}" var="c"><h:column>#{c.name}</h:column><h:column>#{c.customerId}</h:column></h:dataTable>

Java Server Faces 2.0

● Facelets as “templating language” for the page● Custom components much easier to develop

● Integrated Ajax● “faces-config.xml” optional in common cases● Default navigation rules● Much more …

● Runs on Servlet 2.5+● Bookmarkable URLs● Conditional navigation● ...

RESTful resourceUsing JAX-RS

DatabaseEJB

CLI

Servlet

JSFJAX-RSCDI

JPA

RESTful resource – Sample CodeUsing JAX-RS

@Path("/customers")

http://localhost:8080/JavaEE6SampleApp/resources/customers/customer/1

@Produces({"application/xml", "application/json"})

@GET@Path("/customer/{id}")@Produces("application/xml")public Customer getCustomer(@PathParam("id")Integer id) {return(Customer)em.createNamedQuery("Customer.findByCustomerId").setParameter("customerId", id).getSingleResult();}

JAX-RS 1.1

● Java API for building RESTful Web Services● POJO based● Annotation-driven● Server-side API● HTTP-centric

Sample App Review

DatabaseEJB

CLI

Servlet

JSFJAX-RSCDI

JPA

Java EE for the Cloud : JSR 342● More easily operate on private/public clouds

● Multi-tenancy● Elasticity● Service Provisioning

● Tighter requirements for resource/state management● Better isolation between applications● Potential standard APIs for NRDBMS, Caching, other● Common management and monitoring interfaces● Better packaging● Evolution, not revolution

Java EE 7 : Technology Refresh

● Ease-of-development: JMS 2.0● Latest web standards

● New JSRs: Web Sockets, Java JSON API● HTTP Client API (JAX-RS 2.0)

● Possible JSRs inclusion● Concurrency Utilities for Java EE (JSR 236)● JCache (JSR 107)

Java EE 7 – When ?

● Late 2012● Date-driven release

● Anything not ready will be deferred to Java EE 8● Participate

● Expert Groups forming● Public discussion lists● JCP membership free for individuals

Transparency Checklisthttp://jcp.org/en/resources/transparency

● EG members names● EG business reported on a publicly

readable alias● Schedule is public, current and updated

regularly● Public can read/write to a wiki● Discussion board on jcp.org● Public read-only issue tracker

NEW

● Find out what's new with Java technology● See new tools and techniques● Learn how to create solutions● Network with peers● Meet with experts● Influence the future of the Java platform● 400+ sessions/BoFs/HOLs● . . . oracle.com/javaone

References

● oracle.com/javaee● glassfish.org● oracle.com/goto/glassfish● blogs.oracle.com/theaquarium● youtube.com/GlassFishVideos● Follow @glassfish

39

Java EE 6 = Less Code + More Power

Arun Gupta, Java EE & GlassFish Guyblogs.oracle.com/arungupta, @arungupta