SlideShare a Scribd company logo
1 of 16
Introducing DWR (Direct Web
                 Remoting)
       BOOBUN Ashish – 20th November 2009
Agenda
   Ajax
   Introduction to DWR
   Steps to create a DWR web application
   DWR configurations
   Callback Mechanism
   Converters
   DWR .js file
   Comet with DWR
   Advantages
AJAX
   Asynchronous JavaScript and XML
   Collection of technologies used on client site to develop interactive
    web application
        Document Object Model (DOM)
        XML, JSON, HTML, plain text
        XMLHttpRequest (XHR) – for asynchronous
         communication
        JavaScript
   Retrieve data asynchronously from server while preserving the
    current state of the user interface
   Services on server had to be accessed via URL, with request
    parameters. For e.g. http://www.google.co.uk/search?q=ajax
AJAX in Action




                 Google is intelligent
DWR Explained
   An open source library that resides between Java and JavaScript
    code.
   An implementation of AJAX in Java.
   Enables Java code on the server and JavaScript code in a browser
    to interact and call each other as simply as possible.
      Making the process resemble as a “Remote Procedure call”.
      Handles the low-level communication using the
        XMLHttpRequest object.
   DWR consists of two parts:
      A Java Servlet on the server to capture DWR’s request and
       sends response back to the browser
      JavaScript on browser side that handles request and response
       and dynamically update part of the web page accordingly.
Why DWR - NO to boiler-plate code
Steps to create a DWR-enable AJAX
application
   Add maven dependency for DWR
   Add DWR servlet and DWR servlet mapping in web.xml
   Write Java service class and its corresponding methods
   Include DWR configuration (in spring bean configuration
    file, if using DWR v2.x. Else specify in dwr.xml if using
    v1.x) to state what classes and method of the backend
    will be exposed.
       Note that we will be integrating DWR with Spring
   Write client-side JavaScript code and invoke methods
    that has been exposed in an RPC style.
Requirements
   Maven Dependency




   Web.xml
DWR Configuration




   The tag <dwr:configuration> must be present (if defining
    dwr configurations in the spring bean configuration file
    and not in dwr.xml file), even if it’s empty.
Client-side JavaScript code

 DWR includes 2 plain JavaScript files: engine.js (compulsory) and util.js
  (optional).
 OutboundService.js is a dynamically generated .js file that interfaces with
  engine.js to invoke methods exposed on the server.




   Notice the RPC-style syntax – OutboundService.getOutboundList()
Handling Asynchronous Calls
 Data is available some time after the initial call was made.
 How to combine the asynchronous nature of Ajax with the
  synchronous nature of normal Java method calls?
 DWR provides call-back method mechanism.
 Call-back function is called when data is received from the server.
Converters
   Marshall data when it is sent between client and server
   DWR provides the following converters
       Basic and Date Converters (By default it is enable)
       Bean and Object converters - convert Java Beans and
        POJOs to and from JavaScript objects
       Array Converters
       Collection Converters
       DOM Converters

   E.g. <dwr:convert type="bean
    class="com.tnt.express.mww.walldisplay.dto
    .Outbound" />
DWR .js files
   Engine.js
      Used to marshal calls from the dynamically generated interface
       JavaScript function, so it is needed wherever DWR is used.
      Also contain set option methods related to timeout, errorHandler,
       warningHandler.

   Util.js
      Contains a number of utility functions to help you update your
        web pages with JavaScript data
      Can use it outside of DWR scope

      E.g. of utility methods
            $(id) – document.getElementById(id)
            DWRUtil.getValue(id) – get the value of the HTML element with id.
Comet with DWR
   Long-lived HTTP
   Reversing the usual communication flow
   Allow the server to start answering the browser’s
    request for information very slowly by pushing data to
    the browser without the latter ever explicitly requesting it
   Disadvantage:
       Server can be overloaded with too many connection
       Server takes too much time to push data in IE 6 browser
