Websocket,JSON in JEE7

2,000 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
2,000
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Websocket,JSON in JEE7

  1. 1. Java API forWebSockets & JSONP in JEE7Prasanna Kumar S
  2. 2. JSR 356 - Java API for Websocket● Creating WebSocket Java components to handle bi-directional WebSocket conversations● Initiating and intercepting WebSocket events● Creation and consumption of WebSocket text and binarymessages● The abililty to define WebSocket protocols and contentmodels for an applicationHeads up on JSRs
  3. 3. Heads up on JSRs (Contd.)JSR 353 - JAva API for JSON processing● Produce and consume JSON text in a streaming fashion● Build a Java object model for JSON text using API classes● Binding of JSON text to Java objects and vice versa.
  4. 4. Websocket - Server endpoint@ServerEndpoint(value = "/HomeWS",encoders = {DataEncoder.class},decoders = {DataDecoder.class})public class HomeWS {@OnOpenpublic void onOpen(Session peer) {}@OnClosepublic void onClose(Session peer) {}@OnMessagepublic void broadCastMessage(GameData figure, Session session) throwsIOException, EncodeException {}}WebSocket - Server Endpointclients callwith this URL
  5. 5. Websocket - client endpoint@ClientEndpoint(decoders = {DataDecoder.class}, encoders = {DataEncoder.class})public class SignalChangeEndpointClient {@OnOpenpublic void onOpen(Session session) throws IOException, EncodeException {}}WebSocket - Client Endpointhas no url value
  6. 6. public class DataDecoder implements Decoder.Text<GameData> {@Overridepublic GameData decode(String string) throws DecodeException {JsonObject jsonObject = Json.createReader(new StringReader(string)).readObject();return new GameData(jsonObject);}}public class DataEncoder implements Encoder.Text<GameData> {@Overridepublic String encode(GameData figure) throws EncodeException {return figure.getJson().toString();}}WebSocket - Message Carriers
  7. 7. this code could be used with any java object to initiate a websocket message○ EJB○ Servlet○ JSF handlerWebSocket - Message SendingClient//...WebSocketContainer container = ContainerProvider.getWebSocketContainer();String uri = "ws://websocket.appserver.org/websocket"; // illustrative URLcontainer.connectToServer(SignalChangeEndpointClient.class, URI.create(uri));//...
  8. 8. Artifactsfor the well grounded ....Tyrus - a RI of JSR 356http://tyrus.java.net/for the impatient ....GlassFish 4 (JEE7) - via Promoted buildshttp://download.java.net/glassfish/4.0/promoted/upcomingWildFlyhttp://www.wildfly.org/
  9. 9. Questions?
  10. 10. Thank you

×