SlideShare a Scribd company logo
Criando uma aplicação
HTML5 com Java EE 7 e
WebSockets
Bruno Borges
Principal Product Manager
Java Evangelist
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.3
• Java Evangelist
• Orale Product Manager
• Entusiasta JavaFX e IoT
• Onde me encontrar
• @brunoborges
• plus.google.com/+BrunoBorges
Bruno Borges
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.4
Ascenção do Javascript
• O debate cliente ‘leve’ vs cliente ‘pesado’ é antigo...
• Frameworks web server-side mandaram por um tempo (Struts, Spring
MVC, JSF)
• Ajax foi uma mudança suave para o client-side (GWT, Vaadin)
• Rich clients estão voltando voltaram, graças ao Javascript/HTML5
• Motores Javascript melhoraram muito (V8, SpiderMonkey, Nashorn)
• Melhores ferramentas (jQuery, MV* frameworks, Chrome, Firefox, JavaFX)
• Melhores padrões (CSS3, HTML5, WebSockets, Web Components)
Clientes ricos HTML5
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.5
Arquitetura Rich Client
• Similar a arquiteturas cliente/servidor
• Cliente responsável pela UI, input, validacao, lógica e estado
• Server responsável pela lógica de negócio, modelo de domínio, persistência
• Web/HTTP é a cola que conecta client e server
• Protocolos de comunicacao comuns
• REST na maioria dos casos
• WebSocket quando precisa de comunicacao full-duplex
• Ferramentas Javascript suportam REST muito bem, mas ainda não WebSocket
• O formato comum (talvez ideal?) de troca de dados é JSON
• Java EE é uma ótima plataforma server-side para esta arquitetura
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.6
Java EE + Javascript
Plataforma server-side para suportar apps ricas HTML5/Javascript
Servlet
EJB 3 CDI
BeanValidation
JavaScript/HTML5
JAX-RS WebSockets JSON-P JAXB
JPA JMS JTA JCA
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.7
JAX-RS
• API de desenvolvimento REST para Java
• Servidor e Client
• Orientada a Annotations, declarativa
• @Path, @GET, @POST, @PUT, @DELETE, @PathParam, @QueryPara
m, @Produces, @Consumes
• Plugável e extensível
• Providers, filters, interceptors
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.8
JAX-RS
@Path("/atm/{cardId}")
public class AtmService {
@GET
@Path("/balance")
@Produces("text/plain")
public String balance(
@PathParam("cardId") String card,
@QueryParam("pin") String pin) {
return Double.toString(getBalance(card, pin));
}
Exemplo 1
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.9
JAX-RS
@POST
@Path("/withdrawal")
@Consumes("text/plain")
@Produces("application/json")
public Money withdraw(
@PathParam("card") String card,
@QueryParam("pin") String pin,
String amount) {
return getMoney(card, pin, amount);
}
}
Exemplo 2
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10
Java API for WebSockets
JSR 356
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.11
Java API for WebSockets
• Protocolo HTTP é half-duplex
• Gambiarras
• Polling
• Long polling
• Streaming
• WebSocket resolve o problema de uma vez por todas
• Full-duplex
JSR 356
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12
Java API for WebSockets
• API declarativa de alto nivel para WebSockets
• Client e server-side
• Pequena e simples, mas completa
• @ServerEndpoint, @OnOpen, @OnClose, @OnMessage, @OnError, Ses
sion, Remote
• Plugável e extensível
• Encoders, decoders, sub-protocols
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13
Java API for WebSockets
@ServerEndpoint("/chat")
public class ChatBean {
Set<Session> peers = Collections.synchronizedSet(…);
@OnOpen
public void onOpen(Session peer) {
peers.add(peer);
}
@OnClose
public void onClose(Session peer) {
peers.remove(peer);
}
Exemplo 1
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.14
Java API for WebSockets
@OnMessage
public void message(String message, Session client) {
peers.forEach(
p -> p.getRemote().sendObject(message)
);
}
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.15
Javascript Movers and Shakers
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16
Projeto Avatar
• Javascript framework da Oracle
• Javascript no client e no server-side
• Nashorn/JDK8
• Utiliza algumas capacidades do Java EE
• Roda no GlassFish, e em breve no WebLogic também
• Suporte já integrado para REST, WebSocket, Server-Sent Events
(SSE)
• Suporte a PhoneGap
• Versão 1.0 já disponível. Bom momento para participar!
avatar.java.net
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17
Projetos no NetBeans
• Twitter Bootstrap
• HTML5 Boilerplate
• Initializr
• AngularJS
• Mobile Boilerplate
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.18
Demo
•github.com/brunoborges/javaee-javascript
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.19
Conclusão
• Cientes JavaScript/HTML5 conquistando desenvolvedores
• Comunicacao entre cliente e servidor em JSON via REST ou WebSocket
• Java EE funciona muito bem como um backend para clientes ricos
Javascript, especialmente com JAX-RS e a Java API para WebSockets, e
JSON-P
• JavaScript framework da Oracle – Projeto Avatar
• Você opde usar o código de demonstracão para comecar a explorar estas
idéias
• E o mais importante, divirta-se programando! :-)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.20
• glassfish.org
• Java EE 7
• Suporte a JDK 8
• Projeto Avatar
GlassFish Nightly Builds
GlassFish 4.0.1
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.21
Para saber mais
• Java EE Tutorials
• http://docs.oracle.com/javaee/7/tutorial/doc/home.htm
• Outras páginas para iniciar os estudos
• 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
• The Aquarium (blog Java EE da Oracle)
• http://blogs.oracle.com/theaquarium
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.23
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.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.24
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.25
Ad