Advantages of using DWR
   DWR uses an “RPC-style mechanism” whereas almost all other forms
    of AJAX take a URL-based approach.
      DWR eliminate the needs of having each method (service) on the
        server to be addressable via URL.
   No need to map parameters and return value to HTML input form and
    responses respectively.
   DWR is packaged with JavaScript utility functions that allows you to
    dynamically modify HTML tags.
   The code for the service class is a simple POJO, and not tied to HTTP
    at all. Easier to unit test.
                                      You can write AJAX web app at
                                       the same rate as Jack Bauer
                                              works at CTU
   Codes is simpler, less verbose.
Question???

More Related Content

What's hot

What's hot (20)

Construindo portlets para IBM WebSphere Portal – Parte 1
Construindo portlets para IBM WebSphere Portal – Parte 1Construindo portlets para IBM WebSphere Portal – Parte 1
Construindo portlets para IBM WebSphere Portal – Parte 1
 
Designing High Availability for HashiCorp Vault in AWS
Designing High Availability for HashiCorp Vault in AWSDesigning High Availability for HashiCorp Vault in AWS
Designing High Availability for HashiCorp Vault in AWS
 
Elasticsearch for Data Analytics
Elasticsearch for Data AnalyticsElasticsearch for Data Analytics
Elasticsearch for Data Analytics
 
