0
WebSocket meets JSF 2.0
Matthias Weßendorf - Oracle
Matthias Weßendorf
• Oracle
• Apache Software Foundation
– Member
– PMC Chair (Apache MyFaces)
• Speaker
• Author
• matthi...
Agenda
• Real Time (Web)
– Introduction
– Why not Bayeux
• JavaServer Faces 2.0
– Highlights
• WebSocket
– Client API
– (J...
Agenda
• Real Time (Web)
– Introduction
– Why not Bayeux
• JavaServer Faces 2.0
– Highlights
• WebSocket
– Client API
– (J...
Real Time (Web)
Real Time (Web)
• collaborative tooling:
Push the data...!
Real Time (Web)
• Every application has a hook...
– collaborative tooling
• sharing documents
• chat
– streaming data ( f...
What the Bayeux ???
• Not a real internet standard (IETF / W3C)
• Some (Java) Servers:
– Jetty
– Tomcat
– Glassfish / Griz...
Agenda
• Real Time (Web)
– Introduction
– Why not Bayeux
• JavaServer Faces 2.0
– Highlights
• WebSocket
– Client API
– (J...
JSF 2.0 – Special Feature
• What's new ?
– Ajax integration
– Facelets is the Default VIEW
– Bookmarkable Pages
(View Para...
ProjectStage
JSF 2.0 – Special Feature
• What's better ?
• Facelets is KING !!!
– Templating
– Composite components
• Improved scoping
...
JSF 2.0 – Special Feature
• less is more...
• @nnotations for managed beans
– javax.faces.beans.*
– (optional API)
• Simpl...
JSF 2.0 – Special Feature
Pro Tip on JSF2 ...
• Do NOTuse the @nnotations from:
– javax.faces.beans.*
• Go with JSR-299/330
– @Named(„fooBean“)
– @R...
Agenda
• Real Time (Web)
– Introduction
– Why not Bayeux
• JavaServer Faces 2.0
– Highlights
• WebSocket
– Client API
– (J...
WebSocket...
... is a bi-directional AND full-duplex
communication STANDARD
for next-generation web applications
(„TCP for...
… and HTML5 APIs
WebSocket Standard
• Client API (WC3)
– (simple) JavaScript API
• Network Protocol (ITEF)
– Still under development...:
– ...
WebSocket Protocol
GET / HTTP/1.1.
Upgrade: WebSocket.
Connection: Upgrade.
Host: echo.websockets.org.
...
HTTP/1.1 101 We...
WebSocket vs COMET...
WebSocket Client API
ws = new WebSocket("ws://echo.websockets.org:80");
ws.onmessage = function(event)
{
  doSomeFancyDhtm...
WebSocket - Support
• Browser:
– Firefox 4 (in beta status)
– Chrome / Chromium
– (mobile) Safari
– Opera
• Server
– Node....
WebSocket – Jetty
public class JettyWebSocketServlet extends 
WebSocketServlet
{
private final Set<WebSocket> clients = .....
WebSocket – Resin
public class ResinWebSocketServlet extends 
GenericServlet
{
public void service(ServletRequest req, 
Se...
WebSocket – Glassfish 3.1
import java.io.IOException;
import com.sun.grizzly.websockets.*;
public class EchoWebSocketApp e...
WebSocket – Glassfish 3.1
public class BackEndWrapper extends 
WebSocketApplication
{
  @Inject Service myService;
  publi...
WebSocket – Java EE
WebSocket Support
in
JavaEE 7 ?
Agenda
• Real Time (Web)
– Introduction
– Why not Bayeux
• JavaServer Faces 2.0
– Highlights
• WebSocket
– Client API
– (J...
WebSocket meets JSF
• JSF integration points:
– Streaming data to the client
• JSF Components
– existing ones
– custom one...
JSF's Action methods
• Set up the WebSocket connection:
– global (framework level)
– Custom tag (page level)
• Use JSF lif...
WebSocket „components“
• Write WebSocket aware components:
– Let the component set up the connection
– leverage WS's onmes...
Thoughts...
• Client's send() is outside of HTTP
• current systems are HTTP based:
– JAX-RS
– JavaServer Faces
– Apache Wi...
Thank you!
@mwessendorf
BLOG:
matthiaswessendorf.wordpress.com
Upcoming SlideShare
Loading in...5
×

Jsf meets websockets

8,172

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
8,172
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
100
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "Jsf meets websockets"

  1. 1. WebSocket meets JSF 2.0 Matthias Weßendorf - Oracle
  2. 2. Matthias Weßendorf • Oracle • Apache Software Foundation – Member – PMC Chair (Apache MyFaces) • Speaker • Author • matthiaswessendorf.wordpress.com • @mwessendorf
  3. 3. Agenda • Real Time (Web) – Introduction – Why not Bayeux • JavaServer Faces 2.0 – Highlights • WebSocket – Client API – (Java) Server APIs • Mixing JSF and WebSocket – Concepts and Demos
  4. 4. Agenda • Real Time (Web) – Introduction – Why not Bayeux • JavaServer Faces 2.0 – Highlights • WebSocket – Client API – (Java) Server APIs • Mixing JSF and WebSocket – Concepts and Demos
  5. 5. Real Time (Web)
  6. 6. Real Time (Web) • collaborative tooling: Push the data...!
  7. 7. Real Time (Web) • Every application has a hook... – collaborative tooling • sharing documents • chat – streaming data ( football/soccer, ...) – trading systems ( auctions) – live reporting – monitoring ( server console) – What is YOUR use-case ?
  8. 8. What the Bayeux ??? • Not a real internet standard (IETF / W3C) • Some (Java) Servers: – Jetty – Tomcat – Glassfish / Grizzly – Weblogic (HTTP Publish-Subscribe Server) • JavaScript Client libraries: – Dojo – jQuery • Issues – No unified API (like via JCP) – ALL impls have different APIs (packages,...)
  9. 9. Agenda • Real Time (Web) – Introduction – Why not Bayeux • JavaServer Faces 2.0 – Highlights • WebSocket – Client API – (Java) Server APIs • Mixing JSF and WebSocket – Concepts and Demos
  10. 10. JSF 2.0 – Special Feature • What's new ? – Ajax integration – Facelets is the Default VIEW – Bookmarkable Pages (View Params) – Partial State Saving – ProjectStage (like Wicket / Rails) – ExceptionHandler – ...
  11. 11. ProjectStage
  12. 12. JSF 2.0 – Special Feature • What's better ? • Facelets is KING !!! – Templating – Composite components • Improved scoping – Flash – ViewScope – „MyCustomScope“ • XML-less
  13. 13. JSF 2.0 – Special Feature • less is more... • @nnotations for managed beans – javax.faces.beans.* – (optional API) • Simple navigation (w/o XML) – <h:command(Link|Button) /> – New <h:button/>, <h:link /> • More @nnotations for less XML – @FacesComponent, etc
  14. 14. JSF 2.0 – Special Feature
  15. 15. Pro Tip on JSF2 ... • Do NOTuse the @nnotations from: – javax.faces.beans.* • Go with JSR-299/330 – @Named(„fooBean“) – @RequestScoped • Even works with Spring... http://github.com/matzew/spring-cdi-bridge
  16. 16. Agenda • Real Time (Web) – Introduction – Why not Bayeux • JavaServer Faces 2.0 – Highlights • WebSocket – Client API – (Java) Server APIs • Mixing JSF and WebSocket – Concepts and Demos
  17. 17. WebSocket... ... is a bi-directional AND full-duplex communication STANDARD for next-generation web applications („TCP for the web“)
  18. 18. … and HTML5 APIs
  19. 19. WebSocket Standard • Client API (WC3) – (simple) JavaScript API • Network Protocol (ITEF) – Still under development...: – draft-hixie-thewebsocketprotocol-75 – ... – draft-ietf-hybi-thewebsocketprotocol-03 – http://blog.chromium.org/2010/06/websocket-protocol-updated.html
  20. 20. WebSocket Protocol GET / HTTP/1.1. Upgrade: WebSocket. Connection: Upgrade. Host: echo.websockets.org. ... HTTP/1.1 101 Web Socket Protocol Handshake. Upgrade: WebSocket. Connection: Upgrade. Sec­WebSocket­Location: ws://echo.websockets.org/. Server: Kaazing Gateway. ....
  21. 21. WebSocket vs COMET...
  22. 22. WebSocket Client API ws = new WebSocket("ws://echo.websockets.org:80"); ws.onmessage = function(event) {   doSomeFancyDhtml(event.data); }; ws.onopen = function(event) {...}; ws.onclose = function(event) {...}; ws.onerror = function(event) {...}; ws.send('Howdy, Partner!'); ws.close();
  23. 23. WebSocket - Support • Browser: – Firefox 4 (in beta status) – Chrome / Chromium – (mobile) Safari – Opera • Server – Node.js – Kaazing Gateway – Jetty 7 and 8 – Glassfish 3.1 – Resin – ...
  24. 24. WebSocket – Jetty public class JettyWebSocketServlet extends  WebSocketServlet { private final Set<WebSocket> clients = ...            new CopyOnWriteArraySet();   protected WebSocket doWebSocketConnect( HttpServletRequest request, String protocol)   {     return new MyWebSocket();   } ... }
  25. 25. WebSocket – Resin public class ResinWebSocketServlet extends  GenericServlet { public void service(ServletRequest req,  ServletResponse res)     throws IOException, ServletException   {     WebSocketServletRequest wsReq =  (WebSocketServletRequest) req;  WebSocketListener handler  = new CustomHandler();     wsReq.startWebSocket(handler);   } }
  26. 26. WebSocket – Glassfish 3.1 import java.io.IOException; import com.sun.grizzly.websockets.*; public class EchoWebSocketApp extends  WebSocketApplication {   public void onMessage(WebSocket socket,  DataFrame data) throws IOException   {     socket.send(data.getTextPayload());   } }
  27. 27. WebSocket – Glassfish 3.1 public class BackEndWrapper extends  WebSocketApplication {   @Inject Service myService;   public void onMessage(WebSocket socket,  DataFrame data) throws IOException   {     ServiceWebSocket sws =                (ServiceWebSocket) socket;     myService.doInvokeTheBackend(sws.getFooBar());     ....   }   ... }
  28. 28. WebSocket – Java EE WebSocket Support in JavaEE 7 ?
  29. 29. Agenda • Real Time (Web) – Introduction – Why not Bayeux • JavaServer Faces 2.0 – Highlights • WebSocket – Client API – (Java) Server APIs • Mixing JSF and WebSocket – Concepts and Demos
  30. 30. WebSocket meets JSF • JSF integration points: – Streaming data to the client • JSF Components – existing ones – custom ones – Communication from the browser: • JSF actions 'talk' to (active) system – „Invoke Application“ Phase
  31. 31. JSF's Action methods • Set up the WebSocket connection: – global (framework level) – Custom tag (page level) • Use JSF lifecycle to issue regular HTTP POST – 'invoke application interaction' • do regular work • Notify the WS 'channel' • Client-Side callback gets the server-side payload
  32. 32. WebSocket „components“ • Write WebSocket aware components: – Let the component set up the connection – leverage WS's onmessage() callback – Make custom JSF/WS models • What to do with existing components/pages? – 1) remove the „refresh“ button :-) – 2) let the framework notify the 'channel' – 3) use JSF's Ajax API to rerender the comp.
  33. 33. Thoughts... • Client's send() is outside of HTTP • current systems are HTTP based: – JAX-RS – JavaServer Faces – Apache Wicket, etc • Atmosphere Framework works with all of them, but • what about something like this ? <h:commandButton value=“Send stuff“ action=“#{bean.doStuff}“> <f:ajax .... /> </h:commandButton>
  34. 34. Thank you! @mwessendorf BLOG: matthiaswessendorf.wordpress.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×