Recommended

PDF
Aplicações HTML5 com Java EE 7 e NetBeans
Bruno Borges
 
PDF
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Arun Gupta
 
PPTX
Move from J2EE to Java EE
Hirofumi Iwasaki
 
PDF
What's coming in Java EE 8
David Delabassee
 
PDF
Best Way to Write SQL in Java
Gerger
 
PDF
How Scala, Wicket, and Java EE Can Improve Web Development
Bruno Borges
 
PPT
Have You Seen Java EE Lately?
Reza Rahman
 
PDF
Java EE Revisits GoF Design Patterns
Murat Yener
 
PDF
Java EE 7 overview
Masoud Kalali
 
PDF
Java EE 7 - Overview and Status
Java Usergroup Berlin-Brandenburg
 
PPT
What's New in WebLogic 12.1.3 and Beyond
Oracle
 
PDF
CON5898 What Servlet 4.0 Means To You
Edward Burns
 
PDF
Websocket 1.0
Arun Gupta
 
PDF
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Arun Gupta
 
PDF
Java Summit Chennai: JAX-RS 2.0
Arun Gupta
 
PDF
Finally, EE Security API JSR 375
Alex Kosowski
 
PDF
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
Arun Gupta
 
PDF
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit'
C2B2 Consulting
 
PDF
Java EE 7 and HTML5: Developing for the Cloud
Arun Gupta
 
PDF
Java EE 8: On the Horizon
Josh Juneau
 
PDF
'New JMS features in GlassFish 4.0' by Nigel Deakin
C2B2 Consulting
 
PDF
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
David Delabassee
 
PDF
Building Java Desktop Apps with JavaFX 8 and Java EE 7
Bruno Borges
 
PDF
GIDS 2012: Java Message Service 2.0
Arun Gupta
 
PDF
JAX-RS 2.0: What’s New in JSR 339 ?
Arun Gupta
 
PDF
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Consuming Java EE in Desktop, Web, and Mobile Frontends
Geertjan Wielenga
 
PDF
As novidades do Java EE 7: do HTML5 ao JMS 2.0
Bruno Borges
 
PDF
Java EE 7 - Novidades e Mudanças
Bruno Borges
 
PDF
What's new in Java EE 7? From HTML5 to JMS 2.0
Bruno Borges
 

More Related Content

What's hot (17)

PDF
Java EE 7 overview
Masoud Kalali
 
PDF
Java EE 7 - Overview and Status
Java Usergroup Berlin-Brandenburg
 
PPT
What's New in WebLogic 12.1.3 and Beyond
Oracle
 
PDF
CON5898 What Servlet 4.0 Means To You
Edward Burns
 
PDF
Websocket 1.0
Arun Gupta
 
PDF
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Arun Gupta
 
PDF
Java Summit Chennai: JAX-RS 2.0
Arun Gupta
 
PDF
Finally, EE Security API JSR 375
Alex Kosowski
 
PDF
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
Arun Gupta
 
PDF
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit'
C2B2 Consulting
 
PDF
Java EE 7 and HTML5: Developing for the Cloud
Arun Gupta
 
PDF
Java EE 8: On the Horizon
Josh Juneau
 
PDF
'New JMS features in GlassFish 4.0' by Nigel Deakin
C2B2 Consulting
 
PDF
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
David Delabassee
 
PDF
Building Java Desktop Apps with JavaFX 8 and Java EE 7
Bruno Borges
 
PDF
GIDS 2012: Java Message Service 2.0
Arun Gupta
 
