an introduction to struts 2 and restful applications
DESCRIPTION
Presentation given by Don Brown at OSDC Sydney 2008TRANSCRIPT
![Page 2: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/2.jpg)
![Page 3: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/3.jpg)
![Page 4: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/4.jpg)
![Page 5: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/5.jpg)
![Page 6: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/6.jpg)
![Page 7: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/7.jpg)
![Page 8: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/8.jpg)
![Page 9: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/9.jpg)
![Page 10: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/10.jpg)
What’s wrong with my web application?
Modern web framework
Presentation and business logic separation
Code not tied to HTTP
![Page 11: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/11.jpg)
Problem: Confusing URIs
GEThttp://localhost/spaces/addspacenotification.action?key=AJOBS
GEThttp://localhost/spaces/addspacenotification.action?key=AJOBS
GEThttp://localhost/spaces/addspacenotification.action?key=AJOBS
GEThttp://localhost/spaces/addspacenotification.action?key=AJOBS
![Page 12: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/12.jpg)
Problem: Poor caching
HTTP traffic laws broken:
GET - Could be anything,including deletes andupdates
POST - Also could beanything, even regularpage views
PUT - Not used
DELETE - Not used
![Page 13: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/13.jpg)
Problem: People can’t get at their data
![Page 14: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/14.jpg)
REST is the Way of the Web
![Page 15: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/15.jpg)
Not just for Web Services
http://www.flickr.com/photos/psd/2217422218/
![Page 16: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/16.jpg)
Solution: Humane URIs
GET
http://localhost/spaces/addspacenotification.action?key=AJOBS
POST
http://localhost/spaces/AJOBS/notifications
GET
http://localhost/spaces/AJOBS/notifications/3
PUT
http://localhost/spaces/AJOBS/notifications/3
DELETE
http://localhost/spaces/AJOBS/notifications/3
![Page 17: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/17.jpg)
Solution: Scalable caching
Follow HTTP traffic laws:
GET - No side-effects, canrepeat
POST - Changes state,cannot repeat
PUT - Changes state, canrepeat
DELETE - Changes state,can repeat
![Page 18: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/18.jpg)
Solution: One API for all
![Page 19: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/19.jpg)
REST in action
![Page 20: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/20.jpg)
Detour: Struts 2
![Page 21: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/21.jpg)
Struts 2 History
![Page 22: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/22.jpg)
Struts 2 plugins
![Page 23: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/23.jpg)
Struts 2 Codebehind Plugin
http://example.com/myapp/public/profile.xhtml
Calls:
com.example.myapp.actions.public.ProfileAction
Forwards to:
/WEB-INF/jsp/public/profile.jsp
![Page 24: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/24.jpg)
Struts 2 REST Plugin
edit()GET/orders/3/edit
editNew()GET/orders/new
destroy()DELETE/orders/3
update()PUT/orders/3
create()POST/orders
show()GET/orders/3
index()GET/orders
Action MethodHTTP MethodURI
![Page 25: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/25.jpg)
A RESTful example: orders
. . . Let’s see some code!
![Page 26: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/26.jpg)
REST in the real world
![Page 27: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/27.jpg)
Not everything is a resource
Account:
• GET . . . Yep
• POST . . . Yep
• PUT . . . Yep
• DELETE . . . Yep
• Renew?
![Page 28: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/28.jpg)
Account Renewal: resource or operation?
Renew as a ResourcePOST:
http://localhost/accounts/3/renewals
Renew as an OperationPOST
http://localhost/accounts/3/renew
![Page 29: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/29.jpg)
REST is training friendly
![Page 30: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/30.jpg)
RESTWS-*
V.S.
UDDI*
WS-Security*
JAXB
AXIS/CXF
SOAP
XML Schema
XML *WSDL
HTTPXML
![Page 31: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/31.jpg)
Clients are and aren’t free
But not
![Page 32: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/32.jpg)
REST: the silver bullet?
![Page 33: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/33.jpg)
The takeaway: apply REST to your app
![Page 34: An introduction to Struts 2 and RESTful applications](https://reader033.vdocuments.site/reader033/viewer/2022051609/547b9e90b47959a9098b4da3/html5/thumbnails/34.jpg)
Questions?
http://struts.apache.org/2.x/docs/rest-plugin.html