Restful communication with Flex

7,038 views
6,794 views

Published on

The addition of the REST API to ArcGIS Server at 9.3 was quickly embraced by developers as a simple but powerful way to utilize ArcGIS Server output in application development. Furthermore the new ArcGIS API for Flex enabled the development of true Rich Internet Applications (RIAs) on top of ArcGIS Server. But the Flex Framework in its current state imposes significant limitations on RESTful communication via HTTP: there's just no straightforward way to extract the headers from an HTTP-response in ActionScript3. This means you can't read the id of a newly created resource from the 'Location' header, making it impossible to tell the difference between a '500 Internal Server Error', a '404 Not Found' or a '422 Validation Error'. There's also no way to get the response body for anything outside the 2xx status range. And the only HTTP methods accepted are GET and POST, meaning you cannot use PUT or DELETE, at least not without a proxy. This session focuses on how to unleash the full power of REST for your RIA using a BlazeDS proxy on your application backend to circumvent aforementioned limitations. We'll walk you through the creation of a Java based RESTful Web service using Jersey (an open source reference implementation for JSR-311/JAX-RS), and show how to set up the Flex application on the client side to utilize the complete set of RESTful Web Service HTTP methods and status codes.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
7,038
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
65
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Restful communication with Flex

  1. 1. Unleash the full power ofRESTful communication with FLEXChristian JunkESRI Developer Summit 2010, Palm Springs<br />
  2. 2. RESTful communication with FLEXChristian JunkESRI Developer Summit 2010, Palm Springs<br />
  3. 3. Who am I?<br />Senior Software Developer @ http://www.alta4.com, Germany<br />Developingbackendsfor web-basedapplicationsprimarilywithJavatechnologies<br />Who areyou?<br />Java and/orFlex Developer (Beginner)<br />Just interested/curious<br />Prerequisites: Basic Knowledgeof Java, REST, BlazeDS, Flex (haveheardofit)<br />
  4. 4. What‘sit all about?<br />
  5. 5. Whatyou (hopefully) will learn<br />Cover the Basics (no 101)<br />REST<br />BlazeDS<br />Jersey<br />EnableFlextousethefullcapabilitiesof REST<br />See someofourdailyroutinesduringthesoftwaredevelopmentprocess<br />
  6. 6. Agenda<br />REST CRUDelySummarized<br />Can FLEX do REST?<br />BlazeDS in 5 Minutes<br />Puttingit all together (demo)<br />
  7. 7. REST(RepresentationalState Transfer)CRUDelySummarized<br />
  8. 8. REST Concepts<br />Architectural style, not technology !<br />Client/server + Request/response approach.<br />Stateless by nature (excellent for distributed systems)<br />Cacheable (naturally supported !)<br />Well known (HTTP)<br />Easy<br />Cool<br />
  9. 9. HTTP Client<br />REST Resource<br />HTTP Request<br />RESPONSE CODE 200 (OK) + BODY<br />GET REQUEST<br />
  10. 10. HTTP Client<br />REST Resource<br />HTTP Request<br />RESPONSE CODE 200 (OK) + BODY<br />GET REQUEST<br />
  11. 11. REST Concepts<br />Resources (nouns)Everythingis a resource ,identified by a URI:- http://www.flickr.com/photos/christianjunk- http://twitter.com/ESRI/favorites <br />
  12. 12. HTTP Client<br />REST Resource<br />HTTP Request<br />RESPONSE CODE 200 (OK) + BODY<br />GET REQUEST<br />
  13. 13. REST Concepts<br />Uniform interface (verbs)REST reduces the syntax of web servicesto a small fixed set of database-derivedverbs<br />
  14. 14. REST Concepts<br />[1] The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.<br />
  15. 15. HTTP Client<br />REST Resource<br />HTTP Request<br />RESPONSE CODE 200 (OK) + BODY<br />GET REQUEST<br />
  16. 16. REST Concepts<br />State RepresentationsData and state transferred between client and server:- XML, JSON, Atom, XHTML, etc.<br />
  17. 17. http://api.twitter.com/ESRI/favorites.json<br />
  18. 18. http://api.twitter.com/ESRI/favorites.xml<br />
  19. 19.
  20. 20. Google AJAX Search API<br />http://code.google.com/apis/ajaxsearch/<br />Amazon S3<br />http://aws.amazon.com/s3<br />flickr<br />http://www.flickr.com/services/api/<br />twitter<br />http://apiwiki.twitter.com/<br />del.icio.us<br />http://delicious.com/help/api<br />
  21. 21. Can FLEX do REST?<br />
  22. 22. With the HTTPServiceComponent<br />you can only do a GET or a POST, no PUT or DELETE<br />the HTTP status code returned in the response is not available (so you can’t get the id of a newly created resource from the ‘Location’ header and you can’t tell the difference between a ‘500 Internal Server Error’, a ‘404 Not Found’ or a ‘422 Validation Error’)<br />there’s also no way to get the response body for anything not in the 2xx range (it fires a fault event for any HTTP response that does not have a status code of 200)<br />
  23. 23. DEMO<br />
  24. 24.
  25. 25. BlazeDS<br />
  26. 26. Whatisit?<br />“BlazeDS is a server-based Java remoting and web messaging technology”<br />
  27. 27. Remoting<br />Messaging<br />Proxying<br />Servlet Container<br />Database<br />BlazeDS<br />AMF/HTTP<br />YourApplication<br />
  28. 28. Without BlazeDS Flex applications can access back-end data using either the HTTPService or WebService components<br />BlazeDS is a series of data services that provide your Flex applications with additional dataconnectivity options:<br />Remoting Service (directly invoke methods of Java objects deployed in your application server)<br />Message Service (provides a complete publish/subscribe infrastructure allowing Flex clients and the server to exchange messages in real time)<br />HTTP Proxy Service (makecross-domain(!) servicerequests)<br />
  29. 29. HTTP Proxy Service<br />Servlet Container<br />BlazeDS<br />YourApplication<br />
  30. 30. Alternatives?<br />
  31. 31. Puttingit all together<br />
  32. 32. Technologies/Tools for Development<br />Flex + BlazeDS (RIA)<br />Java<br />Jersey (JAX-RS/JSR 311) -> Annotation + POJO = REST<br />Apache Maven (Build Manager for Java Projects)<br />IntelliJIdea / MyEclipse (Java IDEs) <br />Adobe FlexBuilder (Flex IDE)<br />Apache Tomcat (Server/Servlet Container)<br />
  33. 33. DEMO<br />
  34. 34. QUESTIONS?<br />
  35. 35. THANK YOU!<br />

×