An introduction to Struts 2 and
RESTful applications

Don Brown
Atlassian
mrdon@twdata.org
What’s wrong with my web application?

 Modern web framework



 Presentation and business logic separation



 Code no...
Problem: Confusing URIs
GET
  http://localhost/spaces/addspacenotification.action?
    key=AJOBS

GET
  http://localhost/s...
Problem: Poor caching
HTTP traffic laws broken:
 GET - Could be anything,
  including deletes and
  updates
 POST - Also...
Problem: People can’t get at their data
REST is the Way of the Web
Not just for Web Services




              http://www.flickr.com/photos/psd/2217422218/
Solution: Humane URIs
GET
  http://localhost/spaces/addspacenotification.action?
    key=AJOBS


POST
  http://localhost/s...
Solution: Scalable caching
Follow HTTP traffic laws:
 GET - No side-effects, can
  repeat
 POST - Changes state,
  canno...
Solution: One API for all
REST in action
Detour: Struts 2
Struts 2 History
Struts 2 plugins
Struts 2 Codebehind Plugin
http://example.com/myapp/public/profile.xhtml



Calls:

com.example.myapp.actions.public.Profi...
Struts 2 REST Plugin

URI              HTTP Method   Action Method
/orders          GET           index()

/orders/3      ...
A RESTful example: orders




                  . . . Let’s see some code!
REST in the real world
Not everything is a resource

Account:
  •   GET . . . Yep
  •   POST . . . Yep
  •   PUT . . . Yep
  •   DELETE . . . Yep...
Account Renewal: resource or operation?

Renew as a Resource
POST:
  http://localhost/accounts/3/renewals




Renew as an ...
REST is training friendly
WS-*                  REST
XML                   HTTP
WSDL                  XML *
XML Schema
SOAP
AXIS/CXF       V.S.
JAXB...
Clients are and aren’t free




                    But not
REST: the silver bullet?
The takeaway: apply REST to your app
Questions?



http://struts.apache.org/2.x/docs/rest-plugin.html
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
Upcoming SlideShare
Loading in …5
×

An introduction to Struts 2 and RESTful applications

27,554 views

Published on

Presentation given by Don Brown at OSDC Sydney 2008

Published in: Technology, Education
2 Comments
9 Likes
Statistics
Notes
No Downloads
Views
Total views
27,554
On SlideShare
0
From Embeds
0
Number of Embeds
115
Actions
Shares
0
Downloads
601
Comments
2
Likes
9
Embeds 0
No embeds

No notes for slide

An introduction to Struts 2 and RESTful applications

  1. 1. An introduction to Struts 2 and RESTful applications Don Brown Atlassian mrdon@twdata.org
  2. 2. What’s wrong with my web application?  Modern web framework  Presentation and business logic separation  Code not tied to HTTP
  3. 3. Problem: Confusing URIs GET http://localhost/spaces/addspacenotification.action? key=AJOBS GET http://localhost/spaces/addspacenotification.action? key=AJOBS GET http://localhost/spaces/addspacenotification.action? key=AJOBS GET http://localhost/spaces/addspacenotification.action? key=AJOBS
  4. 4. Problem: Poor caching HTTP traffic laws broken:  GET - Could be anything, including deletes and updates  POST - Also could be anything, even regular page views  PUT - Not used  DELETE - Not used
  5. 5. Problem: People can’t get at their data
  6. 6. REST is the Way of the Web
  7. 7. Not just for Web Services http://www.flickr.com/photos/psd/2217422218/
  8. 8. 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
  9. 9. Solution: Scalable caching Follow HTTP traffic laws:  GET - No side-effects, can repeat  POST - Changes state, cannot repeat  PUT - Changes state, can repeat  DELETE - Changes state, can repeat
  10. 10. Solution: One API for all
  11. 11. REST in action
  12. 12. Detour: Struts 2
  13. 13. Struts 2 History
  14. 14. Struts 2 plugins
  15. 15. 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
  16. 16. Struts 2 REST Plugin URI HTTP Method Action Method /orders GET index() /orders/3 GET show() /orders POST create() /orders/3 PUT update() /orders/3 DELETE destroy() /orders/new GET editNew() /orders/3/edit GET edit()
  17. 17. A RESTful example: orders . . . Let’s see some code!
  18. 18. REST in the real world
  19. 19. Not everything is a resource Account: • GET . . . Yep • POST . . . Yep • PUT . . . Yep • DELETE . . . Yep • Renew?
  20. 20. Account Renewal: resource or operation? Renew as a Resource POST: http://localhost/accounts/3/renewals Renew as an Operation POST http://localhost/accounts/3/renew
  21. 21. REST is training friendly
  22. 22. WS-* REST XML HTTP WSDL XML * XML Schema SOAP AXIS/CXF V.S. JAXB WS-Security* UDDI*
  23. 23. Clients are and aren’t free But not
  24. 24. REST: the silver bullet?
  25. 25. The takeaway: apply REST to your app
  26. 26. Questions? http://struts.apache.org/2.x/docs/rest-plugin.html

×