TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Web sockets in java EE 7 - JavaOne 2013
1. Web Sockets in Java EE 7
Sivasubramaniam Arunachalam
May 09, 2013
@sivaa_in
https://oraclein.activeevents.com/connect/sessionDetail.ww?SESSION_ID=1081&tclass=popup
11. Pull Based (Polling)Periodic Polling (JS/AJAX)
Server Client
SRH 4/0
Latest Score?
Latest Score?
Latest Score?
Same
Same
Latest Score?
SRH 6/0
Latest Score?
Same
Ov 0.1
Ov 0.3
Ov 0.5
Ov 1.1
Ov 1.2
12. Push Based (Comet)Server Push/Long Polling (JS/AJAX/iframe)
Server Client
SRH 4/0
Latest Score?
Latest Score?
SRH 6/0
Latest Score?
Ov 0.1
Ov 0.2
Ov 1.1
Ov 1.2
13. • Request / Response
• Too Many
• Server Connections
• Heavy Headers
• Outdated Content
18. The Web Socket WayThe Original Route
Server Client
Hi Client!
Hey Server!
SRH 4/0
Update me the Score
SRH 6/0
SRH 146/8
Not Interested. Bye
Ov 0.1
Ov 1.1
Ov 20.0
19. Server Client
Hi Client!
Hey Server!
SRH 4/0
Update me the Score
SRH 6/0
SRH 7/0
Not Interested. Bye
Update Over info too
(1.3 ov)
(1.1 ov)
(0.5 ov)
(1.0 ov)
Ov 0.1
Ov 0.5
Ov 1.0
Ov 1.1
Ov 1.2 (1.2 ov)
Ov 1.3
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 Friendly
CONNECTING
OPEN
CLOSING
CLOSED
46. • Closing Long Lived Connections
• Unresponsive Server
• Buffering Server Response
• Non Encryption
• More Latency
The Guards
(Proxy / Firewall)
47. • Web Sockets isn’t Proxy aware
• Stripping HTTP Headers
• Upgrade
• Options to disable
• Rejecting Server Response
• Frames (HTTP Headers Expected)
• wss:// - No issues
Web Sockets and
The Guards
48. • 501
• 301
• Limited Support
• Inconsistent Behavior
The Hidden Blades
49. • No Polling (0%)
• Low Bandwidth
• Low Latency
• High Interoperability (expected)
Some Marketing Facts
53. • JSR 356
• Java EE 7
• Tyrus ( http://tyrus.java.net/ )
• Web Socket SDK
• Reference Implementation
Java EE 7 & Web Socket
54. • Handshake Response to Clients
• Source/Origin Check
• URI Resolving & Matching
• Sub Protocols Negotiation
• Extension Negotiation
Server Side Capabilities
(Expected)
55. Handlers
Handler Purpose
End Point To handle life cycle events
Session To represent currently active session
Remote End Point To represent a peer
Message Handler To handle incoming messages
Error Handler Handler for error scenarios
62. • Apache Tomcat 7
• GlassFish 3.1
• Jetty 7
• JBoss 7
• And much more
Web Server Support
https://java.net/projects/websocket-spec/pages/WebSocketAPIs
17+
63. • Annotations / Interface
• Reference Implementation
• Web Sockets SDK / mvn
• Samples to Begin with
GlassFish
65. • Subversion (svn)
• Maven (mvn)
• NetBeans IDE (7.3)
• Glassfish Promoted Build (latest)
Tools (which I use)
66. 1. Get your tools ready
2. Configure GlassFish in NetBeans
3. # svn checkout
http://svn.java.net/svn/websocket-sdk~source-code-repository/trunk/samples/
4. # mvn clean install
5. Import in Latest Net Beans
6. Run it
Steps