Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

Presented at FLISOL 2013 and JUG meetings in Brazil

Bruno Borges

April 27, 2013
Tweet

More Decks by Bruno Borges

Other Decks in Technology

Transcript

  1. 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
  2. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 3 Bruno Borges • Oracle Product Manager / Evangelist • Desenvolvedor, Gamer • Entusiasta em Java Embedded e JavaFX • Twitter: @brunoborges
  3. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 4Copyright © 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í
  4. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 5 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... :-)
  5. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 6 Java EE 7: quais as novidades?  Web Profile updated to include – JAX-RS – WebSocket – JSON-P – EJB 3.2 Lite  Outras APIs
  6. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 7 Construindo aplicações HTML5  WebSocket 1.0  JAX-RS 2.0  JavaServer Faces 2.2  JSON-P API
  7. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 8 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
  8. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 9 WebSockets 1.0 import javax.websocket.*; import javax.websocket.server.*; @ServerEndpoint(“/hello”) public class HelloBean { @OnMessage public String sayHello(String name) { return “Hello “ + name; } }
  9. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 10 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)); } }
  10. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

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

    Insert Information Protection Policy Classification from Slide 13 12 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
  12. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 13 DEMO Maven Archetype Java EE 7 GlassFish Embedded
  13. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 14 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
  14. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 15 JAX-RS 2.0 - Client // Get instance of Client Client client = ClientFactory.getClient(); // Get customer name for the shipped products String name = client.target(“http://.../orders/{orderId}/customer”) .resolveTemplate(“orderId”, “10”) .queryParam(“shipped”, “true)” .request() .get(String.class);
  15. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 16 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); }}); } }
  16. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 17 JavaServer Faces 2.0  Flow Faces  HTML5 Friendly Markup  Cross-site Request Forgery Protection  Loading Facelets via ResourceHandler  Componente de File Upload  Multi-templating
  17. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 18 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, ...
  18. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 19 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();
  19. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 20 JMS para Mensageria
  20. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 21 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
  21. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 22 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
  22. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 23 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;
  23. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 24 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”)
  24. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 25 Message Driven Beans para JMS 2.0 @MessageDriven( mappedName = “jms/myQueue”, activationConfig = { @ActivationConfigProperty( propertyName = “destinationLookup”, propertyValue = “jms/myQueue”), @ActivationConfigProperty( propertyName = “connectionFactoryLookup”, propertyValue = “jms/myCF”) })
  25. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

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

    Insert Information Protection Policy Classification from Slide 13 27 Bean Validation 1.1 public void placeOrder( @NotNull String productName, @NotNull @Max(“10”) Integer quantity, @Customer String customer) { //. . . } @Future public Date getAppointment() { //. . . }
  27. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 28 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>
  28. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

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

    Insert Information Protection Policy Classification from Slide 13 30 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
  30. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 31 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
  31. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 33 OBRIGADO!
  32. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 34 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.
  33. Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

    Insert Information Protection Policy Classification from Slide 13 35