SlideShare a Scribd company logo
1 of 89
REST, dojo, Comet Carol McDonald, Java Architect
About the Speaker ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object]
Example RESTful Catalog
RESTful Slideshow using JAX-RS and comet
REST and JAX-RS
REpresentational State Transfer ,[object Object],[object Object],Response XML data = REpresentational State Transfer   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
REST Tenets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
HTTP Example Request GET   /catalog/items  HTTP/1.1 Host: petstore.com Accept: application/xml Response HTTP/1.1 200 OK Date: Tue, 08 May 2007 16:41:58 GMT Server: Apache/1.3.6 Content-Type: application/xml; charset=UTF-8 <?xml version=&quot;1.0&quot;?> <items xmlns=&quot;…&quot;> <item>…</item> … </items> Method Resource  Representation State transfer
JAX-RS: Clear mapping to REST concepts ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example RESTful Catalog
Example RESTful Catalog Service  Catalog Database Web container (GlassFish™) + REST API  Browser (Firefox) HTTP
URIs  and  Methods: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Item Catalog Example ,[object Object]
POJO @Path(&quot;/items/&quot;) public class ItemsResource { @Produces(&quot;application/json&quot;) @GET public ItemsConverter get() { ... } ... } responds to the URI  http://host/catalog/items/ responds with JSON responds to HTTP GET
Methods  ,[object Object],[object Object],@Path(“/items”) class ItemsResource { @GET  Items get() { ... } @POST  Response create(Item) { ... } } class ItemResource { @GET  Item get(...) { ... } @PUT  void update(...) { ... } @DELETE  void delete(...) { ... } }
RESTful Catalog  ,[object Object],DB Registration Application JAX-RS class Dojo client JAXB class Entity Class ItemsConverter Item ItemsResource
Entity Classes ,[object Object],[object Object],[object Object],http://host/catalog/items/123 public class Item {    int id;   String name;    String descr;   String url; } @Entity @Id Item ID NAME DESC URL
Converter Classes ,[object Object],DB JAX-RS class Dojo client JAXB class Entity Class ItemsConverter Item ItemsResource
ItemConverter JAXB annotated  @XmlRootElement(name = &quot;item&quot;) public class ItemConverter { private Item entity; private URI uri; @XmlAttribute public URI getUri() { return uri; } @XmlElement public Long getId() { return (expandLevel > 0) ? entity.getId() : null; } ...   }
XML <item  uri=&quot;http://localhost/Web/resources/items/1/&quot; > <description> black cat is nice</description> <id>1</id> <imagethumburl>/images/anth.jpg</imagethumburl> <name>not Friendly Cat</name> <price>307.10</price> <productid>feline01</productid> </item>
JSON ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ItemsConverter JAXB annotated  @XmlRootElement(name = &quot;items&quot;) public class ItemsConverter { private Collection<ItemConverter> items; private URI uri; @XmlAttribute public URI getUri() { return uri; } @XmlElement public Collection<ItemConverter> getItem() { ... return items; } }
XML <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <items uri=&quot;http://localhost/Web/resources/items/&quot;> <item  uri=&quot;http://localhost/Web/resources/items/1/&quot; > <description> black cat is nice</description> <id>1</id> <imagethumburl>/images/anth.jpg</imagethumburl> <name>not Friendly Cat</name> <price>307.10</price> <productid>feline01</productid> </item> <item  . . . </item> </items>
JSON ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Resource Classes ,[object Object],[object Object],[object Object],[object Object],DB JAX-RS class Dojo client JAXB class Entity Class ItemsConverter Item ItemsResource
Get Items  @Path(&quot;/items/&quot;) public class ItemsResource { @Context protected UriInfo uriInfo; @GET @Produces (&quot;application/json&quot;) public  ItemsConverter  get(){ return new ItemsConverter( getEntities(), uriInfo.getAbsolutePath()); } Performs JPA Query, returns list of entities  JAXB class responds with JSON responds to the URI  http://host/catalog/items/ responds to HTTP GET
Get  Item @Path(&quot;/items/&quot;) public class  ItemsResource  { @Path(&quot;{id}/&quot;) public ItemResource getItemResource( @PathParam (&quot;id&quot;) Long id) { return new  ItemResource (id, context); } } public class  ItemResource  {  @GET @Produces ( &quot;application/json&quot;) public ItemConverter get() { return new ItemConverter(getEntity(), context.getAbsolutePath(), expandLevel); } JAXB class http://host/catalog/items/123
Dojo Client Side JavaScript Library
What is the Dojo Toolkit? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],source: dojotoolkit.org
Dojo  3  main parts:   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
  Loading   d ojo
Use Dojo from Content Distribution Network : ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Use Dojo from your Web Server : ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Use bundled Dojo with Netbeans project: ,[object Object]
Or Use downloaded Dojo with Netbeans project: (if you want a different version) ,[object Object],[object Object],[object Object]
Run File  themeTester.html
Try out dojo  dijit  widgets
Setting up dojo javascript in the page ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Logging  ,[object Object],[object Object],[object Object],[object Object],[object Object]
Dijit =  d ojo Widget
dijit  is a UI widget system layered on top of dojo The dojo Widget Library
What is a dojo Widget? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Creating a Button Widget ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Form Widgets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example dijit.form.DateTextBox ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dijit Layout ,[object Object]
Dijit Command Control ,[object Object]
Dojo Event system
dojo.event.connect(srcObj,&quot;srcFunc&quot;, targetFunc); ,[object Object],[object Object],[object Object],[object Object],[object Object]
  XMLHttpRequest (XHR): dojo.xhrDelete(), dojo.xhrGet(), dojo.xhrPost(),  dojo.xhrPut()
Traditional Web  AJAX  within a browser,  there is AJAX engine
RESTful Pet Catalog Web Service  http://petstore/catalog/resources/items/ HTTP  GET {&quot;url&quot;:&quot;http://store/catalog/item1&quot;, {&quot;url&quot;:&quot;http://store/catalog/item2&quot;} Response JSON slide urls Server Client  Addressable Resources Web Container
Dojo Client ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Getting Items from the RESTful Service ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example RESTful Catalog
Dojo client  index.html <button dojoType=&quot;dijit.form.Button&quot; onclick=&quot; next &quot;> Next </button> <div id=&quot;grid&quot;  dojoType =&quot; dojox.Grid &quot;  model =&quot; model &quot; structure=&quot; layout &quot; autoWidth=&quot;true&quot; > http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c.html Grid widget
Dojo client.js   formatImage  = function(value) { if (!value) return '&nbsp;';  return &quot;<img src='&quot; + value + &quot;'/>&quot;;  }; // Data Grid layout // A grid view is a group of columns var view1 = { cells: [ [ {name: 'Name', field: &quot;name&quot;}, {name: 'Description', field: &quot;description&quot;}, {name: 'Photo',field: &quot;imagethumburl&quot;,  formatter:  formatImage , }, {name: 'Price',field: &quot;price&quot;} ] ] }; // a grid layout is an array of views. var  layout  = [ view1 ]; // the model= collection of objects to be displayed in the grid model  = new dojox.grid.data.Objects(null,null);
Dojo client.js   // make request to the items web service function  loadTable (page){ start = page * batchSize; var  targetURL  = &quot;resources/items/?start=&quot;+   encodeURIComponent(start); dojo.xhrGet ({ url:  targetURL , handleAs: &quot;json&quot;, load:  handleResponse , error: handleError }); } // Process the response from the items web service function  handleResponse ( responseObject , ioArgs){ // set the model object with the returned items list  model .setData( responseObject.items.item ); } function  next()  { page =page + 1; loadTable (page); } Performs HTTP GET on url  catalog/items
COMET
Comet: the server pushes data to the client  over a long-lived HTTP connection   Server Client 1 Client 2
Ajax Push and HTTP keep-alive ,[object Object],[object Object],[object Object],[object Object],Long Poll : Send a request to the server,  request waits for an event, then response sent
Ajax Push HTTP example ,[object Object],[object Object],[object Object],[object Object],HTTP/1.1 200 OK Content-Type: application/json-comment-filtered Server: GlassFish/v3 /*[{&quot;id&quot;:&quot;0&quot;, &quot;minimumVersion&quot;:0.9, &quot;supportedConnectionTypes&quot;:[&quot;long-polling&quot;,&quot;callback-polling&quot;], &quot;successful&quot;:true,&quot;advice&quot;:{&quot;reconnect&quot;:&quot;retry&quot;,&quot;interval&quot;:0}, &quot;channel&quot;:&quot;/meta/handshake&quot;,&quot;clientId&quot;:&quot;3b37f0aae53ab2f1&quot; ,&quot;ext&quot;:{&quot;json-comment-filtered&quot;:true},&quot;version&quot;:1.0}]*/ Handshake
Blocking http request =server catastrophe GET /updates HTTP/1.1 Connection: keep-alive GET /updates HTTP/1.1 Connection: keep-alive GET /updates HTTP/1.1 Connection: keep-alive GET /updates HTTP/1.1 Connection: keep-alive GET /updates HTTP/1.1 Connection: keep-alive
GlassFish Grizzly Comet ,[object Object],[object Object],[object Object],[object Object],[object Object]
Introduction to Grizzly Comet ,[object Object],[object Object],[object Object]
Server-side Ajax Push: Who supports what The asynchronicity matrix. X WebLogic Container Asynchronous IO Suspendible Request/ Response Delivery Guarantee Jetty X Tomcat X X GlassFish X X X Resin X
The Bayeux Protocol ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Bayeux HTTP  Publish Subscribe protocol for routing  JSON -encoded events between clients and servers  in a  publish-subscribe  model Grizzly provides an implementation of Bayeux Just configure Glassfish domain.xml and Web App  web.xml
Bayeux Multiple Channels Http Comet and Reverse Ajax Cometd clients ,[object Object]
Bayeux/Cometd JSON Publish/Subscribe ,[object Object],[object Object],[object Object],[object Object],[ { &quot;channel&quot;: &quot;/some/name&quot;, &quot;clientId&quot;: &quot;83js73jsh29sjd92&quot;, &quot;data&quot;: { &quot;myapp&quot; : &quot;specific data&quot;, value: 100 } } ]
Enable Comet in GlassFish V2 Admin Console
Configure Cometd  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Cometd HTTP  Requests ,[object Object],[object Object],[object Object]
RESTful Web Services and Comet http://developers.sun.com/appserver/reference/techart/cometslideshow.html
RESTful Slideshow Web Service  http://host/slideshow/resources/slides/ HTTP  GET {&quot;url&quot;:&quot;http://host/slideshow/image1.jpg&quot;, {&quot;url&quot;:&quot;http://host/slideshow/image2.jpg&quot;} Response JSON slide urls Server Client  Addressable Resources Web Container
Cometd Step1 : Initialize dojo.require(&quot; dojox.cometd &quot;); //Initialize a connection to the given Comet server:  the GlassFish Grizzly Bayeux servlet dojox.cometd. init (&quot;serverURL&quot;); Comet Server Client 1 Client 2
Cometd Step 2: Subscribe dojox.cometd. subscribe (“topic”, &quot;object&quot;,  &quot;callbackFunction&quot;); ,[object Object],[object Object],[object Object],Comet Server Client 1 Client 2
 
 
Cometd Step 3: Publish dojox.cometd. publish (&quot;topic&quot;, {slide: url}); a client publishes the next slide url  to the topic channel JSON message client 1 Comet Server Next slide url
 
Cometd Step 4: Update Clients: CallBack  callBackFunction(slideUrl) { slide.innerHTML =&quot;<img src='&quot; + slideUrl + &quot;'/>&quot;; ... } ,[object Object],[object Object],[object Object],Update Browser Update Browser Comet Server Client 2 Client 3
 
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
RESTful Web Services and Comet http://developers.sun.com/appserver/reference/techart/cometslideshow.html
RESTful Web Services http://netbeans.tv/screencasts/offset/7/
Example RESTful Catalog http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c.html
For More Information ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],Carol McDonald  Java Architect http://weblogs.java.net/blog/caroljmcdonald/