PDF
JAX-RS 2.0: What’s New in JSR 339 ?
Arun Gupta
 
Java EE 7 overview
Masoud Kalali
 
Java EE 7 - Overview and Status
Java Usergroup Berlin-Brandenburg
 
What's New in WebLogic 12.1.3 and Beyond
Oracle
 
CON5898 What Servlet 4.0 Means To You
Edward Burns
 
Websocket 1.0
Arun Gupta
 
Building HTML5 WebSocket Apps in Java at JavaOne Latin America 2012
Arun Gupta
 
Java Summit Chennai: JAX-RS 2.0
Arun Gupta
 
Finally, EE Security API JSR 375
Alex Kosowski
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
Arun Gupta
 
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit'
C2B2 Consulting
 
Java EE 7 and HTML5: Developing for the Cloud
Arun Gupta
 
Java EE 8: On the Horizon
Josh Juneau
 
'New JMS features in GlassFish 4.0' by Nigel Deakin
C2B2 Consulting
 
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
David Delabassee
 
Building Java Desktop Apps with JavaFX 8 and Java EE 7
Bruno Borges
 
GIDS 2012: Java Message Service 2.0
Arun Gupta
 
JAX-RS 2.0: What’s New in JSR 339 ?
Arun Gupta
 

Similar to Construindo aplicações com HTML5, WebSockets, e Java EE 7 (20)

PDF
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Consuming Java EE in Desktop, Web, and Mobile Frontends
Geertjan Wielenga
 
PDF
As novidades do Java EE 7: do HTML5 ao JMS 2.0
Bruno Borges
 
PDF
Java EE 7 - Novidades e Mudanças
Bruno Borges
 
PDF
What's new in Java EE 7? From HTML5 to JMS 2.0
Bruno Borges
 
PDF
Presente e Futuro: Java EE.next()
Bruno Borges
 
PDF
How to Thrive on REST/WebSocket-Based Microservices
Pavel Bucek
 
PDF
As Novidades do Java EE 8
Paulo Alberto Simoes ∴
 
PDF
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Max Andersen
 
PPTX
Java EE for the Cloud
Dmitry Kornilov
 
PDF
JAX-RS.next
Michal Gajdos
 
PDF
Java EE 7 in practise - OTN Hyderabad 2014
Jagadish Prasath
 
PDF
JAX-RS 2.0: RESTful Web Services
Arun Gupta
 
PDF
What’s new in Java SE, EE, ME, Embedded world & new Strategy
Mohamed Taman
 
PDF
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
Arun Gupta
 
PDF
JavaOne 2014 Java EE 8 Booth Slides
Edward Burns
 
PDF
WebSockets: um upgrade de comunicação no HTML5
Bruno Borges
 
PDF
Coding for Desktop and Mobile with HTML5 and Java EE 7
Petr Jiricka
 
ODP
OTN Developer Days - Java EE 6
glassfish
 
PPT
JavaScript Frameworks and Java EE – A Great Match
Reza Rahman
 
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Consuming Java EE in Desktop, Web, and Mobile Frontends
Geertjan Wielenga
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
Bruno Borges
 
Java EE 7 - Novidades e Mudanças
Bruno Borges
 
What's new in Java EE 7? From HTML5 to JMS 2.0
Bruno Borges
 
Presente e Futuro: Java EE.next()
Bruno Borges
 
How to Thrive on REST/WebSocket-Based Microservices
Pavel Bucek
 
As Novidades do Java EE 8
Paulo Alberto Simoes ∴
 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Max Andersen
 
Java EE for the Cloud
Dmitry Kornilov
 
JAX-RS.next
Michal Gajdos
 
Java EE 7 in practise - OTN Hyderabad 2014
Jagadish Prasath
 
JAX-RS 2.0: RESTful Web Services
Arun Gupta
 
What’s new in Java SE, EE, ME, Embedded world & new Strategy
Mohamed Taman
 
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
Arun Gupta
 
JavaOne 2014 Java EE 8 Booth Slides
Edward Burns
 
WebSockets: um upgrade de comunicação no HTML5
Bruno Borges
 
Coding for Desktop and Mobile with HTML5 and Java EE 7
Petr Jiricka
 
OTN Developer Days - Java EE 6
glassfish
 
JavaScript Frameworks and Java EE – A Great Match
Reza Rahman
 
Ad

More from Bruno Borges (20)

PDF
Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
PDF
[Outdated] Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
PDF
From GitHub Source to GitHub Release: Free CICD Pipelines For JavaFX Apps
Bruno Borges
 
PDF
Making Sense of Serverless Computing
Bruno Borges
 
