Overview of Java EE 6 by Roberto Chinnici at SFJUG

Preview:

DESCRIPTION

Roberto Chinnici, Java EE 6 spec lead, gives an overview of Java EE 6 for San Francisco Java User Group on August 10th, 2010.http://www.sfjava.org/calendar/13940755/

Citation preview

<Insert Picture Here>

An Overview of the Java EE 6 Platform

Roberto ChinniciJava EE Platform Lead

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.

Agenda

• What's new in Java EE 6?• Web Profile• Extensibility• Highlights from some of the new APIs

<Insert Picture Here>

Java EE 6 Platform

JAVA EE 6

FINAL RELEASEDECEMBER 10, 2009

What's New?

• Several new APIs• Web Profile• Pluggability/extensibility• Dependency injection• Lots of improvements to existing APIs

New and updated components

• EJB 3.1• JPA 2.0• Servlet 3.0• JSF 2.0• JAX-RS 1.1• Connectors 1.6• Bean Validation 1.0• DI 1.0• CDI 1.0

• Managed Beans 1.0• Interceptors 1.1• JAX-WS 2.2• JSR-109 1.3• JSP 2.2• EL 2.2• JSR-250 1.1• JASPIC 1.1• JACC 1.5

Web Profile

• First Java EE profile to be defined• A fully-functional, mid-size stack for modern web

application development• Complete, but not the kitchen sink

Java EE 6 Web Profile Contents

JSF 2.0

JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0

Servlet 3.0

EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0

Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1

JPA 2.0 · JTA 1.1

Java EE 6 Web Profile Extension Points

JSF 2.0

JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0

Servlet 3.0

EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0

Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1

JPA 2.0 · JTA 1.1

Pluggability/Extensibility

• Focus on the web tier in this release• Create a level playing field for third-party frameworks• Simplify packaging of web applications

Modular Web Applications

• Libraries can contain /META-INF/web-fragment.xml• web.xml is optional• @WebServlet, @WebFilter annotations• ServletContainerInitializer interface• Programmatic registration of components• Resource jars containing /META-INF/resources /WEB-INF/lib/catalog.jar /META-INF/resources/catalog/books.html

→ http://myserver:8080/myapp/catalog/books.html

Sample Servlet

import javax.servlet.annotation.WebServlet;

@WebServlet(urlPatterns=”/contents”)

public class MyServlet extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response) {

// ...

}

}

No deployment descriptor needed

Sample Web Fragment Descriptor

<web-fragment

version=”3.0”

xmlns="http://java.sun.com/xml/ns/javaee">

<servlet>

<servlet-name>welcome</servlet-name>

<servlet-class>WelcomeServlet</servlet-class>

</servlet>

<listener>

<listener-class>RequestListener</listener-class>

</listener>

</web-fragment>

Strategy for Evolving the APIs

• Capture common patterns• Fix inconsistencies• Adopt what works• Make APIs work better together• Reducing boilerplate/packaging• Be transparent

JAX-RS 1.1

• RESTful web services API• Already widely adopted• Really a general, high-level HTTP API• Annotation-based programming model• Programmatic API when needed

JAX-RS Sample

@Path(“widgets/{id}”)

@Consumes(“application/widgets+xml”)

@Produces(“application/widgets+xml”)

public class WidgetResource {

public WidgetResource(@PathParam(“id”)

String id) {…}

@GET

public Widget getWidget() {…}

@PUT

public void putWidget(Widget widget){…}

}

Building HTTP Responses

return Response.created(createdUri)

.entity(createdContent)

.build();

return Response.status(404)

.entity(message)

.type("text/plain")

.build();

Similarly, use UriBuilder to build URIs

EJB 3.1

• @Singleton beans• @Startup beans• Declarative timers• Asynchronous method calls @Asynchronous public Future<Integer> compute();• Define EJBs directly inside a web application• EJBContainer API works on Java SE

EJB 3.1 Code Snippets

@Singleton @Startup

public class StartupBean {

@PostConstruct

public void doAtStartup() { … }

}

@Stateless public class BackupBean {

@Schedule(dayOfWeek=”Fri”, hour=”3”, minute=”15”)

public void performBackup() { … }

}

@Stateless public class CacheRefreshingBean {

@Schedule(minute=”*/5”, persistent=false)

public void refreshCache() { … }

}

EJB 3.1 Lite

• A subset of EJB 3.1• All types of session beans (stateful, stateless, singletons)• Local access only• Declarative transactions and security• Interceptors• ejb-jar.xml descriptor optional

Java EE 6 Web Profile Core Component Model

JSF 2.0

JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0

Servlet 3.0

EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0

Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1

JPA 2.0 · JTA 1.1

Dependency Injection

• DI + CDI (JSR-330 + JSR-299)• @Resource still around for container resources @Resource DataSource myDB;• Added @Inject annotation for type-safe injection @Inject @LoggedIn User user;• Automatic scope management (request, session, etc.)• No configuration: beans discovered at startup• Extensible via the BeanManager API

Scoped Bean with Constructor Injection

@ApplicationScoped

public class CheckoutHandler {

@Inject

public CheckoutHandler(

@LoggedIn User user,

@Reliable @PayBy(CREDIT_CARD)

PaymentProcessor processor,

@Default ShoppingCart cart) {…}

}

Injection points identified by Qualifier + Type@Default qualifier can be omitted

Why Use CDI?

• Structure the application as a set of beans• Injection and events enable decoupling

– No direct dependency between beans– Freedom to refactor the code, change implementations

• Automatic state management base on scope• Support EJB components and plain “managed beans”• Beans discovered automatically - no configuration

needed• Extensible notion of bean

– Can incorporate components from external frameworks

Java EE 6 Platform

• More powerful• More flexible• More extensible• Easier to use

http://www.oracle.com/javaee

Recommended