40
JavaEE.Next(): Java EE 7, 8, and Beyond Reza Rahman Java EE/GlassFish Evangelist [email protected] @reza_rahman

JavaEE.Next(): Java EE 7, 8, and Beyond

Embed Size (px)

DESCRIPTION

Java EE 7 is here and the horizons for Java EE 8 are emerging. This session looks into the key changes the community can expect. The goal of this session is to foster interest and discussion around these changes. Some of the changes discussed include retiring EJB 2 entity beans and JAX-RPC, greater alignment with CDI, WebSocket/HTML 5 support, a standard API for JSON processing, the next version of JAX-RS, an overhaul of JMS, long-awaited concurrency utilities, batch processing in Java EE and much, much more.

Citation preview

Page 1: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public1

JavaEE.Next(): Java EE 7, 8, and BeyondReza RahmanJava EE/GlassFish [email protected]@reza_rahman

Page 2: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public2Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public

Agenda Overview

A Taste of API Changes

Looking Ahead

Page 3: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public3

The preceding 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 4: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public4

Java EE Past, Present, & Future

J2EE 1.3

CMP,JCA

J2EE 1.4

Web Services, Mgmt, Deplymnt

Java EE 5

Ease of Use,EJB 3, JPA, JSF, JAXB,JAX-WS

Java EE 6

Pruning,Ease of Use,JAX-RS,CDI,Bean-Validation

Web Profile

Servlet 3,EJB 3.1 Lite

Java EE 7

JMS 2, Batch, TX, Concurr,Web-Sockets,JSON

Web Profile

JAX-RS 2

J2EE 1.2

Servlet, JSP, EJB, JMS, RMI

Page 5: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public5

Java EE 7

Connector 1.7

Connector 1.7

Managed Beans 1.0Managed Beans 1.0 EJB 3.2EJB 3.2

Servlet 3.1Servlet 3.1

Eco-system

Eco-system

JSF 2.2JSF 2.2 JAX-RS 2

JAX-RS 2

JMS 2JMS 2JPA 2.1JPA 2.1

EL 3EL 3

JTA 1.2JTA 1.2

JSP 2.3JSP 2.3

Interceptors 1.2Interceptors 1.2 CDI 1.1CDI 1.1Common Annotations 1.2

Common Annotations 1.2

UpdatedMajorRelease

New

Concurrency Utilities

Concurrency Utilities

Batch Applications

Batch Applications

Java API for JSONJava API for JSON

Java API for WebSocketJava API for WebSocket

Bean

Valid

ation

1.1B

ean V

alidatio

n 1.1

Page 6: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public6

JMS 2

API modernization using dependency injection Delivery delay, async send, MDB alignment, JMS resource definition Fixes, clarifications

Page 7: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public7

JMS 2Old API

@Resource(lookup = "java:global/jms/demoConnectionFactory")ConnectionFactory connectionFactory;@Resource(lookup = "java:global/jms/demoQueue")Queue demoQueue;

public void sendMessage(String payload) { try { Connection connection = connectionFactory.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(demoQueue); TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } finally { connection.close(); } } catch (JMSException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); }}

Page 8: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public8

JMS 2Simplified API

@Injectprivate JMSContext context;

@Resource(mappedName = "jms/inboundQueue")private Queue inboundQueue;

public void sendMessage (String payload) { context.createProducer() .setPriority(HIGH_PRIORITY) .setDisableMessageID(true) .setDisableMessageTimestamp(true) .send(inboundQueue, payload);}

Page 9: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public9

JMS 2/Java EE 7JMS Resource Definition

@JMSConnectionFactoryDefinition( name="java:global/jms/demoConnectionFactory", interfaceName= "javax.jms.ConnectionFactory", description="ConnectionFactory to use in demonstration")

@JMSDestinationDefinition( name = "java:global/jms/demoQueue", description = "Queue to use in demonstration", interfaceName = "javax.jms.Queue", destinationName="demoQueue")

Page 10: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public10

JMS 2/EJB 3.2More Standard MDB Properties

@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty( propertyName = "destinationLookup", propertyValue = "jms/OrderQueue"), @ActivationConfigProperty( propertyName = "connectionFactoryLookup", propertyValue = "jms/MyConnectionFactory")})public class OrderListener implements MessageListener { ... public void onMessage(Message message) { ... } ...}

Page 11: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public11

Java API for WebSocket

Higher level API for WebSocket Both client and server-side (Java SE and Java EE) Both declarative and programmatic

Page 12: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public12

Java API for WebSocketConnection Life Cycle

