1 WebSocket & JSON Java APIs Hackday By Somay David

Slides:



Advertisements
Similar presentations
What are Web Services? How to use them?
Advertisements

Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 1.
Rensselaer Polytechnic Institute CSCI-4220 – Network Programming David Goldschmidt, Ph.D.
JSON Valery Ivanov.
With jQuery and AJAX Doncho Minkov Telerik Corporation Technical Trainer.
6/11/2015Page 1 Web Services-based Distributed System B. Ramamurthy.
Reverse AJAX and HTML5 Based Clients for Embedded Control and Monitoring Systems C Robson, C Bohm, Stockholm University or "HTML5, why should we care?"
Client-server interactions in Mobile Applications.
More APIs: Web Services CMPT 281. Announcements Project milestone Lab: – Web services examples.
Android and iOS Development with JAX-RS, WebSocket , and Java EE 7
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 1.
Semantic Web Andrejs Lesovskis. Publishing on the Web Making information available without knowing the eventual use; reuse, collaboration; reproduction.
Lightning Talk Fred Rodriguez Aakash Juneja CPSC 473 March 16, 2012.
Rensselaer Polytechnic Institute CSCI-4220 – Network Programming David Goldschmidt, Ph.D.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 Lecture 22 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
CGI and AJAX CS-260 Dick Steflik.
GIS technologies and Web Mapping Services
1 What Can HTML5 WebSocket Do For You? Sidda Eraiah Director of Management Services Kaazing Corporation.
The New Zealand Institute for Plant & Food Research Limited Matthew Laurenson Web Services: Introduction & Design Considerations.
Lecture 13 – XML and JSON SFDV3011 – Advanced Web Development Reference: 1.
Message Driven Beans & Web Services INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
CSCI 6962: Server-side Design and Programming Web Services.
Web Services Week 7 Aims: A detailed look at the underlying mechanisms for communication between web services Objectives: SOAP, WSDL, UDDI.
HTML5. HTML5’s overall theme The browser as a rich application platform rich, cross-device user interfaces offline operation capability hardware access.
Or, Hey can’t we just do it using HTTP for the envelope?
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
1 Cisco Unified Application Environment Developers Conference 2008© 2008 Cisco Systems, Inc. All rights reserved.Cisco Public Introduction to Etch Scott.
Accada – Open Source EPC Network Prototyping Platform Christian Floerkemeier Christof Roduner SAP October 2006.
INT-5: Integrate over the Web with OpenEdge® Web Services
1 82 nd IETF meeting NETCONF over WebSocket ( ) Tomoyuki Iijima, (Hitachi) Hiroyasu Kimura,
Web Services (SOAP) part 1 Eriq Muhammad Adams J |
1 ObjectRiver Metadata Compilers Programmatic WebSockets JavaOne 2014 – Steven Lemmo.
Google Data Protocol Guy Mark Lifshitz. Motivation Google’s Mission: – Organize the world’s information – Make information universally accessible – Provide.
Server - Client Communication Getting data from server.

