SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
Server-Side Programming
         Primer
           Ivano Malavolta
      ivano.malavolta@univaq.it
  http://www.di.univaq.it/malavolta
Roadmap

• REST
• Web Sockets
• Server-sent Events
REST (Quick) Refresher

    In most cases,
    client-server
     comunication
    relies on HTTP




http://bit.ly/JALve1
REST Main Actors

These are the abstractions that make a RESTful system:

• Resources

• Representations

• Actions
Resources
In general, a RESTful resource is anything that is
   addressable over the Web

Addressable = anything that can be accessed and transferred
  between clients and servers

      a resource must have a unique address over the Web

  Under HTTP these are URIs

ex.
  .../orderinfo?id=123
Representations
The representation of resources is what is sent back and
  forth between clients and servers

A URL is a specialization of URI that defines the network
  location of a specific resource

es.   http://some.domain.com/orderinfo?id=123
Actions

Actions are used to operate on resources




They make up the uniform interface used for
  client/server data transfers
A Possible Implementation in Java
                                      these are annotated
     HTTP                                 Java classes




                     Resources
            Jersey

            Connector/J Driver JDBC
                                                 mySQL
                     Tomcat
JAX-RS
        Java API for RESTful Web Services

It is a Java programming language API that provides
  support in creating web services according to the
  REST architectural style
                                    Apache CXF
Many Implementations
                         Wink             Restlet

     RESTEasy
                           Jersey
Jersey

     Sun's reference implementation for JAX-RS

     • Open Source
     • Production Quality

     Jersey provides the connectors for web services
       through Java annotations




https://jersey.dev.java.net
Jersey

     The use of annotations allows us to create Jersey
       resources just as easily as we develop Plain Old
       Java Objects (POJOs)

     Jersey manages:
     • interception of HTTP requests
     • representation of negotiations

         we can concentrate on the business rules only

https://jersey.dev.java.net
Resource
A Jersey resource is a plain Java class with a @Path
  annotation

Every Jersey resource has a URI pointing to it
HTTP Methods: GET

Every HTTP request made to a web service is handled
  by an appropriately annotated method in a resource
  class




The name of the method is not important
HTTP Methods: POST

The POST request has a payload that the framework
  intercepts and delivers to us in the parameter
  payload




The payload can be a string, but also a binary stream
  of MIME type image/jpg, so our object type for the
  payload must change accordingly (InputStream,
  for instance)
HTTP Methods: PUT

Similar to the POST request, the PUT request has a
  payload associated with it, which is stored in the
  payload variable




* we will see later what @Consumes and @PathParam mean
HTTP Methods: DELETE

Similarly to the other methods...




* we will see later what @pathParam means
URI Variables
@PathParam gives us access to the value of a
  variable in a URI

We have to define also one or more String objects as
  parameters of the method




here, id is just another variable within the scope of
  the method
Input Formats

The @Consumes annotation tells how to receive
  inbound representations from the clients




The client sets the Content-Type HTTP header and Jersey
  delegates the request to the corresponding method

This annotation works together with @POST and @PUT
Output Formats

The @Produces annotation tells how to send outbound
  representations to the clients




The client sets the Accept HTTP header that maps
  directly to the Content-Type the method produces

This annotation works together with @GET, @POST and
  @PUT
Other Annotations
• @FormParams
    – it lets us read the values of name/value pairs passed in as part
      of a POST or PUT request
• @HEAD
    – the method will process HTTP HEAD request
• @CookieParam
    – it is used to extract values from a cookie
• @HeaderParam
    – it is used to extract parameters from an HTTP header
• ...
Employee Directory DEMO
Roadmap

• REST
• Web Sockets
• Server-sent Events
Real-time Web? Polling
                            Browser         connect      Server
                                            no message
                                            connect
                                            no message
                                                          event
                                            connect
                                            event
                                            connect
