as novidades do java ee 7: do html5 ao jms 2.0

33
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 2 As novidades do Java EE 7: do HTML5 ao JMS 2.0 Bruno Borges Oracle Product Manager Java Evangelist Insert Picture Here

Upload: bruno-borges

Post on 11-Nov-2014

1.207 views

Category:

Technology


1 download

DESCRIPTION

As novidades do Java EE 7: do HTML5 ao JMS 2.0

TRANSCRIPT

Page 1: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 132

As novidades do Java EE 7:do HTML5 ao JMS 2.0Bruno BorgesOracle Product ManagerJava Evangelist

Insert Picture Here

Page 2: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 133

Bruno Borges

● Oracle Product Manager / Evangelist

● Desenvolvedor, Gamer

● Entusiasta em Java Embedded e JavaFX

● Twitter: @brunoborges

Page 3: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 134Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16

Agenda Java EE 7: quais as novidades?

Construindo aplicações HTML5– WebSockets 1.0

– JAX-RS 2.0

– JavaServer Faces 2.2

– JSON API 1.0

Mensageria com JMS 2.0

Códigos de exemplo de Java EE 7

O que vem por aí

Page 4: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 135

Java EE 7: quais as novidades?

Servlet 3.1 Java API for JSON Processing 1.0 Bean Validation 1.1 Batch Applications API 1.0 Java Persistence API 2.1 Concurrency Utilities for Java EE 1.0 E muito mais... :-)

Page 5: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 136

Java EE 7: quais as novidades?

Web Profile updated to include– JAX-RS

– WebSocket

– JSON-P

– EJB 3.2 Lite

Outras APIs

Page 6: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 137

Construindo aplicações HTML5

WebSocket 1.0 JAX-RS 2.0 JavaServer Faces 2.2 JSON-P API

Page 7: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 138

WebSockets 1.0

API para definir WebSockets, tanto Client como Server– Annotation-driven (@ServerEndpoint)

– Interface-driven (Endpoint)

– Client (@ClientEndpoint)

SPI para data frames– Negociação handshake na abertura do WebSocket

Integração com o Java EE Web container

Page 8: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 139

WebSockets 1.0

import javax.websocket.*;import javax.websocket.server.*;

@ServerEndpoint(“/hello”)public class HelloBean {

    @OnMessage    public String sayHello(String name) {        return “Hello “ + name;    }}

Page 9: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1310

WebSockets 1.0

@ServerEndpoint(“/chat”)public class ChatBean {

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

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

    @OnMessage    public void message(String msg, Session client) {        peers.forEach(p ­> p.getRemote().sendMessage(msg));    }}

Page 10: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1311

DEMO

WebSockets

Page 11: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1312

Maven Archetype para o Java EE 7

Maven Archetypes para Java EE 7– http://mojo.codehaus.org

Maven Archetype com o Embedded GlassFish configurado– http://github.com/brunoborges/javaee7-archetype

Só precisa... – $ mvn package embedded-glassfish:run

Page 12: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1313

DEMO

Maven ArchetypeJava EE 7GlassFish Embedded

Page 13: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1314

JAX-RS 2.0

Client API Message Filters & Entity Interceptors Asynchronous Processing – Server & Client Suporte Hypermedia Common Configuration

– Compartilhar configuração comum entre diversos serviços REST

Page 14: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1315

JAX-RS 2.0 - Client

// Get instance of ClientClient client = ClientFactory.getClient();

// Get customer name for the shipped productsString name = client.target(“http://.../orders/{orderId}/customer”)                    .resolveTemplate(“orderId”, “10”)                    .queryParam(“shipped”, “true)”                    .request()                    .get(String.class);

Page 15: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1316

JAX-RS 2.0 - Server

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

@GET public void longRunningOp(@Suspended AsyncResponse ar) { ar.setTimeoutHandler(new MyTimoutHandler()); ar.setTimeout(15, SECONDS); Executors.newSingleThreadExecutor().submit(new Runnable() { public void run() { ... ar.resume(result); }}); }

}

Page 16: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1317

JavaServer Faces 2.0