More Related Content

What's hot

03 form-data
03 form-data03 form-data
03 form-data
snopteck
 
2008.07.17 발표
2008.07.17 발표2008.07.17 발표
2008.07.17 발표
Sunjoo Park
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr1383
 
070517 Jena
070517 Jena070517 Jena
070517 Jena
yuhana
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernate
patinijava
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
Samnang Chhun
 

What's hot (20)

Thinking restfully
Thinking restfullyThinking restfully
Thinking restfully
 
Terms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explainedTerms of endearment - the ElasticSearch Query DSL explained
Terms of endearment - the ElasticSearch Query DSL explained
 
IR with lucene
IR with luceneIR with lucene
IR with lucene
 
03 form-data
03 form-data03 form-data
03 form-data
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
 
Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0
 
2008.07.17 발표
2008.07.17 발표2008.07.17 발표
2008.07.17 발표
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
What’s in a structured value?
What’s in a structured value?What’s in a structured value?
What’s in a structured value?
 
Jena
JenaJena
Jena
 
070517 Jena
070517 Jena070517 Jena
070517 Jena
 
2007 03 12 Swecr 2
2007 03 12 Swecr 22007 03 12 Swecr 2
2007 03 12 Swecr 2
 
Using Apache Solr
Using Apache SolrUsing Apache Solr
Using Apache Solr
 