Zz SOCKET.IO going real time with Arnout Kazemier
Introduction to Web Services
Front end (user interfaces) Facilitating the user‘s interaction with the SandS services and processes I. Mlakar, D. Ceric, A. Lipaj Valladolid, 17/12/2014.
ICM – API Server & Forms Gary Ratcliffe.
Using WebSockets in Web apps Presenter: Shahzad Badar.
J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
VoiceXML Version 2.0 Jon Pitcherella. What is it? A W3C standard for specifying interactive voice dialogues. Uses a “voice” browser to interpret documents,
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
Feeling RESTful? Well, first we’ll define a Web Service –A web page meant to be consumed by a computer via an autonomous program as opposed to a web browser.
Tools of the trade J SON, M AVEN, A PACHE COMMON Photo from
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
Embt.co/sprint-rest-json-services Blog Notes: Building RESTful servers. In C++ Builder Developer Skill Sprint Tips, Tricks and Techniques The Ultimate.
LAB S – v0.13 – mpf – 23 juin Build a Mobile Rich Internet Application with JavaFX and RESTful services Didier Burkhalter, Mark Foster, Patrice Goutin.
JSR 353: Java API for JSON Processing
The Fat-Free Alternative to XML
Research of Web Real-Time Communication Based on WebSocket
WebSockets: TCP in Javascript
Creating,Publishing,Testing and Describing a Web Service
CS5220 Advanced Topics in Web Programming Introduction to WebSocket
Websocket Application
The Fat-Free Alternative to XML
WEB SERVICES.
JSON.
Web Services-JAX-RPC JAX-RPC enables a Web Service endpoint to be developed using either a Java Servlet or Enterprise JavaBeans (EJB) component model.
Unit – 5 JAVA Web Services
Lesson 11: Web Services & API's
WebSocket: Full-Duplex Solution for the Web
Asynchronous Javascript And XML
Web Socket Protocol.
Strings and Serialization
Integrating REST API and SQL Server JSON Functions
Distributed System using Web Services
The Fat-Free Alternative to XML
Distributed System using Web Services
Presentation transcript:

1 WebSocket & JSON Java APIs Hackday By Somay David

2 Hackday ?  Adapt A JSR programme  Explore new APIs  JSR 353 JSON Processing API  JSR 356 WebSockets API  Provide feedback

3 WebSocket and Java

4  Interactive web application  HTTP is half-duplex  Polling  Long Polling  Comet/Ajax  Complex, Inefficient, Wasteful

5 Enter WebSocket Protocol  TCP based, bi-directional, full-duplex messaging  Part of HTML5  IETF-defined Protocol: RFC 6455  W3C defined JavaScript API  Uses HTTP upgrade handshake  Supports HTTP proxies, filtering, authentication and intermediaries

6 How does it work?  Establish connection (Single TCP connection)  Send messages in both direction (Bi-directional)  Send messages independent of each other (Full Duplex)  End connection

7 Browser Support caniuse.com