Application Autoscaling Made Easy with Kubernetes Event-Driven Autoscaling (K...
Application Autoscaling Made Easy with Kubernetes Event-Driven Autoscaling (K...Application Autoscaling Made Easy with Kubernetes Event-Driven Autoscaling (K...
Application Autoscaling Made Easy with Kubernetes Event-Driven Autoscaling (K...
 
A brief study on Kubernetes and its components
A brief study on Kubernetes and its componentsA brief study on Kubernetes and its components
A brief study on Kubernetes and its components
 
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
 
Helm - the Better Way to Deploy on Kubernetes - Reinhard Nägele - Codemotion...
 Helm - the Better Way to Deploy on Kubernetes - Reinhard Nägele - Codemotion... Helm - the Better Way to Deploy on Kubernetes - Reinhard Nägele - Codemotion...
Helm - the Better Way to Deploy on Kubernetes - Reinhard Nägele - Codemotion...
 
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)
 
Red Hat Insights
Red Hat InsightsRed Hat Insights
Red Hat Insights
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
 
Expressjs
ExpressjsExpressjs
Expressjs
 
Java agents for fun and (not so much) profit
Java agents for fun and (not so much) profitJava agents for fun and (not so much) profit
Java agents for fun and (not so much) profit
 
Chapter 1 - Web Design
Chapter 1 - Web DesignChapter 1 - Web Design
Chapter 1 - Web Design
 
React
React React
React
 
ATO 2022 - Machine Learning + Graph Databases for Better Recommendations (3)....
ATO 2022 - Machine Learning + Graph Databases for Better Recommendations (3)....ATO 2022 - Machine Learning + Graph Databases for Better Recommendations (3)....
ATO 2022 - Machine Learning + Graph Databases for Better Recommendations (3)....
 
CIDOC CRM Tutorial
CIDOC CRM TutorialCIDOC CRM Tutorial
CIDOC CRM Tutorial
 
Intro to Helm for Kubernetes
Intro to Helm for KubernetesIntro to Helm for Kubernetes
Intro to Helm for Kubernetes
 
Easy tests with Selenide and Easyb
Easy tests with Selenide and EasybEasy tests with Selenide and Easyb
Easy tests with Selenide and Easyb
 

Viewers also liked

Framework MVC - vRaptor
Framework MVC - vRaptorFramework MVC - vRaptor
Framework MVC - vRaptor
Édipo Souza
 
Caelum java-web-vraptor-hibernate-ajax-fj28
Caelum java-web-vraptor-hibernate-ajax-fj28Caelum java-web-vraptor-hibernate-ajax-fj28
Caelum java-web-vraptor-hibernate-ajax-fj28
Valdinho Pereira
 

Viewers also liked (13)

Vraptor 3
Vraptor 3Vraptor 3
Vraptor 3
 
Framework MVC - vRaptor
Framework MVC - vRaptorFramework MVC - vRaptor
Framework MVC - vRaptor
 
Caelum java-web-vraptor-hibernate-ajax-fj28
Caelum java-web-vraptor-hibernate-ajax-fj28Caelum java-web-vraptor-hibernate-ajax-fj28
Caelum java-web-vraptor-hibernate-ajax-fj28
 
Apresentação VRaptor 3
Apresentação VRaptor 3Apresentação VRaptor 3
Apresentação VRaptor 3
 
Palestra VRaptor 3
Palestra VRaptor 3Palestra VRaptor 3
Palestra VRaptor 3
 
Apresentação sobre VRaptor na Campus Recife 2014
Apresentação sobre VRaptor na Campus Recife 2014Apresentação sobre VRaptor na Campus Recife 2014
Apresentação sobre VRaptor na Campus Recife 2014
 
Introdução ao vraptor
Introdução ao vraptorIntrodução ao vraptor
Introdução ao vraptor
 
Aula Introdução a VRaptor 4 - Pós Java UTFPR
Aula Introdução a VRaptor 4 - Pós Java UTFPRAula Introdução a VRaptor 4 - Pós Java UTFPR
Aula Introdução a VRaptor 4 - Pós Java UTFPR
 
Java Web Fácil com VRaptor
Java Web Fácil com VRaptorJava Web Fácil com VRaptor
Java Web Fácil com VRaptor
 
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...
VRaptor 3, JPA, Hibernate, Geotools e OpenLayers, ajudando Pedro Alvares Cabr...
 
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVA
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVAVRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVA
VRaptor - Um Framework MVC Web para desenvolvimento ágil com JAVA
 
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3
Dividindo responsabilidades com VRaptor, Rest, HTML5 e CSS3
 
VRaptor - Ciclo CASIN 2011
VRaptor - Ciclo CASIN 2011VRaptor - Ciclo CASIN 2011
VRaptor - Ciclo CASIN 2011
 

Similar to Introducing dwr (direct web remoting)

Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
dominion
 
Ajax with DWR
Ajax with DWRAjax with DWR
Ajax with DWR
gouthamrv
 
Web service- Guest Lecture at National Wokshop
Web service- Guest Lecture at National WokshopWeb service- Guest Lecture at National Wokshop
Web service- Guest Lecture at National Wokshop
Nishikant Taksande
 

Similar to Introducing dwr (direct web remoting) (20)

11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
Dwr
DwrDwr
Dwr
 
Dwr
DwrDwr
Dwr
 
SCDJWS 5. JAX-WS
SCDJWS 5. JAX-WSSCDJWS 5. JAX-WS
SCDJWS 5. JAX-WS
 
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
 
Web services in java
Web services in javaWeb services in java
Web services in java
 
Android chapter16-web-services
Android chapter16-web-servicesAndroid chapter16-web-services
Android chapter16-web-services
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Ajax with DWR
Ajax with DWRAjax with DWR
Ajax with DWR
 
Web service- Guest Lecture at National Wokshop
Web service- Guest Lecture at National WokshopWeb service- Guest Lecture at National Wokshop
Web service- Guest Lecture at National Wokshop
 
Day7
Day7Day7
Day7
 
Servlets
ServletsServlets
Servlets
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Ntg web services
Ntg   web servicesNtg   web services
Ntg web services
 
CHC 2009 - The Ccls Approach To Building M Pages
CHC 2009 - The Ccls Approach To Building M PagesCHC 2009 - The Ccls Approach To Building M Pages
CHC 2009 - The Ccls Approach To Building M Pages
 
Signal r
Signal rSignal r
Signal r
 
Direct Web Remoting : DWR
Direct Web Remoting : DWRDirect Web Remoting : DWR
Direct Web Remoting : DWR
 
Dot net training bangalore
Dot net training bangaloreDot net training bangalore
Dot net training bangalore
 
Java Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web ServicesJava Web Services [4/5]: Java API for XML Web Services
Java Web Services [4/5]: Java API for XML Web Services
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

Introducing dwr (direct web remoting)

  • 1. Introducing DWR (Direct Web Remoting) BOOBUN Ashish – 20th November 2009
  • 2. Agenda  Ajax  Introduction to DWR  Steps to create a DWR web application  DWR configurations  Callback Mechanism  Converters  DWR .js file  Comet with DWR  Advantages
  • 3. AJAX  Asynchronous JavaScript and XML  Collection of technologies used on client site to develop interactive web application  Document Object Model (DOM)  XML, JSON, HTML, plain text  XMLHttpRequest (XHR) – for asynchronous communication  JavaScript  Retrieve data asynchronously from server while preserving the current state of the user interface  Services on server had to be accessed via URL, with request parameters. For e.g. http://www.google.co.uk/search?q=ajax
  • 4. AJAX in Action Google is intelligent
  • 5. DWR Explained  An open source library that resides between Java and JavaScript code.  An implementation of AJAX in Java.  Enables Java code on the server and JavaScript code in a browser to interact and call each other as simply as possible.  Making the process resemble as a “Remote Procedure call”.  Handles the low-level communication using the XMLHttpRequest object.  DWR consists of two parts:  A Java Servlet on the server to capture DWR’s request and sends response back to the browser  JavaScript on browser side that handles request and response and dynamically update part of the web page accordingly.
  • 6. Why DWR - NO to boiler-plate code
  • 7. Steps to create a DWR-enable AJAX application  Add maven dependency for DWR  Add DWR servlet and DWR servlet mapping in web.xml  Write Java service class and its corresponding methods  Include DWR configuration (in spring bean configuration file, if using DWR v2.x. Else specify in dwr.xml if using v1.x) to state what classes and method of the backend will be exposed.  Note that we will be integrating DWR with Spring  Write client-side JavaScript code and invoke methods that has been exposed in an RPC style.
  • 8. Requirements  Maven Dependency  Web.xml
  • 9. DWR Configuration  The tag <dwr:configuration> must be present (if defining dwr configurations in the spring bean configuration file and not in dwr.xml file), even if it’s empty.
  • 10. Client-side JavaScript code  DWR includes 2 plain JavaScript files: engine.js (compulsory) and util.js (optional).  OutboundService.js is a dynamically generated .js file that interfaces with engine.js to invoke methods exposed on the server.  Notice the RPC-style syntax – OutboundService.getOutboundList()
  • 11. Handling Asynchronous Calls  Data is available some time after the initial call was made.  How to combine the asynchronous nature of Ajax with the synchronous nature of normal Java method calls?  DWR provides call-back method mechanism.  Call-back function is called when data is received from the server.
  • 12. Converters  Marshall data when it is sent between client and server  DWR provides the following converters  Basic and Date Converters (By default it is enable)  Bean and Object converters - convert Java Beans and POJOs to and from JavaScript objects  Array Converters  Collection Converters  DOM Converters  E.g. <dwr:convert type="bean class="com.tnt.express.mww.walldisplay.dto .Outbound" />
  • 13. DWR .js files  Engine.js  Used to marshal calls from the dynamically generated interface JavaScript function, so it is needed wherever DWR is used.  Also contain set option methods related to timeout, errorHandler, warningHandler.  Util.js  Contains a number of utility functions to help you update your web pages with JavaScript data  Can use it outside of DWR scope  E.g. of utility methods  $(id) – document.getElementById(id)  DWRUtil.getValue(id) – get the value of the HTML element with id.
  • 14. Comet with DWR  Long-lived HTTP  Reversing the usual communication flow  Allow the server to start answering the browser’s request for information very slowly by pushing data to the browser without the latter ever explicitly requesting it  Disadvantage:  Server can be overloaded with too many connection  Server takes too much time to push data in IE 6 browser
  • 15. Advantages of using DWR  DWR uses an “RPC-style mechanism” whereas almost all other forms of AJAX take a URL-based approach.  DWR eliminate the needs of having each method (service) on the server to be addressable via URL.  No need to map parameters and return value to HTML input form and responses respectively.  DWR is packaged with JavaScript utility functions that allows you to dynamically modify HTML tags.  The code for the service class is a simple POJO, and not tied to HTTP at all. Easier to unit test. You can write AJAX web app at the same rate as Jack Bauer works at CTU  Codes is simpler, less verbose.