@ServerEndpoint(”/chat”)public class ChatServer { Set<Session> peers = ...

@OnOpen public void onOpen(Session peer) { peers.add(peer); }

@OnClose public void onClose(Session peer) { peers.remove(peer); } ...

Page 13: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public13

Java API for WebSocketWebSocket Communication

... @OnMessage public void message(String message, Session client) throws IOException { for (Session session : peers) { if (!session.equals(client)) { session.getRemote().sendObject(message); } } }}

Page 14: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public14

Java API for JSON Processing

API to parse, generate, transform, query JSON Object Model and Streaming API -- similar to DOM and StAX Binding JSON to Java objects forthcoming

Page 15: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public15

Java API for JSON ProcessingWriting JSON (Object Model API)

[

{

"type": "home”,

"number": "212 555-1234"

},

{

"type": "fax”,

"number": "646 555-4567"

}

]

JsonArray value =

Json.createArrayBuilder()

.add(Json.createObjectBuilder()

.add("type", "home")

.add("number", "212 555-1234")

)

.add(Json.createObjectBuilder()

.add("type", "fax")

.add("number", "646 555-4567")

)

.build();

Page 16: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public16

Java API for JSON ProcessingReading JSON (Streaming API)

{

"firstName": "John", "lastName": "Smith", "age": 25,

"phoneNumber": [

{ "type": "home", "number": "212 555-1234" },

{ "type": "fax", "number": "646 555-4567" }

]

}

Event event = parser.next(); // START_OBJECT

event = parser.next(); // KEY_NAME

event = parser.next(); // VALUE_STRING

String name = parser.getString(); // "John”

Page 17: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public17

JAX-RS 2

Client API Message Filters & Entity Interceptors Asynchronous Processing – Server & Client Hypermedia Support Content negotiation

Page 18: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public18

JAX-RS 2Client API

// Get instance of ClientClient client = ClientBuilder.newClient(); // Get customer name for the shipped productsString name = client.target(“../orders/{orderId}/customer”) .pathParam(”orderId", ”10”) .queryParam(”shipped", ”true”) .request() .get(String.class);

Page 19: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public19

JAX-RS 2Asynchronous Processing

@Stateless @Path("/async/longRunning")public class MyResource {

@GET @Asynchronous public void longRunningOp(@Suspended AsyncResponse ar) { final String result = executeLongRunningOperation(); ar.resume(result); }}

Future<String> handle = target.request().async().get(String.class); // After waiting for too long...if (!handle.isDone()) handle.cancel(true);

Page 20: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public20

JPA 2.1

Schema generation Stored procedures Entity Graphs Entity converters Unsynchronized persistence contexts Fixes and enhancements

Page 21: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public21

JPA 2.1

javax.persistence.schema-generation.[database|scripts].action

– “none”, “create”, “drop-and-create”, “drop”

javax.persistence.schema-generation.scripts.[create|drop]-target

javax.persistence.schema-generation.[create|drop]-script-source

javax.persistence.sql-load-script-source javax.persistence.schema-generation.[create|drop]-source

– “metadata”, “script”, “metadata-then-script”, “script-then-metadata”

Schema Generation Properties

Page 22: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public22

JPA 2.1Entity Graphs

@NamedEntityGraph( name="previewEmail", attributeNodes={ @NamedAttributeNode("subject"), @NamedAttributeNode("sender"), @NamedAttributeNode("body")})@Entitypublic class EmailMessage { ... }

EntityGraph<EmailMessage> preview = em.getEntityGraph("previewEmail");List<EmailMessage> messages = em.createNamedQuery("findAllEmailMessages") .setParameter("mailbox", "inbox") .setParameter("user", user) .setHint("javax.persistence.fetchgraph", preview) .getResultList();

Page 23: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public23

JTA 1.2

Declarative transactions outside EJB Transaction scope - @TransactionScoped

Page 24: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public24

JTA 1.2@Transactional Annotation

@Inherited@InterceptorBinding@Target({TYPE, METHOD}) @Retention(RUNTIME)public @interface Transactional { TxType value() default TxType.REQUIRED; Class[] rollbackOn() default {}; Class[] dontRollbackOn() default {};}

@Transactional(rollbackOn={SQLException.class}, dontRollbackOn={SQLWarning.class})public class UserService {...}

Page 25: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public25

JSF 2.2

HTML5 Support @FlowScoped @ViewScoped for CDI Managed beans deprecated/CDI alignment Stateless views Resource library contracts File upload component View actions Fixes and enhancements

Page 26: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public26

JSF 2.2Pass-Through HTML 5 Components

