SlideShare a Scribd company logo
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

DOCX
Web services in java
PDF
11-DWR-and-JQuery
PDF
Android chapter16-web-services
PDF
Java web services using JAX-WS
PDF
Java Web Services [4/5]: Java API for XML Web Services
PDF
Introduction to SOAP/WSDL Web Services and RESTful Web Services
PDF
quickguide-einnovator-5-springxd
PDF
Jsp & Ajax
Web services in java
11-DWR-and-JQuery
Android chapter16-web-services
Java web services using JAX-WS
Java Web Services [4/5]: Java API for XML Web Services
Introduction to SOAP/WSDL Web Services and RESTful Web Services
quickguide-einnovator-5-springxd
Jsp & Ajax

What's hot (19)

PDF
Web service introduction
PDF
Java Web Services [2/5]: Introduction to SOAP
PDF
quickguide-einnovator-8-spring-cloud
PDF
Java Web Services [3/5]: WSDL, WADL and UDDI
PPTX
Session And Cookies In Servlets - Java
PPTX
Mule soap client demo
PPT
Oracle streams-step-by-step-ppt
PPTX
Java Servlet
PPT
WebService-Java
PPTX
Java on Windows Azure
PPTX
Web services
PDF
Windows Azure架构探析
PPTX
PPTX
JSP- JAVA SERVER PAGES
PDF
Java Web Services [1/5]: Introduction to Web Services
PPTX
Database connect
PPTX
Spring Web Services
PPT
Java web services
PDF
Lift Framework
Web service introduction
Java Web Services [2/5]: Introduction to SOAP
quickguide-einnovator-8-spring-cloud
Java Web Services [3/5]: WSDL, WADL and UDDI
Session And Cookies In Servlets - Java
Mule soap client demo
Oracle streams-step-by-step-ppt
Java Servlet
WebService-Java
Java on Windows Azure
Web services
Windows Azure架构探析
JSP- JAVA SERVER PAGES
Java Web Services [1/5]: Introduction to Web Services
Database connect
Spring Web Services
Java web services
Lift Framework
Ad

Viewers also liked (13)

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

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

PDF
11-DWR-and-JQuery
PDF
PPT
Ajax with DWR
PDF
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
PPT
Direct Web Remoting : DWR
PPTX
Dwr explanation
PPT
PPTX
Introduction to AJAX and DWR
PDF
Joe Walker Interactivewebsites Cometand Dwr
PDF
What's new in DWR version 3
PPT
Spring and DWR
PPT
CTS Conference Web 2.0 Tutorial Part 2
PPT
Week 10 Technical Stack I I 03
ODP
2010 07-20 TDD with ActiveResource
PPTX
06 web applications
PPTX
Building Restful Web Services with Java
PDF
RESTful Java With JAX RS 1st Edition Bill Burke
PDF
RESTful Java With JAX RS 1st Edition Bill Burke
PDF
Django Rest Framework - Building a Web API
11-DWR-and-JQuery
Ajax with DWR
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
Direct Web Remoting : DWR
Dwr explanation
Introduction to AJAX and DWR
Joe Walker Interactivewebsites Cometand Dwr
What's new in DWR version 3
Spring and DWR
CTS Conference Web 2.0 Tutorial Part 2
Week 10 Technical Stack I I 03
2010 07-20 TDD with ActiveResource
06 web applications
Building Restful Web Services with Java
RESTful Java With JAX RS 1st Edition Bill Burke
RESTful Java With JAX RS 1st Edition Bill Burke
Django Rest Framework - Building a Web API

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Spectroscopy.pptx food analysis technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Empathic Computing: Creating Shared Understanding
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation
Spectroscopy.pptx food analysis technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Unlocking AI with Model Context Protocol (MCP)
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Empathic Computing: Creating Shared Understanding
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
“AI and Expert System Decision Support & Business Intelligence Systems”
cuic standard and advanced reporting.pdf

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.