27
<Insert Picture Here> An Overview of the Java EE 6 Platform Roberto Chinnici Java EE Platform Lead

Overview of Java EE 6 by Roberto Chinnici at SFJUG

Embed Size (px)

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

Page 1: Overview of Java EE 6 by Roberto Chinnici at SFJUG

<Insert Picture Here>

An Overview of the Java EE 6 Platform

Roberto ChinniciJava EE Platform Lead

Page 2: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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.

Page 3: Overview of Java EE 6 by Roberto Chinnici at SFJUG

Agenda

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

Page 4: Overview of Java EE 6 by Roberto Chinnici at SFJUG

<Insert Picture Here>

Java EE 6 Platform

Page 5: Overview of Java EE 6 by Roberto Chinnici at SFJUG

JAVA EE 6

FINAL RELEASEDECEMBER 10, 2009

Page 6: Overview of Java EE 6 by Roberto Chinnici at SFJUG

What's New?

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

Page 7: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 8: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 9: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 10: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 11: Overview of Java EE 6 by Roberto Chinnici at SFJUG

Pluggability/Extensibility

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

Page 12: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 13: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 14: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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>

Page 15: Overview of Java EE 6 by Roberto Chinnici at SFJUG

Strategy for Evolving the APIs

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

Page 16: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 17: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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){…}

}

Page 18: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 19: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 20: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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() { … }

}

Page 21: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 22: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 23: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 24: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 25: Overview of Java EE 6 by Roberto Chinnici at SFJUG

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

Page 26: Overview of Java EE 6 by Roberto Chinnici at SFJUG

Java EE 6 Platform

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

http://www.oracle.com/javaee

Page 27: Overview of Java EE 6 by Roberto Chinnici at SFJUG