<html> ... <input type=“color” jsf:value=“#{colorBean.color2}” /> <input type=“date” jsf:value=“#{calendarBean.date1}” /> ...</html>

Page 27: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public27

JSF 2.2Faces Flow

@Named@FlowScoped(id="flow-a")public class FlowABean implements Serializable { public String getName() { return "FlowABean"; } public String getReturnValue() { return "/return1"; } @Produces public Flow getFlow(FlowBuilder builder) { builder.startNode("router1"); builder.flowReturn("success").fromOutcome("/complete"); builder.flowReturn("errorOccurred").fromOutcome("error"); builder.switchNode("router1") .navigationCase().condition("#{facesFlowScope.customerId == null}") .fromOutcome("create-customer") .defaultOutcome("view-customer"); builder.viewNode("create-customer"); builder.viewNode("maintain-customer-record"); builder.methodCall("upgrade-customer") .method("#{maintainCustomerBean.upgradeCustomer}").defaultOutcome("view-customer"); builder.initializer("#{maintainCustomerBean.initializeFlow}"); builder.finalizer("#{maintainCustomerBean.cleanUpFlow}"); return builder.getFlow(); }}

Page 28: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public28

Batch Applications for the Java Platform

API for robust batch processing targeted to Java EE, Java SE

Page 29: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public29

Batch Applications for the Java PlatformStep Example

<step id=”sendStatements”> <chunk reader=”accountReader” processor=”accountProcessor” writer=”emailWriter” item-count=”10” /></step>

@Named(“accountReader")...implements ItemReader... {public Account readItem() { // read account using JPA

@Named(“accountProcessor")...implements ItemProcessor... {Public Statement processItems(Account account) { // read Account, return Statement

@Named(“emailWriter")...implements ItemWriter... {public void writeItems(List<Statements> statements) { // use JavaMail to send email

Page 30: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public30

Bean Validation 1.1

Method constraints Bean Validation artifacts injectable Fixes, clarifications and enhancements

Page 31: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public31

Bean Validation 1.1Method Level Constraints

public void placeOrder( @NotNull String productName, @NotNull @Max(“10”) Integer quantity, @Customer String customer) { . . .}

@Futurepublic Date getAppointment() { . . .}

Page 32: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public32

Concurrency Utilities for Java EE

Provides simple, safe API for concurrency in Java EE Builds on Java SE concurrency

– java.util.concurrent.ExecutorService

Relatively low-level API Important enabler for Java EE ecosystem

Page 33: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public33

Concurrency Utilities for Java EEManaged Task Executor

public class TestServlet extends HTTPServlet { @Resource(name=“concurrent/MyExecutorService”) ManagedExecutorService executor;

Future future = executor.submit(new MyTask());

class MyTask implements Runnable { public void run() { ... // Task logic } }}

Page 34: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public34

Others

Servlet 3.1: Non-blocking I/O, upgrade to WebSocket, security… CDI 1.1: Global enablement, @AroundConstruct, @Vetoed… EL 3.0: Lambda expressions, collections, operators, standalone API… EJB 3.2: Truncating CMP/BMP…

Page 35: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public35

Java EE 8 Community Survey

https://java.net/downloads/javaee-spec/JavaEE8_Community_Survey_Results.pdf

https://blogs.oracle.com/ldemichiel/entry/results_from_the_java_ee

Page 36: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public36

Java EE 8 Possibilities

Web Standards/HTML5 Alignment– HTTP2, SSE, JSON-B, action-oriented web framework

Cloud– Simple security providers, multitenancy, REST management/monitoring

CDI Alignment– CDI 2, EJB services outside EJB, security interceptors, EJB pruning

Enterprise– JCache, Configuration, JMS

Java SE 8 alignment

Page 37: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public37

Try it Out!

http://dlc.sun.com.edgesuite.net/glassfish/4.0.1/promoted/

Page 38: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public38

Java EE 7 Platforms

GlassFish

Java EE 7

Java EE 6

TomEE

Page 39: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public39

Learning More

Java EE Tutorials– http://docs.oracle.com/javaee/7/tutorial/doc/home.htm

Digging Deeper– http://docs.oracle.com/javaee/7/firstcup/doc/home.htm

– https://glassfish.java.net/hol/

– https://java.net/projects/cargotracker/

Java EE 7 Transparent Expert Groups– http://javaee-spec.java.net

Java EE 7 Reference Implementation– http://glassfish.org

The Aquarium– http://blogs.oracle.com/theaquarium

Page 40: JavaEE.Next(): Java EE 7, 8, and Beyond

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Public40