Flow Faces HTML5 Friendly Markup Cross-site Request Forgery Protection Loading Facelets via ResourceHandler Componente de File Upload Multi-templating

Page 17: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1318

JSON API 1.0

JsonParser– Processa JSON em modo “streaming”

– Similar ao XMLStreamReader do StaX

Como criar– Json.createParser(...)

– Json.createParserFactory().createParser(...)

Eventos do processador– START_ARRAY, END_ARRAY, START_OBJECT, END_OBJECT, ...

Page 18: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1319

JSON API 1.0

"phoneNumber": [ { "type": "home", "number": ”408-123-4567” }, { "type": ”work", "number": ”408-987-6543” }]

JsonGenerator jg = Json.createGenerator(...);jg. .beginArray("phoneNumber") .beginObject() .add("type", "home") .add("number", "408-123-4567") .endObject() .beginObject() .add("type", ”work") .add("number", "408-987-6543") .endObject() .endArray();jg.close();

Page 19: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1320

JMS para Mensageria

Page 20: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1321

Java Message Service API 2.0

Simplificação da JMS API 1.1 sem quebrar compatibilidade Nova API requer menos objetos

– JMSContext, JMSProducer...

No Java EE, permite que JMSContext seja injetado e gerenciado pelo container, usando CDI

Objetos JMS implementam AutoCloseable Envio Async de mensagens

Page 21: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1322

Java Message Service API 2.0

JMSContext Encapsula Connection e Session Criado a partir de um default ConnectionFactory

– Permite especificar um ConnectionFactory também

Unchecked exceptions Suporta encadeamento de métodos, para fluid style

Page 22: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1323

Java Message Service API 2.0

@Resource(lookupName = “java:comp/defaultJMSConnectionFactory”)ConnectionFactory myJMScf;

@Resource(lookupName = “jms/inboud”)private Queue inboundQueue;

@Inject@JMSConnectionFactory(“jms/myCF”)private JMSContext context;

Page 23: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1324

Java Message Service API 2.0

@JMSConnectionFactoryDefinition( name=”java:global/jms/demoCF” className = “javax.jms.ConnectionFactory”)@JMSDestinationDefinition( name = “java:global/jms/inboudQueue” className = “javax.jms.Queue” destinationName = “inboundQueue”)

Page 24: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1325

Message Driven Beans para JMS 2.0

@MessageDriven(mappedName = “jms/myQueue”, activationConfig = { @ActivationConfigProperty( propertyName = “destinationLookup”, propertyValue = “jms/myQueue”), @ActivationConfigProperty( propertyName = “connectionFactoryLookup”, propertyValue = “jms/myCF”)})

Page 25: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1326

Outros exemplos

Page 26: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1327

Bean Validation 1.1

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

@Futurepublic Date getAppointment() { //. . .}

Page 27: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1328

Batch API 1.0<job id=“myJob”> <step id=“init”> <chunk reader=“R” writer=W” processor=“P” /> <next on=“initialized” to=“process”/> <fail on=“initError”/> </step> <step id=“process”> <batchlet ref=“ProcessAndEmail”/> <end on=”success”/> <fail on=”*” exit-status=“FAILURE”/> </step></job>

Page 28: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1329

Page 29: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1330

GlassFish 4.0, NetBeans, e Java EE 7

Java EE 7 Expert Group Project– http://javaee-spec.java.net

GlassFish 4.0 - Java EE 7 Reference Implementation– http://www.glassfish.org

Adopt a JSR– http://glassfish.org/adoptajsr

NetBeans e Java EE 7– http://wiki.netbeans.org/JavaEE7

Page 30: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1331

GlassFish 4.0, NetBeans, e Java EE 7

JUGs participando ativamente Promovendo as JSRs

– Para a comunidade Java

– Revendo specs

– Testando betas e códigos de exemplo

– Examplos, docs, bugs

– Blogging, palestrando, reuniões de JUG

Page 31: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1333

OBRIGADO!

Page 32: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1334

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 33: As novidades do Java EE 7: do HTML5 ao JMS 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1335