http://slidesha.re/LeNohX




                                            no message
                                            connect
                                            no message    event
                                            connect
                                             event
Real-time Web? Polling
PROs
• Easy to implement via REST
• Runs on standard HTTP servers

CONs
• No real-time user experience
• Wasted bandwidth
   – most requests return no data
• High server loads
Real-time Web? Long Polling (Comet)
                            Browser                      Server
                                        connect
                                                  wait
                                                          event
                                         event
                                        connect
                                                  wait
http://slidesha.re/LeNohX




                                                          event
                                         event
                                        connect
                                                  wait
Real-time Web? Long Polling (Comet)

PROs
• Real-time user experience



CONs
• High server loads
   – memory
   – threads & processes
• Still waste of bandwidth
Real-time Web? Server-Sent Events
                            Browser                            Server
                                           open event stream
                              <EventSource>

                                               event            event
                                  onmessage
                                                                event
                                               event
                                  onmessage
                                                                event
http://slidesha.re/LeNohX




                                  onmessage    event
Real-time Web? Long Polling (Comet)

PROs
• Real-time user experience



CONs
• only unidirectional
Real-time Web? Web Sockets
                                               GET /text HTTP/1.1
                            Client/Browser     Upgrade: WebSocket
                                                                                    Server
                                               Connection: Upgrade
                                               Host: www.websocket.org ...


                                              HTTP/1.1 101 WebSocket Protocol Handshake
                                              Upgrade: WebSocket ...
http://slidesha.re/LeNohX




                                               TCP comm. channel
                                             Full duplex, bidirectional
Web Sockets
Bidirectional, full-duplex communication between
               full-
  devices and server

Specifically suited for
  chat, videogames, drawings sharing, real-time info