8 WebSocket API (JavaScript) var websocket = new WebSocket("ws:// websocket.onopen = function(evt) { onOpen(evt) }; websocket.onclose = function(evt) { onClose(evt) }; websocket.onmessage = function(evt) { onMessage(evt) }; websocket.onerror = function(evt) { onError(evt) }; } function onMessage(evt) { alert( evt.data); } function onError(evt) { alert( evt.data); } websocket.send("client to server");

9 JSR 356 Java API for WebSocket

10  Client and Server WebSocket protocol APIs in Java  Integration with Java EE Web container  Reference Implementation:  –  – Bundled in latest Glassfish 4 builds JSR 356 Java API for WebSocket

11 Terminology  Endpoint: Client or server  Connection: Network connection between two endpoints  Peer: Other endpoint of the connection  Session: represents a sequence of websocket interactions between and end point and a peer

12 Annotations –Class level annotation for websocket server endpoint –Class level annotation for websocket client endpoint –Method level annotation signifies a method to be called whenever a new client connects to this endpoint –Method level annotation signifies a method to be called whenever a new client is about to disconnects from this endpoint –Method level annotation signifies a method to be called whenever an incoming message is received

13 Some public class HelloWorld public String sayHello(String name) { return "Hello " + name; }

14 More public class HelloWorld { private Set peers = public void onOpen (Session peer) { peers.add(peer); } private void sendMessageToPeer(String message, Session peer) { peer.getRemote().sendString(s); }

15 JSON and Java

16 In the beginning... There was XML... and the DOM... and SAX... Then, after much gnashing of teeth, there was JSON { "message" : "Hello World!" } More at json.org and wikipedia

17 tumbleweed...

18 Not Quite From: "The Software shall be used for Good, not Evil."

19 And many more... org.json.me. org.json.me Jackson JSON Processor. Jackson JSON Processor Json-lib. Json-lib JSON Tools. JSON Tools Stringtree. Stringtree SOJO. SOJO Jettison. Jettison json-taglib. json-taglib XStream. XStream Flexjson. Flexjson JON tools. JON tools Argo. Argo jsonij. jsonij fastjson. fastjson mjson. mjson jjson. jjson json-simple. json-simple json-io. json-io JsonMarshaller. JsonMarshaller google-gson. google-gson Json-smart. Json-smart FOSS Nova JSON. FOSS Nova JSON (list from json.org)

20 Fast-forward to December 2011 JSR 353: JavaTM API for JSON Processing "JSON(JavaScript Object Notation) is a lightweight data-interchange format. Many popular web services use JSON format for invoking and returning the data. Currently Java applications use different implementation libraries to produce/consume JSON from the web services. Hence, there is a need to standardize a Java API for JSON so that applications that use JSON need not bundle the implementation libraries but use the API. Applications will be smaller in size and portable."

21 Goals/Non Goals "The goal of this specification is to develop such APIs to: * Produce and consume JSON text in a streaming fashion(similar to StAX API for XML) * Build a Java object model for JSON text using API classes(similar to DOM API for XML) Non-goals of this specification include: * Binding of JSON text to Java objects and vice versa." "This JSR is targeted for Java SE 6 or higher and Java EE 7 or higher platforms."

22 Fast-forward to February 2013 Pretty much done Just finished the formal public review phase Looking for final feedback from JUGs... and to get the word out about what's coming

23 Some code... JsonGenerator generator = Json.createGenerator(System.out) // or generator = Json.createGenerator(servletResponse.getWriter()) generator.writeStartObject().write("firstName", "John").write("lastName", "Smith").write("age", 25).writeStartObject("address").write("streetAddress", "21 2nd Street").write("city", "New York").write("state", "NY").write("postalCode", "10021").writeEnd().writeStartArray("phoneNumber").writeStartObject().write("type", "home").write("number", " ").writeEnd().writeStartObject().write("type", "fax").write("number", " ").writeEnd().writeEnd().writeEnd(); generator.close();

24 Produces { "firstName": "John", "lastName": "Smith", "age": 25, "address" : { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ {"type": "home", "number": " "}, {"type": "fax", "number": " "} ] } (JavaDoc - JsonGenerator)

25 Or to build an object model... JsonObject value = Json.createObjectBuilder().add("firstName", "John").add("lastName", "Smith").add("age", 25).add("address", Json.createObjectBuilder().add("streetAddress", "21 2nd Street").add("city", "New York").add("state", "NY").add("postalCode", "10021")).add("phoneNumber", Json.createArrayBuilder().add(Json.createObjectBuilder().add("type", "home").add("number", " ")).add(Json.createObjectBuilder().add("type", "fax").add("number", " "))).build(); // or from a stream.. JsonObject value2 = Json.createReader(inputStream).readObject(); (JavaDoc - JsonObject) bit.ly/11CwMdebit.ly/11CwMde

26 And to read things from it... int age = value2.getIntValue("age", 18); JsonObject address = value2.getValue("address", JsonObject.class); String city = "London"; if(address != null){ city = address.getStringValue("city", "London"); } JsonArray phoneNumbers = value2.getValue("phoneNumber", JsonArray.class); if(phoneNumbers != null){ for(JsonValue val: value2){ if(val instanceof JsonObject){ JsonObject jo = (JsonObject)val; System.out.println(jo.getStringValue("number","Number Missing"); }

27 And a low-level event API Event event = parser.next(); // START_OBJECT event = parser.next(); // KEY_NAME event = parser.next(); // VALUE_STRING parser.getString(); // "John" (JavaDoc - JsonParser) bit.ly/VzGWErbit.ly/VzGWEr

28 JSON Hacks/Workshop Latest version of the library not in Glassfish yet, so a small standalone maven project Includes tests for some uncompleted code operating on stored JSON.. see the README for more.

29