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

Java EE 7 in practise - OTN Hyderabad 2014

Embed Size (px)

DESCRIPTION

Java EE 7 in practise - OTN Hyderabad 2014

Citation preview

Page 1: Java EE 7 in practise - OTN Hyderabad 2014

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

Page 2: Java EE 7 in practise - OTN Hyderabad 2014

Java EE 7 in PracticeBluePrints RebornJagadish RamuApplication Server [email protected]

Page 3: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 3

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: Java EE 7 in practise - OTN Hyderabad 2014

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

Program Agenda

Java EE 7

Cargo Tracker (Blueprints)

The API Changes + The Code!

Looking Ahead…

Page 5: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 5

Java EE Past, Present and Future

J2EE 1.3

CMP,ConnectorArchitecture

J2EE 1.4

Web Services Mgmt, Deployment,Connectors Inbound

Java EE 5

Ease of Development,EJB 3, JPA, JSF, JAXB, JAX-WS, StAX, SAAJ

Java EE 6

Profiles,CDI,Validation,Pruning,Extensibility,Ease of Dev,JAX-RS

Web Profile

EJB 3.1 LiteServlet 3,

Java EE 7

JMS 2, Batch, TX, Concurrency, InterceptorWebSocketJSON

Web Profile

JAX-RS 2

J2EE 1.2

Servlet, JSP, EJB, JMS, RMI

Page 6: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 6

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

PortableExtensionsPortable

Extensions

JSF 2.2JSF 2.2 JAX-RS 2.0

JAX-RS 2.0

JMS 2.0JMS 2.0JPA 2.1JPA 2.1

EL 3.0EL 3.0

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(JSR 236)

Concurrency Utilities(JSR 236)

Batch Applications(JSR 352)

Batch Applications(JSR 352)

Java API for JSON(JSR 353)

Java API for JSON(JSR 353)

Java API for WebSocket(JSR 356)

Java API for WebSocket(JSR 356)

Page 7: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 7

Java EE in Action

http://cargotracker.java.net

The Blueprints

Page 8: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 9

Domain Driven Design – Java EE Technologies/API

Value Objects

Entities

Application

Infrastructure

Interface

Repository

JSF

EJB

JPA Entity Manager

Web SocketJAX-RS

JPA Entities

JPA Embeddable

Batch

JPA EJB ClientJAX-RS ClientJMS

CDI

Page 9: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 10

Cargo Tracker – The BlueprintsJava EE features used in Cargo Tracker

Java EE API Features

JSF Facelets, templates, view parameters, view actions, message bundles, CDI compatible view scope, HTML 5 pass-though attributes, HTML 5 pass-though elements

CDI Basic injection, scopes, named beans, qualifiers, events, observers, default enablement,

EJB Transactions, stateless session bean, message driven bean, startup singleton, CRON style scheduling, application exceptions, XML deployment descriptors, portable activation configuration

JPA Generated ID, basic mapping, embeddables, many-to-one, one-to-many, enumerations, temporal types, named queries, managed persistence context, portable data source definition, schema generation

JAX-RS REST endpoint, MIME types, client API, JSON processing, content-type negotiation

WebSocket Server-side endpoint, sending messages to remote endpoints, EJB integration

JSON-P Writing JSON using Streaming API

Bean Validation

Basic validation annotations, method level validation for REST endpoints, method level validation for local EJB application services

JMS JMS 2 simplified API message send, portable JMS resource definition

Java Batch Job operator, job XML, job properties, job context, job listener, skip listener, reader, writer, skippable exceptions, checkpointing, chunking

JTA 1.2 @Transactional interceptor

Page 10: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 11

Cargo Tracker - Demo

Page 11: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 12

JMS 2

API modernization– Dependency injection– Fluent APIs– Intelligent defaults– Unchecked exceptions

New features– Delivery delay, async send

Platform alignment – MDB activation properties, JMS resource definition

Java EE 7

Page 12: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 13

JMS 2 (Contd.)

@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);

}

}

Old API

Page 13: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 14

JMS 2 (Contd.)

@Inject

private JMSContext context;

@Resource(lookup = "jms/demoQueue")

private Queue demoQueue;

public void sendMessage (String payload) {

context.createProducer().send(demoQueue, payload);

}

Simplified API

Page 14: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 16

JMS 2 (Contd.)

@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")

Creating Resources

Page 15: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 17

Batch Processing

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

– Operator, repository, job, step, reader-processor-writer pattern Common features

– Chunking, check-pointing, transactions, retries, skippable-exceptions, workflow, parallelism

Page 16: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 18

Batch Processing (Contd.)API for Robust Batch Processing

Page 17: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 19

Batch Processing (Contd.)Step 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 18: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 20

Batch Jobs - Demo

Page 19: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 21

Bean Validation 1.1

Method constraints– Very useful for JAX-RS and WebSocket– Built-in and Custom Constraints

CDI Alignment– All Bean Validation artifacts now injection capable

EL 3 integration– More expressive validation messages

Java EE 7

Page 20: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 22

Bean Validation 1.1 (Contd.)

public class Doctor {

public Doctor (@NotNull String name) { ... }

public void payFee(

@NotNull @Digits(integer=6, fraction=2) BigDecimal fee,

@NotNull @ValidCurrency String currencyType) {

}

@Future public Date getAppointment() {

}

}

Method Level Constraints

Page 21: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 26

JAX-RS 2

Client API Message Filters & Entity Interceptors

– Servlet filters and CDI interceptors for JAX-RS– Common configuration

Asynchronous Processing – Server & Client Content negotiation Bean Validation 1.1 integration

Page 22: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 27

JAX-RS 2 (Contd.)

// Get instance of ClientClient client = ClientBuilder.newClient(); // Build the URI, build the request, and get responseString name = client.target(“http://example.com/orders/{orderId}/customer”) .resolveTemplate(”orderId", ”10”) .queryParam(”shipped", ”true”)

.request() .get(String.class);

// http://example.com/orders/10/customer?shipped=true

Client API

Page 23: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 31

Java API for JSON Processing Reading JSON (Streaming API)

{

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

"phoneNumber": [

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

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

]

}

JsonParser parser = Json.createParser(…);

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

event = parser.next(); // KEY_NAME - “firstname”

event = parser.next(); // VALUE_STRING - “John”

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

Page 24: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 32

Java API for JSON Processing Writing JSON (Object Model API)

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();

[

{

"type": "home”,

"number": "212 555-1234"

},

{

"type": "fax”,

"number": "646 555-4567"

}

]

Page 25: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 35

Concurrency Utilities for Java EE

Managed 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 26: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 36

Yet More…

JPA 2.1– Schema Generation, Entity Graphs

JTA 1.2– @Transactional, @TransactionScoped

EL 3.0– Standalone API, lambda expressions, collections, operators

Servlet 3.1– Non-blocking I/O, upgrade to WebSocket, security

CDI 1.1– Global enablement, @AroundConstruct, @Vetoed

EJB 3.2– Truncating CMP/BMP

Page 27: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 37

Java EE 8

JSON-B JCache CDI 2 More CDI/EJB alignment Security Action-oriented Web framework/HTML 5 alignment Cloud, PaaS, multitenancy/SaaS Configuration, deployment, management, monitoring? Further pruning?

Page 28: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 38

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 29: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 39

Try it Out!

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

Page 30: Java EE 7 in practise - OTN Hyderabad 2014

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Public 40

Resources

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 31: Java EE 7 in practise - OTN Hyderabad 2014

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