Your SlideShare is downloading. ×
0
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Developing JAX-RS Web Applications Utilizing Server-Sent Events and WebSocket

3,503

Published on

JAX-RS/WebSocket lab at JavaOne Latin America 2012

JAX-RS/WebSocket lab at JavaOne Latin America 2012

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,503
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
101
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 2. Developing JAX-RS WebApplications Utilizing Server-Sent Events and WebSocketReza Rahman/Arun Gupta/Bruno BorgesJava EE/GlassFish Evangelists2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 3. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 4. Program Agenda  About This Lab  Quick Intro to the Technologies Used  Lab Exercises  Getting Started  Resources4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 5. About This Lab  Follow the lab guide  Exercises are self-paced  Raise your hand if you get stuck – we are here to help  To get most of the lab try to understand the code, don’t just blindly copy-paste5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 6. JAX-RS 2/Jersey Description  Java API for RESTful Web Services – Annotation-based API for RESTful web services  New in JAX-RS 2 – Client API – Filters/interceptors – Server-side content negotiation – Asynchronous processing6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 7. JAX-RS 2/Jersey Client API// Get instance of ClientClient client = ClientFactory.newClient();// Get account balanceString bal = client.target("http://.../atm/{cardId}/balance") .pathParam("cardId", "111122223333") .queryParam("pin", "9876") .request("text/plain").get(String.class);7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 8. JAX-RS 2/Jersey Where to get more info  JavaOne sessions: – JAX-RS 2: New and Noteworthy in the RESTful Web Services API  Reza Rahman  Keynote Hall - Thursday, 3 PM  On the web: – Specification project: http://jax-rs-spec.java.net – Implementation project: http://jersey.java.net – Twitter: @gf_jersey8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 9. Java API for WebSocket Description  Annotation-based API for utilizing WebSocket protocol in Java web applications – Planned to be part of Java EE 7  Allows defining WebSocket endpoints – Handling onOpen, onClose, onError and onMessage events – Bi-directional communication between peers  Support for encoders/decoders to map message content to/from Java objects9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 10. Java API for WebSocket Example – Simple Endpoint @WebSocketEndpoint("/echo") public class EchoBean { @WebSocketMessage public String echo(String message) { System.out.println("Message received: " + message); return message + " (from your server)"; } }10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 11. Java API for WebSocket Example – Decoder/Encoder @WebSocketEndpoint(”/drawing/”, decoders = ShapeCoding.class, encoders = ShapeCoding.class, ) public class DrawingWebSocket { @WebSocketMessage public void shapeCreated(Shape shape, Session session) { … } } public class ShapeCoding implements Decoder.Text<Shape>, Encoder.Text<Shape> { public Shape decode(String s) throws DecodeException { … } public boolean willDecode(String s) { … } public String encode(Shape object) throws EncodeException { … } }11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 12. Java API for WebSocket Where to get more information  JavaOne Sessions – HTML5 WebSocket and Java, Arun Gupta  Thursday, 10 AM, Mezanino: Sala 12  On The Web – Specification Project: http://websocket-spec.java.net – Implementation: http://tyrus.java.net12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 13. Java API for JSON Processing JSR-353  Streaming API to produce/consume JSON – Similar to StAX API in XML world  Object model API to represent JSON – Similar to DOM API in XML world  Aligns with Java EE 7 schedules13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 14. JSR-353: Java API for JSON Processing JsonReader/JsonWriter  JsonReader – reads JsonObject/JsonArray from i/o try(JsonReader reader = new JsonReader(io)) { JsonObject jsonObj = reader.readObject(); }  JsonWriter – writes JsonObject/JsonArray to i/o try(JsonWriter writer = new JsonWriter(io)) { writer.writeObject(jsonObj); }14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 15. Resources  Projects – Specification Project - http://json-processing-spec.java.net – RI Project - http://jsonp.java.net  Latest Javadoc – http://json-processing- spec.java.net/nonav/releases/1.0/edr/javadocs/index.html15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 16. Lab Exercises  Drawing Board web application: – Exercise 1: Exposing RESTful API ~ 30 minutes – Exercise 2: Adding Server-Sent Events ~ 30 minutes – Exercise 3: Adding WebSockets ~ 30 minutes  Simple Drawing Board client (optional): – Exercise 4: Implementing a Simple Java Client16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 17. Getting Started  Launch HOL4461 virtual machine in VirtualBox (if not already started)  Lab files installed under: – C:hol-sse-websocket-master  Open lab-guide.pdf  Follow the instructions17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 18. Additional Resources  GitHub project with this lab – https://github.com/jersey/hol-sse- websocket  Jersey – http://jersey.java.net  Tyrus – http://tyrus.java.net  JSON Processing – http://jsonp.java.net18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 19. Graphic Section Divider19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 20. 20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

×