RESTful POJO with DWR (Direct Web Remoting)
* About this article
* What is REST?
* Direct Web Remoting
* Creating Restful Calculator Service
* Packaging/Deploying/Testing Calculator Service
About this article
This article talks about how REST architectural style be used in DWR , to invoke
Adhering to the REST principles we will make your pojo's Restful.
What is REST?
The web is built on an architectural style called REST.
Any URL is a representation of some resource and REST refers to a
set of principles that outline how resources can be defined
REST is not a standard , it uses standards like
* HTTP , URL , XML,HTML,GIF,JPEG,etc (Resource Representations)
* text/xml, text/html, image/gif, image/jpeg, etc (MIME Types
Lets consider a library ,the library may define library resource.
The resource might be represented by a URL something like
A representation of the resource is returned in any of the standard mime type
(text/xml, text/html,image/gif, image/jpeg, etc).
Direct Web Remoting
Go through DWR if you haven't done.
Its good to have an understanding of these things listed below, before we start with
the Calculator Service.
* Basic of DWR
* DWR xml configuration
* DWR request types
Creating Restful Calculator Service
* step 1 : create a calculator class with add,subtract,mutiply,divide methods,
* step 2 : create a ServletFilter ,
* step 3 : Configure dwr.xml ,
* step 4 : write client html ,
The methods inside Calculator
In a REST style representation of the above listed methods
* addTwoNumbers (http://..../addTwoNumbers/100/10/)
* subtractTwoNumbers (http://..../subtractTwoNumbers/100/10/)
* multiplyTwoNumbers (http://..../multiplyTwoNumbers/100/10/)
* divideTwoNumbers (http://..../divideTwoNumbers/100/10/)
This url http://host:port/restws/addTwoNumbers/100/10/ is a representation of
"addTwoNumbers",100/10 are the values which are passed to it.
when a request is made to above url it passes through the servlet filter,
which inturn forwards the request to a client html page.
Servlet Filter acts as a Handler.
Packaging/Deploying/Testing Calculator Service
Packaging / Deploying:
* step 1: download dwr.war
* step 2: extract the war
* step 3: compile RESTFilter.java,Calculator.java,copy them inside \WEB-INF\classes\
* step 4: edit \WEB-INF\dwr.xml
* step 5: configure servlet filter RESTFilter in web.xml
* step 6: copy client html appropriately
* step 7: package it and deploy it
Testing Calculator Service :
Good thing about DWR
* Easy way to expose server-side java methods as services.
* Calling client doesn't deal with XMLHTTPRequest.
* No need to write object serialization code.
* Calculator.java for this article
* dwr.xml for this article
* HTML Client for this article