PPTX
Visual Studio Code for Java and Spring Developers
Bruno Borges
 
PDF
Taking Spring Apps for a Spin on Microsoft Azure Cloud
Bruno Borges
 
PDF
A Look Back at Enterprise Integration Patterns and Their Use into Today's Ser...
Bruno Borges
 
PPTX
Melhore o Desenvolvimento do Time com DevOps na Nuvem
Bruno Borges
 
PPTX
Tecnologias Oracle em Docker Containers On-premise e na Nuvem
Bruno Borges
 
PPTX
Java EE Arquillian Testing with Docker & The Cloud
Bruno Borges
 
PPTX
Migrating From Applets to Java Desktop Apps in JavaFX
Bruno Borges
 
PDF
Servidores de Aplicação: Por quê ainda precisamos deles?
Bruno Borges
 
PDF
Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]
Bruno Borges
 
PDF
Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]
Bruno Borges
 
PDF
Booting Up Spring Apps on Lightweight Cloud Services [CON10258]
Bruno Borges
 
PDF
Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]
Bruno Borges
 
PDF
Running Oracle WebLogic on Docker Containers [BOF7537]
Bruno Borges
 
PPTX
Lightweight Java in the Cloud
Bruno Borges
 
PDF
Tweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFX
Bruno Borges
 
PDF
Integrando Oracle BPM com Java EE e WebSockets
Bruno Borges
 
Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
[Outdated] Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
From GitHub Source to GitHub Release: Free CICD Pipelines For JavaFX Apps
Bruno Borges
 
Making Sense of Serverless Computing
Bruno Borges
 
Visual Studio Code for Java and Spring Developers
Bruno Borges
 
Taking Spring Apps for a Spin on Microsoft Azure Cloud
Bruno Borges
 
A Look Back at Enterprise Integration Patterns and Their Use into Today's Ser...
Bruno Borges
 
Melhore o Desenvolvimento do Time com DevOps na Nuvem
Bruno Borges
 
Tecnologias Oracle em Docker Containers On-premise e na Nuvem
Bruno Borges
 
Java EE Arquillian Testing with Docker & The Cloud
Bruno Borges
 
Migrating From Applets to Java Desktop Apps in JavaFX
Bruno Borges
 
Servidores de Aplicação: Por quê ainda precisamos deles?
Bruno Borges
 
Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]
Bruno Borges
 
Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]
Bruno Borges
 
Booting Up Spring Apps on Lightweight Cloud Services [CON10258]
Bruno Borges
 
Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]
Bruno Borges
 
Running Oracle WebLogic on Docker Containers [BOF7537]
Bruno Borges
 
Lightweight Java in the Cloud
Bruno Borges
 
Tweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFX
Bruno Borges
 
Integrando Oracle BPM com Java EE e WebSockets
Bruno Borges
 
Ad

Recently uploaded (20)

PPTX
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PDF
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PPTX
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
PDF
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
PDF
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
PDF
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
PDF
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
PDF
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
PDF
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
PPTX
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
PDF
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
PDF
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
PPTX
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 