4 sw architectures and sparql
4 sw architectures and sparql4 sw architectures and sparql
4 sw architectures and sparql
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernate
 
Querying Linked Data with SPARQL
Querying Linked Data with SPARQLQuerying Linked Data with SPARQL
Querying Linked Data with SPARQL
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
 
NHibernate
NHibernateNHibernate
NHibernate
 
Lucene And Solr Intro
Lucene And Solr IntroLucene And Solr Intro
Lucene And Solr Intro
 

Viewers also liked

Are you good at doing sports?
Are you good at doing sports?Are you good at doing sports?
Are you good at doing sports?
onlychild21
 
Using Oracle Applications on your iPad
Using Oracle Applications on your iPadUsing Oracle Applications on your iPad
Using Oracle Applications on your iPad
Oracle Day
 

Viewers also liked (18)

Diskripsi diri
Diskripsi diriDiskripsi diri
Diskripsi diri
 
JS basics
JS basicsJS basics
JS basics
 
Nce2文本
Nce2文本Nce2文本
Nce2文本
 
Quotes from Leaders in the Civic Engagement Movement
Quotes from Leaders in the Civic Engagement Movement Quotes from Leaders in the Civic Engagement Movement
Quotes from Leaders in the Civic Engagement Movement
 
Are you good at doing sports?
Are you good at doing sports?Are you good at doing sports?
Are you good at doing sports?
 
Portugal Global Times Feature
Portugal Global Times FeaturePortugal Global Times Feature
Portugal Global Times Feature
 
Chongqing municipal people's government work report
Chongqing municipal people's government work reportChongqing municipal people's government work report
Chongqing municipal people's government work report
 
Bao cao thuc tap
Bao cao thuc tapBao cao thuc tap
Bao cao thuc tap
 
Spine X Live2D 百萬智多星製作經驗談
Spine X Live2D 百萬智多星製作經驗談Spine X Live2D 百萬智多星製作經驗談
Spine X Live2D 百萬智多星製作經驗談
 
Root: Ped
Root: PedRoot: Ped
Root: Ped
 
ijhff
ijhffijhff
ijhff
 
Microsoft Technical Webinar: Doing more with MS Office, SharePoint and Visual...
Microsoft Technical Webinar: Doing more with MS Office, SharePoint and Visual...Microsoft Technical Webinar: Doing more with MS Office, SharePoint and Visual...
Microsoft Technical Webinar: Doing more with MS Office, SharePoint and Visual...
 
Transformator
TransformatorTransformator
Transformator
 
Khaak aur khoon (dirt and blood) by naseem hijazi part 1
Khaak aur khoon (dirt and blood) by naseem hijazi part 1Khaak aur khoon (dirt and blood) by naseem hijazi part 1
Khaak aur khoon (dirt and blood) by naseem hijazi part 1
 
Extending Ajax Events for all mankind
Extending Ajax Events for all mankindExtending Ajax Events for all mankind
Extending Ajax Events for all mankind
 
Using Oracle Applications on your iPad
Using Oracle Applications on your iPadUsing Oracle Applications on your iPad
Using Oracle Applications on your iPad
 
Aula 1 a obra de kant como síntese do nascente pensamento burguês
Aula 1   a obra de kant como síntese do nascente pensamento burguêsAula 1   a obra de kant como síntese do nascente pensamento burguês
Aula 1 a obra de kant como síntese do nascente pensamento burguês
 
PLAZA 3.0 - an access point for plant comparative genomics
PLAZA 3.0 - an access point for plant comparative genomicsPLAZA 3.0 - an access point for plant comparative genomics
PLAZA 3.0 - an access point for plant comparative genomics
 

Similar to REST dojo Comet

Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
Lorna Mitchell
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic CommunicationIQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
Ted Leung
 

Similar to REST dojo Comet (20)

my test
my testmy test
my test
 
