an introduction to struts 2 and restful applications

34
An introduction to Struts 2 and RESTful applications Don Brown Atlassian [email protected]

Upload: mrdon

Post on 29-Nov-2014

27.480 views

Category:

Technology


2 download

DESCRIPTION

Presentation given by Don Brown at OSDC Sydney 2008

TRANSCRIPT

Page 1: An introduction to Struts 2 and RESTful applications

An introduction to Struts 2 andRESTful applications

Don BrownAtlassian [email protected]

Page 2: An introduction to Struts 2 and RESTful applications
Page 3: An introduction to Struts 2 and RESTful applications
Page 4: An introduction to Struts 2 and RESTful applications
Page 5: An introduction to Struts 2 and RESTful applications
Page 6: An introduction to Struts 2 and RESTful applications
Page 7: An introduction to Struts 2 and RESTful applications
Page 8: An introduction to Struts 2 and RESTful applications
Page 9: An introduction to Struts 2 and RESTful applications
Page 10: An introduction to Struts 2 and RESTful applications

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

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

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

Problem: People can’t get at their data

Page 14: An introduction to Struts 2 and RESTful applications

REST is the Way of the Web

Page 15: An introduction to Struts 2 and RESTful applications

Not just for Web Services

http://www.flickr.com/photos/psd/2217422218/

Page 16: An introduction to Struts 2 and RESTful applications

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

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

Solution: One API for all

Page 19: An introduction to Struts 2 and RESTful applications

REST in action

Page 20: An introduction to Struts 2 and RESTful applications

Detour: Struts 2

Page 21: An introduction to Struts 2 and RESTful applications

Struts 2 History

Page 22: An introduction to Struts 2 and RESTful applications

Struts 2 plugins

Page 23: An introduction to Struts 2 and RESTful applications

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

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

A RESTful example: orders

. . . Let’s see some code!

Page 26: An introduction to Struts 2 and RESTful applications

REST in the real world

Page 27: An introduction to Struts 2 and RESTful applications

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

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

REST is training friendly

Page 30: An introduction to Struts 2 and RESTful applications

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

Clients are and aren’t free

But not

Page 32: An introduction to Struts 2 and RESTful applications

REST: the silver bullet?

Page 33: An introduction to Struts 2 and RESTful applications

The takeaway: apply REST to your app

Page 34: An introduction to Struts 2 and RESTful applications

Questions?

http://struts.apache.org/2.x/docs/rest-plugin.html