Web Sockets in Java EE 7Sivasubramaniam ArunachalamMay 09, 2013@sivaa_inhttps://oraclein.activeevents.com/connect/sessionD...
It’s me!• Product/Application Developer• Web/Enterprise/Middleware/B2B• Java/Java EE, Python/Django• 2002• Technical Consu...
Agenda• Introduction to Web Sockets• History• Protocol Spec• Adoption• Java EE 7 Support• Demo
http://tweetping.netLet’s warm up
Web 1.0Web 1.0Web 2.0Web 3.0
https://www.facebook.com/sitetour/chat.php600+ M Active Users/Day
http://199119952013Still 22 Years Oldhttp?
http/tcp(1974)(1991)request / response~ 2k bytes~ 150 msState less
Real TimeReal Time~
4,0,0,0,0,0 | 2,0,1,…http://www.espncricinfo.com/indian-premier-league-2013/engine/match/598051.htmlSRH Score Card vs CSKO...
Pull Based (Polling)Periodic Polling (JS/AJAX)Server ClientSRH 4/0Latest Score?Latest Score?Latest Score?SameSameLatest Sc...
Push Based (Comet)Server Push/Long Polling (JS/AJAX/iframe)Server ClientSRH 4/0Latest Score?Latest Score?SRH 6/0Latest Sco...
• Request / Response• Too Many• Server Connections• Heavy Headers• Outdated Content
StreamingServer Side HackServer ClientSRH 4/0 (1/n)Latest Score?SRH 6/0 (2/n)SRH 146/8 (n/n)Ov 0.1Ov 1.1Ov 20.0
Server ClientSRH 4/0Latest Score?SRH 4/0SRH 6/0SRH 146/8ServerBufferSRH 6/0SRH 146/8PROXY(1/n)(n-1 to go)(n/n)(2/n)(n-2 to...
• RTMP• Adobe• Are you Still using Flash?• RTD• Windows/Excel• Non WebOthers
Web Sockets (to rescue)
The Web Socket WayThe Original RouteServer ClientHi Client!Hey Server!SRH 4/0Update me the ScoreSRH 6/0SRH 146/8Not Intere...
Server ClientHi Client!Hey Server!SRH 4/0Update me the ScoreSRH 6/0SRH 7/0Not Interested. ByeUpdate Over info too(1.3 ov)(...
The Background
https://webmq.tavendo.de:9090/help/faqLet’s Meet Next Year (2014)
Server Side• Hand Shake• Data TransferRFC 6455Client Side• Java Script API• Browser Behaviorhttps://webmq.tavendo.de:9090/...
• tcp• Full Duplex (Bi-Directional)• Native Browser Support• No Hacks• Not Limited to WebFundamentals+ http
• 80 / 443 (plain/secure)• No Proxy/Firewall pains• Stream of Messages (Not Bytes)• ws:// & wss://• Only ONE Connection (u...
2 Bytes Header(for each message)Still Why?~ 50 ms (Latency)1000 x3 x
http://www.codeproject.com/Articles/437342/DotNet-WebSocket-Programming1 Message/Second to each Client1,000 clients 10,000...
• GET (request)• 101 (response code)• Not 200 OK• http:// -> ws://The UpgradeRFC 2616 (14.42)
GET /demo HTTP/1.1Origin : http://sivaa.inHost : sivaa.inConnection : UpgradeUpgrade : WebSocketWebSocket-Protocol : json,...
HTTP/1.1 101 Switching ProtocolsConnection : UpgradeUpgrade : WebSocketWebSocket-Protocol : json, chat, <protocol>WebSocke...
Challenge by ClientSec-WebSocket-Key : Key (Random 128 bits -> Base 64)Response By ServerSec-WebSocket-Accept : Key + GUID...
http://tools.ietf.org/html/rfc6455#page-28
Client / ServerClient / ServerPeer <-> Peer
• Frames (TCP)•• No request / response behavior• No Correlation too• Independent• # of requests != # of responsesData Tran...
• Headers• Cookies• AuthenticationAnd No
• Custom Message Patterns• Technical / Business• Request / Response• 1 – 1• 1 to Many• AcknowledgementsSub Protocols
Sub Protocols - Currenthttp://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name
Extensions• Compression• Multiplexing• Private Extenstions (x-)
Client -> PingServer -> PongPing / Pong• Keep-Alive• Heart Beat• Latency Metrics• N/W Status Probing• Detect Failed Connec...
Browser Supporthttp://caniuse.com/websockets
Server SupportIDL (Java Script)http://www.w3.org/TR/websockets/
http://www.w3.org/TR/websockets/
http://www.w3.org/TR/websockets/
http://www.w3.org/TR/websockets/
http://www.w3.org/TR/websockets/
1. var ws = new WebSocket("ws://sivaa.in/demo");2. ws.onopen = function() {ws.send("Hello Server!");};3. ws.onmessage = fu...
• Closing Long Lived Connections• Unresponsive Server• Buffering Server Response• Non Encryption• More LatencyThe Guards(P...
• Web Sockets isn’t Proxy aware• Stripping HTTP Headers• Upgrade• Options to disable• Rejecting Server Response• Frames (H...
• 501• 301• Limited Support• Inconsistent BehaviorThe Hidden Blades
• No Polling (0%)• Low Bandwidth• Low Latency• High Interoperability (expected)Some Marketing Facts
The Vendors(Server/Client/Proxy)http://static.ibnlive.in.com/ibnlive/pix/slideshow/12-2011/happy-birthday-rajinikaths/raji...
• Web Socket• Flash• Long Polling• Multi-Part Streaming• Forever Frame• Long Polling JSONPThe Best Approach
• SSE (Server Side Events)• SPDYWeb Sockets vs
• JSR 356• Java EE 7• Tyrus ( http://tyrus.java.net/ )• Web Socket SDK• Reference ImplementationJava EE 7 & Web Socket
• Handshake Response to Clients• Source/Origin Check• URI Resolving & Matching• Sub Protocols Negotiation• Extension Negot...
HandlersHandler PurposeEnd Point To handle life cycle eventsSession To represent currently active sessionRemote End Point ...
• Interface Driven• Annotation DrivenModels
• Text Based• Binary• Ping/PongMessage Types
• Text• TextStream• Binary• BinaryStreamEncoders/Decoders
• javax.websocket.*• javax.websocket.server.*• javax.net.websocket.*Packages
Recent Refactoring Changeshttps://blogs.oracle.com/PavelBucek/entry/tyrus_1_0_b12_released (Feb 27, 2013)
Web Sockets & Servlet 3.1• HTTP Upgrade• HttpServletRequest.upgrade()• javax.servlet.http.HttpUpgradeHandler• javax.servle...
• Apache Tomcat 7• GlassFish 3.1• Jetty 7• JBoss 7• And much moreWeb Server Supporthttps://java.net/projects/websocket-spe...
• Annotations / Interface• Reference Implementation• Web Sockets SDK / mvn• Samples to Begin withGlassFish
Lets Play!
• Subversion (svn)• Maven (mvn)• NetBeans IDE (7.3)• Glassfish Promoted Build (latest)Tools (which I use)
1. Get your tools ready2. Configure GlassFish in NetBeans3. # svn checkouthttp://svn.java.net/svn/websocket-sdk~source-cod...
Demo
Thank You!siva@sivaa.inbit.ly/sivasubramaniambit.ly/sivaa_in
References• http://www.inc.com/ss/brief-history-time-management#7• http://resources3.news.com.au/images/2013/01/30/1226564...
Upcoming SlideShare
Loading in …5
×

Web sockets in java EE 7 - JavaOne 2013

4,541 views

Published on

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

No Downloads
Views
Total views
4,541
On SlideShare
0
From Embeds
0
Number of Embeds
682
Actions
Shares
0
Downloads
86
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Web sockets in java EE 7 - JavaOne 2013

  1. 1. Web Sockets in Java EE 7Sivasubramaniam ArunachalamMay 09, 2013@sivaa_inhttps://oraclein.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1081&tclass=popup
  2. 2. It’s me!• Product/Application Developer• Web/Enterprise/Middleware/B2B• Java/Java EE, Python/Django• 2002• Technical Consultant/Process Mentor• Member of BOJUG• Speaker
  3. 3. Agenda• Introduction to Web Sockets• History• Protocol Spec• Adoption• Java EE 7 Support• Demo
  4. 4. http://tweetping.netLet’s warm up
  5. 5. Web 1.0Web 1.0Web 2.0Web 3.0
  6. 6. https://www.facebook.com/sitetour/chat.php600+ M Active Users/Day
  7. 7. http://199119952013Still 22 Years Oldhttp?
  8. 8. http/tcp(1974)(1991)request / response~ 2k bytes~ 150 msState less
  9. 9. Real TimeReal Time~
  10. 10. 4,0,0,0,0,0 | 2,0,1,…http://www.espncricinfo.com/indian-premier-league-2013/engine/match/598051.htmlSRH Score Card vs CSKOver 1 (Mohit) Over 2 (Holder)146/8 (20 Overs)(May 08, 2013)
  11. 11. Pull Based (Polling)Periodic Polling (JS/AJAX)Server ClientSRH 4/0Latest Score?Latest Score?Latest Score?SameSameLatest Score?SRH 6/0Latest Score?SameOv 0.1Ov 0.3Ov 0.5Ov 1.1Ov 1.2
  12. 12. Push Based (Comet)Server Push/Long Polling (JS/AJAX/iframe)Server ClientSRH 4/0Latest Score?Latest Score?SRH 6/0Latest Score?Ov 0.1Ov 0.2Ov 1.1Ov 1.2
  13. 13. • Request / Response• Too Many• Server Connections• Heavy Headers• Outdated Content
  14. 14. StreamingServer Side HackServer ClientSRH 4/0 (1/n)Latest Score?SRH 6/0 (2/n)SRH 146/8 (n/n)Ov 0.1Ov 1.1Ov 20.0
  15. 15. Server ClientSRH 4/0Latest Score?SRH 4/0SRH 6/0SRH 146/8ServerBufferSRH 6/0SRH 146/8PROXY(1/n)(n-1 to go)(n/n)(2/n)(n-2 to go)Ov 0.1Ov 1.1Ov 20.0
  16. 16. • RTMP• Adobe• Are you Still using Flash?• RTD• Windows/Excel• Non WebOthers
  17. 17. Web Sockets (to rescue)
  18. 18. The Web Socket WayThe Original RouteServer ClientHi Client!Hey Server!SRH 4/0Update me the ScoreSRH 6/0SRH 146/8Not Interested. ByeOv 0.1Ov 1.1Ov 20.0
  19. 19. Server ClientHi Client!Hey Server!SRH 4/0Update me the ScoreSRH 6/0SRH 7/0Not Interested. ByeUpdate Over info too(1.3 ov)(1.1 ov)(0.5 ov)(1.0 ov)Ov 0.1Ov 0.5Ov 1.0Ov 1.1Ov 1.2 (1.2 ov)Ov 1.3
  20. 20. The Background
  21. 21. https://webmq.tavendo.de:9090/help/faqLet’s Meet Next Year (2014)
  22. 22. Server Side• Hand Shake• Data TransferRFC 6455Client Side• Java Script API• Browser Behaviorhttps://webmq.tavendo.de:9090/help/faq
  23. 23. • tcp• Full Duplex (Bi-Directional)• Native Browser Support• No Hacks• Not Limited to WebFundamentals+ http
  24. 24. • 80 / 443 (plain/secure)• No Proxy/Firewall pains• Stream of Messages (Not Bytes)• ws:// & wss://• Only ONE Connection (up/down streams)The Spec
  25. 25. 2 Bytes Header(for each message)Still Why?~ 50 ms (Latency)1000 x3 x
  26. 26. http://www.codeproject.com/Articles/437342/DotNet-WebSocket-Programming1 Message/Second to each Client1,000 clients 10,000 clients 1,00,000 clients
  27. 27. • GET (request)• 101 (response code)• Not 200 OK• http:// -> ws://The UpgradeRFC 2616 (14.42)
  28. 28. GET /demo HTTP/1.1Origin : http://sivaa.inHost : sivaa.inConnection : UpgradeUpgrade : WebSocketWebSocket-Protocol : json, chat, <protocol>WebSocket-extensions : compression, <extn>WebSocket-Version : 10Client Request
  29. 29. HTTP/1.1 101 Switching ProtocolsConnection : UpgradeUpgrade : WebSocketWebSocket-Protocol : json, chat, <protocol>WebSocket-Origin : http://sivaa.inWebSocket-Location : ws://sivaa.in/demoServer Response
  30. 30. Challenge by ClientSec-WebSocket-Key : Key (Random 128 bits -> Base 64)Response By ServerSec-WebSocket-Accept : Key + GUID* (SHA1)[NOT FOR SECURITY]* 258EAFA5-E914-47DA- 95CA-C5AB0DC85B11 (RFC 6455)Challenge - Response
  31. 31. http://tools.ietf.org/html/rfc6455#page-28
  32. 32. Client / ServerClient / ServerPeer <-> Peer
  33. 33. • Frames (TCP)•• No request / response behavior• No Correlation too• Independent• # of requests != # of responsesData Transfer
  34. 34. • Headers• Cookies• AuthenticationAnd No
  35. 35. • Custom Message Patterns• Technical / Business• Request / Response• 1 – 1• 1 to Many• AcknowledgementsSub Protocols
  36. 36. Sub Protocols - Currenthttp://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name
  37. 37. Extensions• Compression• Multiplexing• Private Extenstions (x-)
  38. 38. Client -> PingServer -> PongPing / Pong• Keep-Alive• Heart Beat• Latency Metrics• N/W Status Probing• Detect Failed Connections
  39. 39. Browser Supporthttp://caniuse.com/websockets
  40. 40. Server SupportIDL (Java Script)http://www.w3.org/TR/websockets/
  41. 41. http://www.w3.org/TR/websockets/
  42. 42. http://www.w3.org/TR/websockets/
  43. 43. http://www.w3.org/TR/websockets/
  44. 44. http://www.w3.org/TR/websockets/
  45. 45. 1. var ws = new WebSocket("ws://sivaa.in/demo");2. ws.onopen = function() {ws.send("Hello Server!");};3. ws.onmessage = function(event) {alert("Reply from Server " + event.data);};n-1. ws.send("This is the message sent by the client");n. ws.close()Developer FriendlyCONNECTINGOPENCLOSINGCLOSED
  46. 46. • Closing Long Lived Connections• Unresponsive Server• Buffering Server Response• Non Encryption• More LatencyThe Guards(Proxy / Firewall)
  47. 47. • Web Sockets isn’t Proxy aware• Stripping HTTP Headers• Upgrade• Options to disable• Rejecting Server Response• Frames (HTTP Headers Expected)• wss:// - No issuesWeb Sockets andThe Guards
  48. 48. • 501• 301• Limited Support• Inconsistent BehaviorThe Hidden Blades
  49. 49. • No Polling (0%)• Low Bandwidth• Low Latency• High Interoperability (expected)Some Marketing Facts
  50. 50. The Vendors(Server/Client/Proxy)http://static.ibnlive.in.com/ibnlive/pix/slideshow/12-2011/happy-birthday-rajinikaths/rajini-dec11-8.jpghttp://media2.intoday.in/indiatoday/images/stories//2012december/rajinikanth_660_121112060009.jpg
  51. 51. • Web Socket• Flash• Long Polling• Multi-Part Streaming• Forever Frame• Long Polling JSONPThe Best Approach
  52. 52. • SSE (Server Side Events)• SPDYWeb Sockets vs
  53. 53. • JSR 356• Java EE 7• Tyrus ( http://tyrus.java.net/ )• Web Socket SDK• Reference ImplementationJava EE 7 & Web Socket
  54. 54. • Handshake Response to Clients• Source/Origin Check• URI Resolving & Matching• Sub Protocols Negotiation• Extension NegotiationServer Side Capabilities(Expected)
  55. 55. HandlersHandler PurposeEnd Point To handle life cycle eventsSession To represent currently active sessionRemote End Point To represent a peerMessage Handler To handle incoming messagesError Handler Handler for error scenarios
  56. 56. • Interface Driven• Annotation DrivenModels
  57. 57. • Text Based• Binary• Ping/PongMessage Types
  58. 58. • Text• TextStream• Binary• BinaryStreamEncoders/Decoders
  59. 59. • javax.websocket.*• javax.websocket.server.*• javax.net.websocket.*Packages
  60. 60. Recent Refactoring Changeshttps://blogs.oracle.com/PavelBucek/entry/tyrus_1_0_b12_released (Feb 27, 2013)
  61. 61. Web Sockets & Servlet 3.1• HTTP Upgrade• HttpServletRequest.upgrade()• javax.servlet.http.HttpUpgradeHandler• javax.servlet.http.WebConnection
  62. 62. • Apache Tomcat 7• GlassFish 3.1• Jetty 7• JBoss 7• And much moreWeb Server Supporthttps://java.net/projects/websocket-spec/pages/WebSocketAPIs17+
  63. 63. • Annotations / Interface• Reference Implementation• Web Sockets SDK / mvn• Samples to Begin withGlassFish
  64. 64. Lets Play!
  65. 65. • Subversion (svn)• Maven (mvn)• NetBeans IDE (7.3)• Glassfish Promoted Build (latest)Tools (which I use)
  66. 66. 1. Get your tools ready2. Configure GlassFish in NetBeans3. # svn checkouthttp://svn.java.net/svn/websocket-sdk~source-code-repository/trunk/samples/4. # mvn clean install5. Import in Latest Net Beans6. Run itSteps
  67. 67. Demo
  68. 68. Thank You!siva@sivaa.inbit.ly/sivasubramaniambit.ly/sivaa_in
  69. 69. References• http://www.inc.com/ss/brief-history-time-management#7• http://resources3.news.com.au/images/2013/01/30/1226564/845955-tim-berners-lee.jpg• http://netdna.webdesignerdepot.com/uploads/2009/01/macii.jpg#old%20apple%20computer%20559x450• http://3.bp.blogspot.com/_zVkfb2MIt4A/S8f_qzhuhRI/AAAAAAAAAjg/2idf7_G4wxo/s1600/apple-imac.png• http://www.softwareforeducation.com/wikileki/images/c/c4/Simplex-half-full.gif• http://www.mediafly.com/wp-content/uploads/Speed_Rocket-2.png• http://weaponsman.com/wp-content/uploads/2013/01/thumbs-down.png• http://m.flikie.com/ImageData/WallPapers/d1bef9f8be6d479387953929c766699a.jpg• http://www.tavendo.de/webmq/resources/faq• http://deadliestwebattacks.com/tag/websocket/• http://en.wikipedia.org/wiki/WebSocket• http://www.infoq.com/articles/Web-Sockets-Proxy-Servers• http://media2.intoday.in/indiatoday/images/stories//2012december/rajinikanth_660_121112060009.jpg

×