Ellerslie User Group - ReST Presentation
Ellerslie User Group - ReST PresentationEllerslie User Group - ReST Presentation
Ellerslie User Group - ReST Presentation
 
Getting Started With The Talis Platform
Getting Started With The Talis PlatformGetting Started With The Talis Platform
Getting Started With The Talis Platform
 
Itemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integrationItemscript, a specification for RESTful JSON integration
Itemscript, a specification for RESTful JSON integration
 
Apache Persistence Layers
Apache Persistence LayersApache Persistence Layers
Apache Persistence Layers
 
W3 C Specification For Interoperability And Accessibility For Ajax, Dhtml, Xm...
W3 C Specification For Interoperability And Accessibility For Ajax, Dhtml, Xm...W3 C Specification For Interoperability And Accessibility For Ajax, Dhtml, Xm...
W3 C Specification For Interoperability And Accessibility For Ajax, Dhtml, Xm...
 
Jsp
JspJsp
Jsp
 
AJAX Workshop Notes
AJAX Workshop NotesAJAX Workshop Notes
AJAX Workshop Notes
 
Clustering Made Easier: Using Terracotta with Hibernate and/or EHCache
Clustering Made Easier: Using Terracotta with Hibernate and/or EHCacheClustering Made Easier: Using Terracotta with Hibernate and/or EHCache
Clustering Made Easier: Using Terracotta with Hibernate and/or EHCache
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
 
Solr Presentation
Solr PresentationSolr Presentation
Solr Presentation
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
 
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
 
Struts2
Struts2Struts2
Struts2
 
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic CommunicationIQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
RIA and Ajax
RIA and AjaxRIA and Ajax
RIA and Ajax
 

More from Carol McDonald

More from Carol McDonald (20)

Introduction to machine learning with GPUs
Introduction to machine learning with GPUsIntroduction to machine learning with GPUs
Introduction to machine learning with GPUs
 
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...
 
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DB
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DBAnalyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DB
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DB
 
Analysis of Popular Uber Locations using Apache APIs: Spark Machine Learning...
Analysis of Popular Uber Locations using Apache APIs:  Spark Machine Learning...Analysis of Popular Uber Locations using Apache APIs:  Spark Machine Learning...
Analysis of Popular Uber Locations using Apache APIs: Spark Machine Learning...
 
Predicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine LearningPredicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine Learning
 
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DB
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DBStructured Streaming Data Pipeline Using Kafka, Spark, and MapR-DB
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DB
 
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...
 
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...
 
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...
 
How Big Data is Reducing Costs and Improving Outcomes in Health Care
How Big Data is Reducing Costs and Improving Outcomes in Health CareHow Big Data is Reducing Costs and Improving Outcomes in Health Care
How Big Data is Reducing Costs and Improving Outcomes in Health Care
 
Demystifying AI, Machine Learning and Deep Learning
Demystifying AI, Machine Learning and Deep LearningDemystifying AI, Machine Learning and Deep Learning
Demystifying AI, Machine Learning and Deep Learning
 
Spark graphx
Spark graphxSpark graphx
Spark graphx
 
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...
 
Streaming patterns revolutionary architectures
Streaming patterns revolutionary architectures Streaming patterns revolutionary architectures
Streaming patterns revolutionary architectures
 
Spark machine learning predicting customer churn
Spark machine learning predicting customer churnSpark machine learning predicting customer churn
Spark machine learning predicting customer churn
 
Fast Cars, Big Data How Streaming can help Formula 1
Fast Cars, Big Data How Streaming can help Formula 1Fast Cars, Big Data How Streaming can help Formula 1
Fast Cars, Big Data How Streaming can help Formula 1
 
Applying Machine Learning to Live Patient Data
Applying Machine Learning to  Live Patient DataApplying Machine Learning to  Live Patient Data
Applying Machine Learning to Live Patient Data
 
Streaming Patterns Revolutionary Architectures with the Kafka API
Streaming Patterns Revolutionary Architectures with the Kafka APIStreaming Patterns Revolutionary Architectures with the Kafka API
Streaming Patterns Revolutionary Architectures with the Kafka API
 
Apache Spark Machine Learning Decision Trees
Apache Spark Machine Learning Decision TreesApache Spark Machine Learning Decision Trees
Apache Spark Machine Learning Decision Trees
 
Advanced Threat Detection on Streaming Data
Advanced Threat Detection on Streaming DataAdvanced Threat Detection on Streaming Data
Advanced Threat Detection on Streaming Data
 