Construindo aplicações com HTML5, WebSockets, e Java EE 7

  • 1. Criando uma aplicação HTML5 com Java EE 7 e WebSockets Bruno Borges Principal Product Manager Java Evangelist
  • 2. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.3 • Java Evangelist • Orale Product Manager • Entusiasta JavaFX e IoT • Onde me encontrar • @brunoborges • plus.google.com/+BrunoBorges Bruno Borges
  • 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.4 Ascenção do Javascript • O debate cliente ‘leve’ vs cliente ‘pesado’ é antigo... • Frameworks web server-side mandaram por um tempo (Struts, Spring MVC, JSF) • Ajax foi uma mudança suave para o client-side (GWT, Vaadin) • Rich clients estão voltando voltaram, graças ao Javascript/HTML5 • Motores Javascript melhoraram muito (V8, SpiderMonkey, Nashorn) • Melhores ferramentas (jQuery, MV* frameworks, Chrome, Firefox, JavaFX) • Melhores padrões (CSS3, HTML5, WebSockets, Web Components) Clientes ricos HTML5
  • 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.5 Arquitetura Rich Client • Similar a arquiteturas cliente/servidor • Cliente responsável pela UI, input, validacao, lógica e estado • Server responsável pela lógica de negócio, modelo de domínio, persistência • Web/HTTP é a cola que conecta client e server • Protocolos de comunicacao comuns • REST na maioria dos casos • WebSocket quando precisa de comunicacao full-duplex • Ferramentas Javascript suportam REST muito bem, mas ainda não WebSocket • O formato comum (talvez ideal?) de troca de dados é JSON • Java EE é uma ótima plataforma server-side para esta arquitetura
  • 5. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.6 Java EE + Javascript Plataforma server-side para suportar apps ricas HTML5/Javascript Servlet EJB 3 CDI BeanValidation JavaScript/HTML5 JAX-RS WebSockets JSON-P JAXB JPA JMS JTA JCA
  • 6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.7 JAX-RS • API de desenvolvimento REST para Java • Servidor e Client • Orientada a Annotations, declarativa • @Path, @GET, @POST, @PUT, @DELETE, @PathParam, @QueryPara m, @Produces, @Consumes • Plugável e extensível • Providers, filters, interceptors
  • 7. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.8 JAX-RS @Path("/atm/{cardId}") public class AtmService { @GET @Path("/balance") @Produces("text/plain") public String balance( @PathParam("cardId") String card, @QueryParam("pin") String pin) { return Double.toString(getBalance(card, pin)); } Exemplo 1
  • 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.9 JAX-RS @POST @Path("/withdrawal") @Consumes("text/plain") @Produces("application/json") public Money withdraw( @PathParam("card") String card, @QueryParam("pin") String pin, String amount) { return getMoney(card, pin, amount); } } Exemplo 2
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.10 Java API for WebSockets JSR 356
  • 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.11 Java API for WebSockets • Protocolo HTTP é half-duplex • Gambiarras • Polling • Long polling • Streaming • WebSocket resolve o problema de uma vez por todas • Full-duplex JSR 356
  • 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.12 Java API for WebSockets • API declarativa de alto nivel para WebSockets • Client e server-side • Pequena e simples, mas completa • @ServerEndpoint, @OnOpen, @OnClose, @OnMessage, @OnError, Ses sion, Remote • Plugável e extensível • Encoders, decoders, sub-protocols
  • 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.13 Java API for WebSockets @ServerEndpoint("/chat") public class ChatBean { Set<Session> peers = Collections.synchronizedSet(…); @OnOpen public void onOpen(Session peer) { peers.add(peer); } @OnClose public void onClose(Session peer) { peers.remove(peer); } Exemplo 1
  • 13. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.14 Java API for WebSockets @OnMessage public void message(String message, Session client) { peers.forEach( p -> p.getRemote().sendObject(message) ); }
  • 14. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.15 Javascript Movers and Shakers
  • 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.16 Projeto Avatar • Javascript framework da Oracle • Javascript no client e no server-side • Nashorn/JDK8 • Utiliza algumas capacidades do Java EE • Roda no GlassFish, e em breve no WebLogic também • Suporte já integrado para REST, WebSocket, Server-Sent Events (SSE) • Suporte a PhoneGap • Versão 1.0 já disponível. Bom momento para participar! avatar.java.net
  • 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.17 Projetos no NetBeans • Twitter Bootstrap • HTML5 Boilerplate • Initializr • AngularJS • Mobile Boilerplate
  • 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.18 Demo •github.com/brunoborges/javaee-javascript
  • 18. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.19 Conclusão • Cientes JavaScript/HTML5 conquistando desenvolvedores • Comunicacao entre cliente e servidor em JSON via REST ou WebSocket • Java EE funciona muito bem como um backend para clientes ricos Javascript, especialmente com JAX-RS e a Java API para WebSockets, e JSON-P • JavaScript framework da Oracle – Projeto Avatar • Você opde usar o código de demonstracão para comecar a explorar estas idéias • E o mais importante, divirta-se programando! :-)
  • 19. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.20 • glassfish.org • Java EE 7 • Suporte a JDK 8 • Projeto Avatar GlassFish Nightly Builds GlassFish 4.0.1
  • 20. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.21 Para saber mais • Java EE Tutorials • http://docs.oracle.com/javaee/7/tutorial/doc/home.htm • Outras páginas para iniciar os estudos • 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 • The Aquarium (blog Java EE da Oracle) • http://blogs.oracle.com/theaquarium
  • 21. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.23 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.
  • 22. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.24
  • 23. Copyright © 2014, Oracle and/or its affiliates. All rights reserved.25

Editor's Notes

  • #5: Richer clients clearly better at some thingsHighly dynamic, interactive interfacesComplex, feature-rich UIs“Single page applications” (“Applets” )But perhaps not a panaceaHeavily form/workflow driven applicationsServer-side rendering still a better bet for performance/reliability?JavaScript/HTML development is not without it’s pains…Server-side frameworks are a strong incumbentCo-existence in the short and long term?Islands of rich client functionality within server-centric UIs?Different strokes for different folks?