Hariharasudhan Dhakshinamoorthy is an Architect working for UST Global. Before joining UST Global he was with Sonoa Systems, a SOA appliance company. And prior to Sonoa Systems he was with Infravio (a/k/a) Webmethods (a/k/a) SoftwareAG, a SOA Intermediatory and Registry product company. His areas of interest include SOA , Web2.0 technologies. When not at work he is interested in bikes, books, fishing.
* About this article
* What is REST?
* Direct Web Remoting
* Creating Restful Calculator Service
* Packaging/Deploying/Testing Calculator Service
* Conclusion
* Resources
About this article
This article talks about how REST architectural style be used in DWR , to invoke
pojo services.
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
and addressed.
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
https://ustri/resources/library/books
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
* Examples
Creating Restful Calculator Service
* step 1 : create a calculator class with add,subtract,mutiply,divide methods,
refer Resources/Calculator.java
* step 2 : create a ServletFilter ,
refer Resources/RESTFilter.java
* step 3 : Configure dwr.xml ,
refer Resources/dwr.xml
* step 4 : write client html ,
refer Resources/index.html
The methods inside Calculator
* addTwoNumbers(int,int)
* subtractTwoNumbers(int,int)
* multiplyTwoNumbers(int,int)
* divideTwoNumbers(int,int)
In a REST style representation of the above listed methods
* addTwoNumbers (https://..../addTwoNumbers/100/10/)
* subtractTwoNumbers (https://..../subtractTwoNumbers/100/10/)
* multiplyTwoNumbers (https://..../multiplyTwoNumbers/100/10/)
* divideTwoNumbers (https://..../divideTwoNumbers/100/10/)
This url https://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 :
Figure 1. addTwoNumbers
Conclusion
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.