REST dojo Comet

  • 1. REST, dojo, Comet Carol McDonald, Java Architect
  • 2.
  • 3.
  • 5. RESTful Slideshow using JAX-RS and comet
  • 7.
  • 8.
  • 9. HTTP Example Request GET /catalog/items HTTP/1.1 Host: petstore.com Accept: application/xml Response HTTP/1.1 200 OK Date: Tue, 08 May 2007 16:41:58 GMT Server: Apache/1.3.6 Content-Type: application/xml; charset=UTF-8 <?xml version=&quot;1.0&quot;?> <items xmlns=&quot;…&quot;> <item>…</item> … </items> Method Resource Representation State transfer
  • 10.
  • 12. Example RESTful Catalog Service Catalog Database Web container (GlassFish™) + REST API Browser (Firefox) HTTP
  • 13.
  • 14. POJO @Path(&quot;/items/&quot;) public class ItemsResource { @Produces(&quot;application/json&quot;) @GET public ItemsConverter get() { ... } ... } responds to the URI http://host/catalog/items/ responds with JSON responds to HTTP GET
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. ItemConverter JAXB annotated @XmlRootElement(name = &quot;item&quot;) public class ItemConverter { private Item entity; private URI uri; @XmlAttribute public URI getUri() { return uri; } @XmlElement public Long getId() { return (expandLevel > 0) ? entity.getId() : null; } ... }
  • 20. XML <item uri=&quot;http://localhost/Web/resources/items/1/&quot; > <description> black cat is nice</description> <id>1</id> <imagethumburl>/images/anth.jpg</imagethumburl> <name>not Friendly Cat</name> <price>307.10</price> <productid>feline01</productid> </item>
  • 21.
  • 22. ItemsConverter JAXB annotated @XmlRootElement(name = &quot;items&quot;) public class ItemsConverter { private Collection<ItemConverter> items; private URI uri; @XmlAttribute public URI getUri() { return uri; } @XmlElement public Collection<ItemConverter> getItem() { ... return items; } }
  • 23. XML <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <items uri=&quot;http://localhost/Web/resources/items/&quot;> <item uri=&quot;http://localhost/Web/resources/items/1/&quot; > <description> black cat is nice</description> <id>1</id> <imagethumburl>/images/anth.jpg</imagethumburl> <name>not Friendly Cat</name> <price>307.10</price> <productid>feline01</productid> </item> <item . . . </item> </items>
  • 24.
  • 25.
  • 26. Get Items @Path(&quot;/items/&quot;) public class ItemsResource { @Context protected UriInfo uriInfo; @GET @Produces (&quot;application/json&quot;) public ItemsConverter get(){ return new ItemsConverter( getEntities(), uriInfo.getAbsolutePath()); } Performs JPA Query, returns list of entities JAXB class responds with JSON responds to the URI http://host/catalog/items/ responds to HTTP GET
  • 27. Get Item @Path(&quot;/items/&quot;) public class ItemsResource { @Path(&quot;{id}/&quot;) public ItemResource getItemResource( @PathParam (&quot;id&quot;) Long id) { return new ItemResource (id, context); } } public class ItemResource { @GET @Produces ( &quot;application/json&quot;) public ItemConverter get() { return new ItemConverter(getEntity(), context.getAbsolutePath(), expandLevel); } JAXB class http://host/catalog/items/123
  • 28. Dojo Client Side JavaScript Library
  • 29.
  • 30.
  • 31. Loading d ojo
  • 32.
  • 33.
  • 34.
  • 35.
  • 36. Run File themeTester.html
  • 37. Try out dojo dijit widgets
  • 38.
  • 39.
  • 40. Dijit = d ojo Widget
  • 41. dijit is a UI widget system layered on top of dojo The dojo Widget Library
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 49.
  • 50. XMLHttpRequest (XHR): dojo.xhrDelete(), dojo.xhrGet(), dojo.xhrPost(), dojo.xhrPut()
  • 51. Traditional Web AJAX within a browser, there is AJAX engine
  • 52. RESTful Pet Catalog Web Service http://petstore/catalog/resources/items/ HTTP GET {&quot;url&quot;:&quot;http://store/catalog/item1&quot;, {&quot;url&quot;:&quot;http://store/catalog/item2&quot;} Response JSON slide urls Server Client Addressable Resources Web Container
  • 53.
  • 54.
  • 56. Dojo client index.html <button dojoType=&quot;dijit.form.Button&quot; onclick=&quot; next &quot;> Next </button> <div id=&quot;grid&quot; dojoType =&quot; dojox.Grid &quot; model =&quot; model &quot; structure=&quot; layout &quot; autoWidth=&quot;true&quot; > http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c.html Grid widget
  • 57. Dojo client.js formatImage = function(value) { if (!value) return '&nbsp;'; return &quot;<img src='&quot; + value + &quot;'/>&quot;; }; // Data Grid layout // A grid view is a group of columns var view1 = { cells: [ [ {name: 'Name', field: &quot;name&quot;}, {name: 'Description', field: &quot;description&quot;}, {name: 'Photo',field: &quot;imagethumburl&quot;, formatter: formatImage , }, {name: 'Price',field: &quot;price&quot;} ] ] }; // a grid layout is an array of views. var layout = [ view1 ]; // the model= collection of objects to be displayed in the grid model = new dojox.grid.data.Objects(null,null);
  • 58. Dojo client.js // make request to the items web service function loadTable (page){ start = page * batchSize; var targetURL = &quot;resources/items/?start=&quot;+ encodeURIComponent(start); dojo.xhrGet ({ url: targetURL , handleAs: &quot;json&quot;, load: handleResponse , error: handleError }); } // Process the response from the items web service function handleResponse ( responseObject , ioArgs){ // set the model object with the returned items list model .setData( responseObject.items.item ); } function next() { page =page + 1; loadTable (page); } Performs HTTP GET on url catalog/items
  • 59. COMET
  • 60. Comet: the server pushes data to the client over a long-lived HTTP connection Server Client 1 Client 2
  • 61.
  • 62.
  • 63. Blocking http request =server catastrophe GET /updates HTTP/1.1 Connection: keep-alive GET /updates HTTP/1.1 Connection: keep-alive GET /updates HTTP/1.1 Connection: keep-alive GET /updates HTTP/1.1 Connection: keep-alive GET /updates HTTP/1.1 Connection: keep-alive
  • 64.
  • 65.
  • 66. Server-side Ajax Push: Who supports what The asynchronicity matrix. X WebLogic Container Asynchronous IO Suspendible Request/ Response Delivery Guarantee Jetty X Tomcat X X GlassFish X X X Resin X
  • 67.
  • 68. Bayeux HTTP Publish Subscribe protocol for routing JSON -encoded events between clients and servers in a publish-subscribe model Grizzly provides an implementation of Bayeux Just configure Glassfish domain.xml and Web App web.xml
  • 69.
  • 70.
  • 71. Enable Comet in GlassFish V2 Admin Console
  • 72.
  • 73.
  • 74. RESTful Web Services and Comet http://developers.sun.com/appserver/reference/techart/cometslideshow.html
  • 75. RESTful Slideshow Web Service http://host/slideshow/resources/slides/ HTTP GET {&quot;url&quot;:&quot;http://host/slideshow/image1.jpg&quot;, {&quot;url&quot;:&quot;http://host/slideshow/image2.jpg&quot;} Response JSON slide urls Server Client Addressable Resources Web Container
  • 76. Cometd Step1 : Initialize dojo.require(&quot; dojox.cometd &quot;); //Initialize a connection to the given Comet server: the GlassFish Grizzly Bayeux servlet dojox.cometd. init (&quot;serverURL&quot;); Comet Server Client 1 Client 2
  • 77.
  • 78.  
  • 79.  
  • 80. Cometd Step 3: Publish dojox.cometd. publish (&quot;topic&quot;, {slide: url}); a client publishes the next slide url to the topic channel JSON message client 1 Comet Server Next slide url
  • 81.  
  • 82.
  • 83.  
  • 84.
  • 85. RESTful Web Services and Comet http://developers.sun.com/appserver/reference/techart/cometslideshow.html
  • 86. RESTful Web Services http://netbeans.tv/screencasts/offset/7/
  • 87. Example RESTful Catalog http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c.html
  • 88.
  • 89.

Editor's Notes

  1. Representational State Transfer (REST) is a style of software architecture for distributed systems such as the World Wide Web. The term was introduced in the doctoral dissertation of Roy Fielding in 2000, and has since come into widespread use in the networking community. An important concept in REST is the existence of resources, each of which can be referred to using a global identifier, that is, a URI. In order to manipulate these resources, components of the network, clients and servers, communicate using a standardized interface such as HTTP and exchange representations of these resources.
  2. What Are RESTful Web Services? Representational State Transfer (REST) is a software application architecture modeled after the way data is represented, accessed, and modified on the web. In the REST architecture, data and functionality are considered resources, and these resources are accessed using Uniform Resource Identifiers (URIs), typically links on the web. The resources are acted upon by using a set of simple, well-defined operations. The REST architecture is designed to use a stateless communication protocol, typically HTTP. In the REST architecture, clients and servers exchange representations of resources using a standardized interface and protocol. These principles encourages REST applications to be simple, lightweight, and have high performance. RESTful web services are web applications built upon the REST architecture. They: expose resources (data and functionality) through web URIs use the four main HTTP methods to create, retrieve, update, and delete resources RESTful web services typically map the four main HTTP methods to the so-called CRUD actions: create, retrieve, update, and delete. The following table shows a mapping of HTTP methods to these CRUD actions.
  3. Use an annotation to mark the methods that you want the runtime to to call to service the http request. Can either put http method in the annotation or in the method
  4. The uniform interface also enables every component that understands the HTTP application protocol to interact with your application. Examples of components that benefit from this are generic clients such as curl and wget, proxies, caches, HTTP servers, gateways, even Google/Yahoo!/MSN, and many more. To summarize: For clients to be able to interact with your resources, they should implement the default application protocol (HTTP) correctly, i.e. make use of the standard methods GET, PUT, POST, DELETE.
  5. UriTemplate annotation defines the URI Template to which the resource responds, HTTP methods are mapped to Java programming language methods using the HttpMethod annotation. @ProduceMime annotation is used to specify the MIME types a resource can produce and send back to the client. variables are specified as parameters to the method by decoration the parameter location with a @UriParam annotation when the method is called the id will be put into the artist parameter by the runtime
  6. To obtain an container managed EntityManager instance, inject the entity manager into the application component: @PersistenceContext EntityManager em; you don&apos;t need any cm lifecycle methods With a container-managed entity manager, an EntityManager instance&apos;s persistence context is automatically propagated by the container to all application components that use the EntityManager instance within a single Java Transaction Architecture (JTA) transaction. JTA transactions usually involve calls across application components. To complete a JTA transaction, these components usually need access to a single persistence context. This occurs when an EntityManager is injected into the application components via the javax.persistence.PersistenceContext annotation. The persistence context is automatically propagated with the current JTA transaction, and EntityManager references that are mapped to the same persistence unit provide access to the persistence context within that transaction. By automatically propagating the persistence context, application components don&apos;t need to pass references to EntityManager instances to each other in order to make changes within a single transaction. The Java EE container manages the lifecycle of container-managed entity managers.
  7. To obtain an container managed EntityManager instance, inject the entity manager into the application component: @PersistenceContext EntityManager em; you don&apos;t need any cm lifecycle methods With a container-managed entity manager, an EntityManager instance&apos;s persistence context is automatically propagated by the container to all application components that use the EntityManager instance within a single Java Transaction Architecture (JTA) transaction. JTA transactions usually involve calls across application components. To complete a JTA transaction, these components usually need access to a single persistence context. This occurs when an EntityManager is injected into the application components via the javax.persistence.PersistenceContext annotation. The persistence context is automatically propagated with the current JTA transaction, and EntityManager references that are mapped to the same persistence unit provide access to the persistence context within that transaction. By automatically propagating the persistence context, application components don&apos;t need to pass references to EntityManager instances to each other in order to make changes within a single transaction. The Java EE container manages the lifecycle of container-managed entity managers.
  8. Dojo toolkit is open source DHTML toolkit written in JavaScript. In other words, it is a set of JavaScript libraries. Dojo toolkit aims to solve some long-standing historical problems with DHTML such as browser incompatibility. Dojo toolkit also allows you easily add dynamic capabilites into the web pages by the usage of pre-built widgets and animations. Because it is only client-side technology, it can work with any server side technology.
  9. Think of Base as the kernel of the toolkit. It&apos;s a tiny library wrapped up into a single JavaScript file ( dojo.js ) that provides the foundation for everything in the toolkit. Among other things, Base handles bootstrapping the toolkit, includes convenient language and AJAX utilities, provides mechanisms for simulating class-based inheritance, offers a slick packaging system that preserves the global namespace, and more. Core builds on Base by providing additional facilities for accessing data stores, providing effects such as wipes/slides, internationalization (i18n), and back-button handling among other things. For the most part, any module or resource associated with the dojo namespace that you have to explicitly import into the page is part of Core. Dijit is shorthand for &amp;quot;Dojo widget&amp;quot; and, depending on the context and capitalization, could refer to a single Dojo widget (a dijit) or to the entire component of the toolkit containing all of Dojo&apos;s widgets (Dijit). Dijit directly leverages the power of Base and Core to provide a powerful widget layer that&apos;s highly usable and simple in design. DojoX stands for &amp;quot;Dojo Experimental&amp;quot; and contains features that stand a chance of one day migrating into Core, Dijit, or even a new Dojo module that doesn&apos;t exist yet. Think of DojoX as an incubator or sandbox
  10. download nothing and simply pull Dojo from a CDN near you: * AOL: &lt;SCRIPT TYPE=&amp;quot;text/javascript&amp;quot; SRC=&amp;quot;http://o.aolcdn.com/dojo/1.2.0/dojo/dojo.xd.js&amp;quot;&gt;&lt;/SCRIPT&gt; * Google: &lt;SCRIPT TYPE=&amp;quot;text/javascript&amp;quot; SRC=&amp;quot;http://ajax.googleapis.com/ajax/libs/dojo/1.2.0/dojo/dojo.xd.js&amp;quot;&gt;&lt;/SCRIPT&gt;
  11. Use Dojo from a CDN or download and follow these simple steps: 1. Extract files from the download locally or on a web server. 2. Include &lt;SCRIPT TYPE=&amp;quot;text/javascript&amp;quot; SRC=&amp;quot;dojo/dojo.js&amp;quot;&gt;&lt;/SCRIPT&gt; and you&apos;re on your way. 3. Browse to dojo/tests/runTests.html or dijit/themes/themeTester.html to see Dojo in action The most important thing to know when installing the Dojo Toolkit is where your copy of dojo.js is located. The package system handles the loading of all other dependencies and modules once dojo.js has been loaded into the page.
  12. The &lt;script&gt; tag pulls the Dojo code from your server. The djConfig=&amp;quot; parseOnLoad:true&amp;quot; attribute is required to use Dojo elements declaratively. To use Firebug Lite, you must include the isDebug config parameter. This parameter has no effect on Firefox browsers with Firebug already present. So including this parameter makes your debugging code usable in IE, Safari, and Firefox with no changes.
  13. The &lt;script&gt; tag pulls the Dojo code from your server. The djConfig=&amp;quot; parseOnLoad:true&amp;quot; attribute is required to use Dojo elements declaratively. To use Firebug Lite, you must include the isDebug config parameter. This parameter has no effect on Firefox browsers with Firebug already present. So including this parameter makes your debugging code usable in IE, Safari, and Firefox with no changes.
  14. What is a widget? You probably have some idea already on what it is. It is a UI element such as a button, text box, scroll bar, calendar, tree and so on. Widgets are a lot easier to deal with than manipulating HTML page with DOM APIs. A widget can be a composite element meaning it could be made of other widgets. A widget can have a custom style so that it can be presented on a page in a particular style. And of course, event handlers can be registered or attached. The event handlers then might call backend service using AJAX-based asynchronous calls.
  15. The @import rule loads the Dojo stylesheet and the theme Tundra. a theme is a set of fonts, colors... for components . Three themes come prepackaged with Dijit—Tundra, Soria, and Nihilo.You must always import dojo.css, but if you’re using Dojo without Dijit, you can omit the theme style sheet import. The &lt;script&gt; tag pulls the Dojo code from your server. The djConfig=&amp;quot; parseOnLoad:true&amp;quot; attribute is required to use Dojo elements declaratively. you set the class of the body to match the theme. In this example tundra. It is also possible to create a custom build of Dojo, which eliminates the need for dojo.require() by putting everything in dojo.js .
  16. You can use the built-in widgets just by adding them in your html or jsp pages. There are many widgets that come with Dojo toolkit already and more are being created by community members. An attribute is a data element used for controlling display or behavior. A method is a function you call to control something. An extension point is a function you provide to override behavior.
  17. This is how you add editor widget to your page. First, you indicates that you would need “dojo.widget.Editor” package. Then you use dojoType attribute to the &lt;div&gt; element. The “items” attribute specifies the list of icons.
  18. You can use the built-in widgets just by adding them in your html or jsp pages. There are many widgets that come with Dojo toolkit already and more are being created by community members.
  19. You can use the built-in widgets just by adding them in your html or jsp pages. There are many widgets that come with Dojo toolkit already and more are being created by community members.
  20. So how does AJAX application performs the asynchronous communication with the server? This slide also compares conventional web application and AJAX application. In the left side, which shows the conventional web application, HTTP request/response interaction occurs directly between a browser and a backend web application. In the right side, which shows AJAX based web application, within a browser, there is AJAX engine, which is actually represented by a JavaScript object called XMLHttpRequest which handles the HTTP request/response interaction in an asynchronous fashion.
  21. Connecting an Event to the Widget A button is all well and good, but what about getting it to do something when it&apos;s clicked? We could just specify an onClick event handler for the button, but there&apos;s another, more efficient way - the Dojo event system! The easiest way to attach an event to a button is through a script tag. But not just any script tag ... this one has a type of dojo/method, like this:
  22. When a message is published to a Bayeux channel on the server, it is delivered to all clients subscribed to that channel, in this case to the &amp;quot;/chat/demo&amp;quot; channel . The _chat callback function, is called with the published message as an input argument. The _chat callback function updates the browser page by setting the slide dom element innerHTML to an html img tag with the slide url from the published message &amp;quot;&lt;img src=&apos;&amp;quot; + slideUrl + &amp;quot;&apos;/&gt;&amp;quot; . This updates the browser page with the image corresponding to the slide URL which was published.
  23. Grizzly is an HTTP framework. It uses all the NIO facilities and provides people an easy to use, high performance API for socket communications. Grizzly actually has a couple of different modes. It has a blocking mode and a non-blocking mode. But, for the purpose of here, we are primarily interested in the non-blocking implementation. In fact, all the implementations that we deal with are going to be the non-blocking implementation Grizzly. So Grizzly essentially, its point is to bring these non-blocking sockets to the HTTP processing layer. Later on, as we will see in the benchmarks, that&apos;s what gives us the high-performance HTTP processing. Grizzly is written architecturally as a connector within Tomcat. Our app server likes a large number of application servers leverages the Coyote implementation for the web container. Coyote is used in Tomcat 3,4, 5. It&apos;s used in our app servers. The Coyote architecture you can stick this thing called a connector in front of the actual Coyote section, which does the JSP and servlet processing. The Grizzly part is actually the small little piece that only responsible for handling communications with the clients and then it passes it off to Coyote to do the actual work. So, it can utilize Coyote&apos;s buffers, and processing parsing classes and all that sort of work. It &apos;s not the full HTTp engine, it is just that part that manages connections.
  24. Grizzly is an HTTP framework. It uses all the NIO facilities and provides people an easy to use, high performance API for socket communications. Grizzly actually has a couple of different modes. It has a blocking mode and a non-blocking mode. But, for the purpose of here, we are primarily interested in the non-blocking implementation. In fact, all the implementations that we deal with are going to be the non-blocking implementation Grizzly. So Grizzly essentially, its point is to bring these non-blocking sockets to the HTTP processing layer. Later on, as we will see in the benchmarks, that&apos;s what gives us the high-performance HTTP processing. Grizzly is written architecturally as a connector within Tomcat. Our app server likes a large number of application servers leverages the Coyote implementation for the web container. Coyote is used in Tomcat 3,4, 5. It&apos;s used in our app servers. The Coyote architecture you can stick this thing called a connector in front of the actual Coyote section, which does the JSP and servlet processing. The Grizzly part is actually the small little piece that only responsible for handling communications with the clients and then it passes it off to Coyote to do the actual work. So, it can utilize Coyote&apos;s buffers, and processing parsing classes and all that sort of work. It &apos;s not the full HTTp engine, it is just that part that manages connections.
  25. Bayeux’s concept of channels allows multiple decoupled conversations on top of a single HTTP connection. The client-side Cometd object and server-side Bayeux implementation communicate over several notional channels all bundled within a single HTTP request-response pair.
  26. JOSN data needs to to be parsed by browser, and this may introduce in sufficient and insecure problems, so the other way of doing it is by using the primitive xml parser. Server does not really participate, it is a reflector to send the message to the right chat room. Server just peer to peer mediates the messages to the right channel. Server can implement in any languages, java, python, ... Because server is not involved, it takes less benefit from the server side data.
  27. # Add the following property in between the http-listener start and end tags: &lt;property name=&amp;quot;cometSupport&amp;quot; value=&amp;quot;true&amp;quot;/&gt; o enable the Bayeux protocol on the Enterprise Server, you must reference the CometdServlet in your web application&apos;s web.xml file. In addition, if your web application includes a servlet, set the load-on-startup value for your servlet to 0 (zero) so that it will not load until the client makes a request to it.
  28. Grizzly is an HTTP framework. It uses all the NIO facilities and provides people an easy to use, high performance API for socket communications. Grizzly actually has a couple of different modes. It has a blocking mode and a non-blocking mode. But, for the purpose of here, we are primarily interested in the non-blocking implementation. In fact, all the implementations that we deal with are going to be the non-blocking implementation Grizzly. So Grizzly essentially, its point is to bring these non-blocking sockets to the HTTP processing layer. Later on, as we will see in the benchmarks, that&apos;s what gives us the high-performance HTTP processing. Grizzly is written architecturally as a connector within Tomcat. Our app server likes a large number of application servers leverages the Coyote implementation for the web container. Coyote is used in Tomcat 3,4, 5. It&apos;s used in our app servers. The Coyote architecture you can stick this thing called a connector in front of the actual Coyote section, which does the JSP and servlet processing. The Grizzly part is actually the small little piece that only responsible for handling communications with the clients and then it passes it off to Coyote to do the actual work. So, it can utilize Coyote&apos;s buffers, and processing parsing classes and all that sort of work. It &apos;s not the full HTTp engine, it is just that part that manages connections.
  29. In chat.js, the application uses the dojo.require function (similar to the import directive in Java) to specify which Dojo modules to load. the call to dojox.cometd.init initialises a connection to the given Comet server, in this case with the Glassfish Grizzly Bayeux servlet (note /cometd/* is the url-pattern for the Grizzly Cometd Servlet configured in the web.xml for the application).
  30. The dojox.cometd.subscribe line subscribes the callback function to the topic channel. Any time a message is sent to the topic channel the callback function will be called.
  31. The function room.next, shown below, calls dojox.cometd.publish to publish the next slide url (input argument) to the /chat/demo channel. Subscribers to the /chat/demo channel will get this message.
  32. When a message is published to a Bayeux channel on the server, it is delivered to all clients subscribed to that channel, in this case to the &amp;quot;/chat/demo&amp;quot; channel . The _chat callback function, is called with the published message as an input argument. The _chat callback function updates the browser page by setting the slide dom element innerHTML to an html img tag with the slide url from the published message &amp;quot;&lt;img src=&apos;&amp;quot; + slideUrl + &amp;quot;&apos;/&gt;&amp;quot; . This updates the browser page with the image corresponding to the slide URL which was published.