W3C/IETF standard
 (http://dev.w3.org/html5/websockets)

Requires a Web Socket Server to handle the protocol
Web Sockets
• What can be sent into a web socket?
   – UTF8 Strings
   – Binary Frames

  it is not a TCP socket
   (TCP manages only streams of bytes)

• WebSockets Protocol prefixes:
   – ws://
   – wss://
Web Sockets Workflow
                                                      Handshake
                                                       Upgrade




http://code.google.com/p/websocket-sample/wiki/Tips
Inter-Clients Communication
     1. Client notifies websocket server of an event, giving ids of
        recipients
     2. The server notifies all the active clients (subscribed to
        that type of event)
     3. Clients process event
        when given recipient Id
        matches the client’s one




http://bit.ly/Ixcupi
Web Socket Interface




http://www.w3.org/TR/2009/WD-websockets-20091222/
Drawbacks
•   draft standard
•   supported by latest browsers only
•   some proxies may still block WS handshakes
•   need for keep-alive messages
             keep-
•   need to manually manage message queues
•   every encountered problem results in closing the
    connection
       you cannot distinguish between:
        • client or server errors
        • network errors
        • timeouts
A Possible Implementation in Java


                                                    extended
                               HTTP handshake
                                                  Java Servlet


                                                    Chat
                                                      Chat
                                                       Chat
                                                  Web Socket
                                                   Web Socket
                                                    Web Socket


                                                Jetty Server


http://www.eclipse.org/jetty
Chat DEMO
Roadmap

• REST
• Web Sockets
• Server-sent Events
Server-Sent Events
It setups a persistent http connection
which has to be setup only once

It is unidirectional:
      unidirectional:
server     client


SSEs are sent over traditional HTTP
    it can be easily implemented with standard server-
  side technologies (eg PHP)
SSE- Overview
     1.   Client sends a request to the server via HTTP
     2.   The server creates a process, which fetches latest state in
          the DB and responds back
     3.   Client gets server response
     4.   In X seconds client automatically sends next request to the
          server




http://bit.ly/Ixcupi
Client-Side Interface




http://dev.w3.org/html5/eventsource/
Client-Side Events

You can also listen to customized events (not only
  generic messages

var source = new EventSource(“http://some.url”);
var handler = function(event){
  console.log(event.data);
  console.log(event.id);              these are all the
  console.log(event.origin);          properties of an
  console.log(event.lastEventId);          event
}
source.addEventListener(‘myEvent', handler, false);
Server-Side SSE

An SSE is plain text delivered as part of a stream from
  a URL

Our data must be treated as a stream
Server-Side SSE

Syntax of an SSE:
         <fieldName>: <fieldValue>n
SSE Fields
fieldName can be:

• data (required)
   – the information to be sent
• event
   – the type of event being sent
• id
   – an identifier for the event to be used when the client
     reconnects
• retry
   – how much time (in milliseconds) should pass before the
     client tries to reconnect to the URL
Drawbacks

• supported by latest browsers only
• browser discrepancies
• you need a server that can handle large numbers of
  simultaneous connections
• legacy browsers may drop the HTTP connection
  after a short timeout
Possible Implementations in Java & PHP

  start event stream
                         Java Servlet
  keep alives
  event stream
                       Jetty Server



                             start event stream
                                                      PHP Page
                            keep alives
                            event stream
                                                  Apache Server
CurrentTime DEMO
References

Weitere ähnliche Inhalte

Was ist angesagt?

Using Java to implement SOAP Web Services: JAX-WS
Using Java to implement SOAP Web Services: JAX-WS�Using Java to implement SOAP Web Services: JAX-WS�
Using Java to implement SOAP Web Services: JAX-WSKatrien Verbert
 
Web development with ASP.NET Web API
Web development with ASP.NET Web APIWeb development with ASP.NET Web API
Web development with ASP.NET Web APIDamir Dobric
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsArun Gupta
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIEyal Vardi
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RSFahad Golra
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonAdnan Masood
 
Server-side Java Programming
Server-side Java ProgrammingServer-side Java Programming
Server-side Java ProgrammingChris Schalk
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using PhpSudheer Satyanarayana
 
Writing & Using Web Services
Writing & Using Web ServicesWriting & Using Web Services
Writing & Using Web ServicesRajarshi Guha
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixBruce Snyder
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technologyvikram singh
 

Was ist angesagt? (19)

Using Java to implement SOAP Web Services: JAX-WS
Using Java to implement SOAP Web Services: JAX-WS�Using Java to implement SOAP Web Services: JAX-WS�
Using Java to implement SOAP Web Services: JAX-WS
 
Web development with ASP.NET Web API
Web development with ASP.NET Web APIWeb development with ASP.NET Web API
Web development with ASP.NET Web API
 
Excellent rest using asp.net web api
Excellent rest using asp.net web apiExcellent rest using asp.net web api
Excellent rest using asp.net web api
 
Java servlets and CGI
Java servlets and CGIJava servlets and CGI
Java servlets and CGI
 
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent EventsGetting Started with WebSockets and Server-Sent Events
Getting Started with WebSockets and Server-Sent Events
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RS
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
 
Server-side Java Programming
Server-side Java ProgrammingServer-side Java Programming
Server-side Java Programming
 
Web-Socket
Web-SocketWeb-Socket
Web-Socket
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Writing & Using Web Services
Writing & Using Web ServicesWriting & Using Web Services
Writing & Using Web Services
 
ASP.NET WEB API
ASP.NET WEB APIASP.NET WEB API
ASP.NET WEB API
 
Servlets
ServletsServlets
Servlets
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 

Andere mochten auch

Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...jaxLondonConference
 
Getting Started with WebSocket and Server-Sent Events in Java
Getting Started with WebSocket and Server-Sent Events in JavaGetting Started with WebSocket and Server-Sent Events in Java
Getting Started with WebSocket and Server-Sent Events in JavaArun Gupta
 
ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim
ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-CardasimItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim
ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-CardasimFlorin Cardasim
 
Scalableenterpriseapplicationswith jee7andbeyond
Scalableenterpriseapplicationswith jee7andbeyondScalableenterpriseapplicationswith jee7andbeyond
Scalableenterpriseapplicationswith jee7andbeyondAndy Moncsek
 
What’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyWhat’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyMohamed Taman
 
REST, Web Sockets, Server-sent Events
REST, Web Sockets, Server-sent EventsREST, Web Sockets, Server-sent Events
REST, Web Sockets, Server-sent EventsIvano Malavolta
 
Pushing Java EE outside of the Enterprise - Home Automation
Pushing Java EE outside of the Enterprise - Home AutomationPushing Java EE outside of the Enterprise - Home Automation
Pushing Java EE outside of the Enterprise - Home AutomationDavid Delabassee
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsSagara Gunathunga
 
Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSKatrien Verbert
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
Adopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS updateAdopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS updatePavel Bucek
 
JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013Jagadish Prasath
 

Andere mochten auch (12)

Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
 
Getting Started with WebSocket and Server-Sent Events in Java
Getting Started with WebSocket and Server-Sent Events in JavaGetting Started with WebSocket and Server-Sent Events in Java
Getting Started with WebSocket and Server-Sent Events in Java
 
ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim
ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-CardasimItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim
ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim
 
Scalableenterpriseapplicationswith jee7andbeyond
Scalableenterpriseapplicationswith jee7andbeyondScalableenterpriseapplicationswith jee7andbeyond
Scalableenterpriseapplicationswith jee7andbeyond
 
What’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyWhat’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new Strategy
 
REST, Web Sockets, Server-sent Events
REST, Web Sockets, Server-sent EventsREST, Web Sockets, Server-sent Events
REST, Web Sockets, Server-sent Events
 
Pushing Java EE outside of the Enterprise - Home Automation
Pushing Java EE outside of the Enterprise - Home AutomationPushing Java EE outside of the Enterprise - Home Automation
Pushing Java EE outside of the Enterprise - Home Automation
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RS
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Adopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS updateAdopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS update
 
JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013
 

Ähnlich wie Server-Side Programming Primer

Codecamp iasi-26 nov 2011-web sockets
Codecamp iasi-26 nov 2011-web socketsCodecamp iasi-26 nov 2011-web sockets
Codecamp iasi-26 nov 2011-web socketsCodecamp Romania
 
Codecamp Iasi-26 nov 2011 - Html 5 WebSockets
Codecamp Iasi-26 nov 2011 - Html 5 WebSocketsCodecamp Iasi-26 nov 2011 - Html 5 WebSockets
Codecamp Iasi-26 nov 2011 - Html 5 WebSocketsFlorin Cardasim
 
Connected Web Systems
Connected Web SystemsConnected Web Systems
Connected Web SystemsDamir Dobric
 
Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15streamdata.io
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleC2B2 Consulting
 
Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"Sachin Katariya
 
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.pptweb-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt20521742
 
Data power v7 update - Ravi Katikala
Data power v7 update - Ravi KatikalaData power v7 update - Ravi Katikala
Data power v7 update - Ravi Katikalafloridawusergroup
 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawnozten
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsNaresh Chintalcheru
 
Messaging for Real-time WebApps
Messaging for Real-time WebAppsMessaging for Real-time WebApps
Messaging for Real-time WebAppsTiju John
 
Decoding real time web communication
Decoding real time web communicationDecoding real time web communication
Decoding real time web communicationAMiT JAiN
 
(ATS4-DEV04) Protocols as RESTful Services and RESTful URL Routing
(ATS4-DEV04) Protocols as RESTful Services and RESTful URL Routing(ATS4-DEV04) Protocols as RESTful Services and RESTful URL Routing
(ATS4-DEV04) Protocols as RESTful Services and RESTful URL RoutingBIOVIA
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIPRIYADARSINISK
 

Ähnlich wie Server-Side Programming Primer (20)

Codecamp iasi-26 nov 2011-web sockets
Codecamp iasi-26 nov 2011-web socketsCodecamp iasi-26 nov 2011-web sockets
Codecamp iasi-26 nov 2011-web sockets
 
Codecamp Iasi-26 nov 2011 - Html 5 WebSockets
Codecamp Iasi-26 nov 2011 - Html 5 WebSocketsCodecamp Iasi-26 nov 2011 - Html 5 WebSockets
Codecamp Iasi-26 nov 2011 - Html 5 WebSockets
 
Connected Web Systems
Connected Web SystemsConnected Web Systems
Connected Web Systems
 
Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15
 
Real time web apps
Real time web appsReal time web apps
Real time web apps
 
Building real-time-collaborative-web-applications
Building real-time-collaborative-web-applicationsBuilding real-time-collaborative-web-applications
Building real-time-collaborative-web-applications
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
 
Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"
 
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.pptweb-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
 
Ws
WsWs
Ws
 
Data power v7 update - Ravi Katikala
Data power v7 update - Ravi KatikalaData power v7 update - Ravi Katikala
Data power v7 update - Ravi Katikala
 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawn
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
 
Messaging for Real-time WebApps
Messaging for Real-time WebAppsMessaging for Real-time WebApps
Messaging for Real-time WebApps
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Decoding real time web communication
Decoding real time web communicationDecoding real time web communication
Decoding real time web communication
 
(ATS4-DEV04) Protocols as RESTful Services and RESTful URL Routing
(ATS4-DEV04) Protocols as RESTful Services and RESTful URL Routing(ATS4-DEV04) Protocols as RESTful Services and RESTful URL Routing
(ATS4-DEV04) Protocols as RESTful Services and RESTful URL Routing
 
Intro to Web Sockets
Intro to Web Sockets Intro to Web Sockets
Intro to Web Sockets
 
www.ppt
www.pptwww.ppt
www.ppt
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, API
 

Mehr von Ivano Malavolta

Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Ivano Malavolta
 
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)Ivano Malavolta
 
Software sustainability and Green IT
Software sustainability and Green ITSoftware sustainability and Green IT
Software sustainability and Green ITIvano Malavolta
 
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Ivano Malavolta
 
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]Ivano Malavolta
 
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Ivano Malavolta
 
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Ivano Malavolta
 
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Ivano Malavolta
 
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Ivano Malavolta
 
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Ivano Malavolta
 
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Ivano Malavolta
 
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Ivano Malavolta
 
Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Ivano Malavolta
 
[2017/2018] Agile development
[2017/2018] Agile development[2017/2018] Agile development
[2017/2018] Agile developmentIvano Malavolta
 
Reconstructing microservice-based architectures
Reconstructing microservice-based architecturesReconstructing microservice-based architectures
Reconstructing microservice-based architecturesIvano Malavolta
 
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design LanguageIvano Malavolta
 
[2017/2018] Architectural languages
[2017/2018] Architectural languages[2017/2018] Architectural languages
[2017/2018] Architectural languagesIvano Malavolta
 
[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software ArchitectureIvano Malavolta
 
[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineeringIvano Malavolta
 

Mehr von Ivano Malavolta (20)

Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
 
The H2020 experience
The H2020 experienceThe H2020 experience
The H2020 experience
 
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
 
Software sustainability and Green IT
Software sustainability and Green ITSoftware sustainability and Green IT
Software sustainability and Green IT
 
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
 
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
 
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...
 
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
 
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
 
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...
 
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
 
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
 
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
 
Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...
 
[2017/2018] Agile development
[2017/2018] Agile development[2017/2018] Agile development
[2017/2018] Agile development
 
Reconstructing microservice-based architectures
Reconstructing microservice-based architecturesReconstructing microservice-based architectures
Reconstructing microservice-based architectures
 
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language
 
[2017/2018] Architectural languages
[2017/2018] Architectural languages[2017/2018] Architectural languages
[2017/2018] Architectural languages
 
[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture
 
[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering
 

Kürzlich hochgeladen

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Kürzlich hochgeladen (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Server-Side Programming Primer

  • 1. Server-Side Programming Primer Ivano Malavolta ivano.malavolta@univaq.it http://www.di.univaq.it/malavolta
  • 2. Roadmap • REST • Web Sockets • Server-sent Events
  • 3. REST (Quick) Refresher In most cases, client-server comunication relies on HTTP http://bit.ly/JALve1
  • 4. REST Main Actors These are the abstractions that make a RESTful system: • Resources • Representations • Actions
  • 5. Resources In general, a RESTful resource is anything that is addressable over the Web Addressable = anything that can be accessed and transferred between clients and servers a resource must have a unique address over the Web Under HTTP these are URIs ex. .../orderinfo?id=123
  • 6. Representations The representation of resources is what is sent back and forth between clients and servers A URL is a specialization of URI that defines the network location of a specific resource es. http://some.domain.com/orderinfo?id=123
  • 7. Actions Actions are used to operate on resources They make up the uniform interface used for client/server data transfers
  • 8. A Possible Implementation in Java these are annotated HTTP Java classes Resources Jersey Connector/J Driver JDBC mySQL Tomcat
  • 9. JAX-RS Java API for RESTful Web Services It is a Java programming language API that provides support in creating web services according to the REST architectural style Apache CXF Many Implementations Wink Restlet RESTEasy Jersey
  • 10. Jersey Sun's reference implementation for JAX-RS • Open Source • Production Quality Jersey provides the connectors for web services through Java annotations https://jersey.dev.java.net
  • 11. Jersey The use of annotations allows us to create Jersey resources just as easily as we develop Plain Old Java Objects (POJOs) Jersey manages: • interception of HTTP requests • representation of negotiations we can concentrate on the business rules only https://jersey.dev.java.net
  • 12. Resource A Jersey resource is a plain Java class with a @Path annotation Every Jersey resource has a URI pointing to it
  • 13. HTTP Methods: GET Every HTTP request made to a web service is handled by an appropriately annotated method in a resource class The name of the method is not important
  • 14. HTTP Methods: POST The POST request has a payload that the framework intercepts and delivers to us in the parameter payload The payload can be a string, but also a binary stream of MIME type image/jpg, so our object type for the payload must change accordingly (InputStream, for instance)
  • 15. HTTP Methods: PUT Similar to the POST request, the PUT request has a payload associated with it, which is stored in the payload variable * we will see later what @Consumes and @PathParam mean
  • 16. HTTP Methods: DELETE Similarly to the other methods... * we will see later what @pathParam means
  • 17. URI Variables @PathParam gives us access to the value of a variable in a URI We have to define also one or more String objects as parameters of the method here, id is just another variable within the scope of the method
  • 18. Input Formats The @Consumes annotation tells how to receive inbound representations from the clients The client sets the Content-Type HTTP header and Jersey delegates the request to the corresponding method This annotation works together with @POST and @PUT
  • 19. Output Formats The @Produces annotation tells how to send outbound representations to the clients The client sets the Accept HTTP header that maps directly to the Content-Type the method produces This annotation works together with @GET, @POST and @PUT
  • 20. Other Annotations • @FormParams – it lets us read the values of name/value pairs passed in as part of a POST or PUT request • @HEAD – the method will process HTTP HEAD request • @CookieParam – it is used to extract values from a cookie • @HeaderParam – it is used to extract parameters from an HTTP header • ...
  • 22. Roadmap • REST • Web Sockets • Server-sent Events
  • 23. Real-time Web? Polling Browser connect Server no message connect no message event connect event connect http://slidesha.re/LeNohX no message connect no message event connect event
  • 24. Real-time Web? Polling PROs • Easy to implement via REST • Runs on standard HTTP servers CONs • No real-time user experience • Wasted bandwidth – most requests return no data • High server loads
  • 25. Real-time Web? Long Polling (Comet) Browser Server connect wait event event connect wait http://slidesha.re/LeNohX event event connect wait
  • 26. Real-time Web? Long Polling (Comet) PROs • Real-time user experience CONs • High server loads – memory – threads & processes • Still waste of bandwidth
  • 27. Real-time Web? Server-Sent Events Browser Server open event stream <EventSource> event event onmessage event event onmessage event http://slidesha.re/LeNohX onmessage event
  • 28. Real-time Web? Long Polling (Comet) PROs • Real-time user experience CONs • only unidirectional
  • 29. Real-time Web? Web Sockets GET /text HTTP/1.1 Client/Browser Upgrade: WebSocket Server Connection: Upgrade Host: www.websocket.org ... HTTP/1.1 101 WebSocket Protocol Handshake Upgrade: WebSocket ... http://slidesha.re/LeNohX TCP comm. channel Full duplex, bidirectional
  • 30. Web Sockets Bidirectional, full-duplex communication between full- devices and server Specifically suited for chat, videogames, drawings sharing, real-time info W3C/IETF standard (http://dev.w3.org/html5/websockets) Requires a Web Socket Server to handle the protocol
  • 31. Web Sockets • What can be sent into a web socket? – UTF8 Strings – Binary Frames it is not a TCP socket (TCP manages only streams of bytes) • WebSockets Protocol prefixes: – ws:// – wss://
  • 32. Web Sockets Workflow Handshake Upgrade http://code.google.com/p/websocket-sample/wiki/Tips
  • 33. Inter-Clients Communication 1. Client notifies websocket server of an event, giving ids of recipients 2. The server notifies all the active clients (subscribed to that type of event) 3. Clients process event when given recipient Id matches the client’s one http://bit.ly/Ixcupi
  • 35. Drawbacks • draft standard • supported by latest browsers only • some proxies may still block WS handshakes • need for keep-alive messages keep- • need to manually manage message queues • every encountered problem results in closing the connection you cannot distinguish between: • client or server errors • network errors • timeouts
  • 36. A Possible Implementation in Java extended HTTP handshake Java Servlet Chat Chat Chat Web Socket Web Socket Web Socket Jetty Server http://www.eclipse.org/jetty
  • 38. Roadmap • REST • Web Sockets • Server-sent Events
  • 39. Server-Sent Events It setups a persistent http connection which has to be setup only once It is unidirectional: unidirectional: server client SSEs are sent over traditional HTTP it can be easily implemented with standard server- side technologies (eg PHP)
  • 40. SSE- Overview 1. Client sends a request to the server via HTTP 2. The server creates a process, which fetches latest state in the DB and responds back 3. Client gets server response 4. In X seconds client automatically sends next request to the server http://bit.ly/Ixcupi
  • 42. Client-Side Events You can also listen to customized events (not only generic messages var source = new EventSource(“http://some.url”); var handler = function(event){ console.log(event.data); console.log(event.id); these are all the console.log(event.origin); properties of an console.log(event.lastEventId); event } source.addEventListener(‘myEvent', handler, false);
  • 43. Server-Side SSE An SSE is plain text delivered as part of a stream from a URL Our data must be treated as a stream
  • 44. Server-Side SSE Syntax of an SSE: <fieldName>: <fieldValue>n
  • 45. SSE Fields fieldName can be: • data (required) – the information to be sent • event – the type of event being sent • id – an identifier for the event to be used when the client reconnects • retry – how much time (in milliseconds) should pass before the client tries to reconnect to the URL
  • 46. Drawbacks • supported by latest browsers only • browser discrepancies • you need a server that can handle large numbers of simultaneous connections • legacy browsers may drop the HTTP connection after a short timeout
  • 47. Possible Implementations in Java & PHP start event stream Java Servlet keep alives event stream Jetty Server start event stream PHP Page keep alives event stream Apache Server