Upload
christian-junk
View
6.397
Download
6
Tags:
Embed Size (px)
DESCRIPTION
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.
Citation preview
© 2010 alta4 Geoinformatik AG
Unleash the full power ofRESTful communication with FLEX
Christian JunkESRI Developer Summit 2010, Palm Springs
© 2010 alta4 Geoinformatik AG
RESTful communication with FLEX
Christian JunkESRI Developer Summit 2010, Palm Springs
© 2010 alta4 Geoinformatik AG
Who am I?
Senior Software Developer @ http://www.alta4.com, GermanyDeveloping backends for web-based applications primarily with Java technologies
Who are you?
Java and/or Flex Developer (Beginner)Just interested/curious Prerequisites: Basic Knowledge of Java, REST, BlazeDS, Flex (have heard of it)
© 2010 alta4 Geoinformatik AG
What‘s it all about?
© 2010 alta4 Geoinformatik AG
What you (hopefully) will learn
Cover the Basics (no 101)RESTBlazeDSJersey
Enable Flex to use the full capabilities of REST
See some of our daily routines during the software development process
© 2010 alta4 Geoinformatik AG
Agenda
REST CRUDely SummarizedCan FLEX do REST?BlazeDS in 5 MinutesPutting it all together (demo)
© 2010 alta4 Geoinformatik AG
REST(Representational State Transfer)
CRUDely Summarized
© 2010 alta4 Geoinformatik AG
Architectural style, not technology !Client/server + Request/response approach.
Stateless by nature (excellent for distributed systems)Cacheable (naturally supported !)Well known (HTTP)EasyCool
REST Concepts
© 2010 alta4 Geoinformatik AG
HTTP Client REST ResourceHTTP Request
RESPONSE CODE 200 (OK) + BODY
GET REQUEST
© 2010 alta4 Geoinformatik AG
HTTP Client REST ResourceHTTP Request
RESPONSE CODE 200 (OK) + BODY
GET REQUEST
© 2010 alta4 Geoinformatik AG
Resources (nouns)Everything is a resource ,identified by a URI:
- http://www.flickr.com/photos/christianjunk- http://twitter.com/ESRI/favorites
REST Concepts
© 2010 alta4 Geoinformatik AG
HTTP Client REST ResourceHTTP Request
RESPONSE CODE 200 (OK) + BODY
GET REQUEST
© 2010 alta4 Geoinformatik AG
Uniform interface (verbs)REST reduces the syntax of web servicesto a small fixed set of database-derivedverbs
REST Concepts
© 2010 alta4 Geoinformatik AG
REST Concepts
Method REST Operation DescriptionPOST CREATE (INSERT) Create or updateGET READ (QUERY) Query about the resourcePUT UPDATE (CHANGE) UpdateDELETE DELETE (DELETE) Delete what-ever-it-isHEAD Something like ‘GET’ [1]
OPTIONS Information about communication options
TRACE used for debugging
[1] The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.
© 2010 alta4 Geoinformatik AG
HTTP Client REST ResourceHTTP Request
RESPONSE CODE 200 (OK) + BODY
GET REQUEST
© 2010 alta4 Geoinformatik AG
State RepresentationsData and state transferred between client and server:- XML, JSON, Atom, XHTML, etc.
REST Concepts
© 2010 alta4 Geoinformatik AG
http://api.twitter.com/ESRI/favorites.json
© 2010 alta4 Geoinformatik AG
http://api.twitter.com/ESRI/favorites.xml
© 2010 alta4 Geoinformatik AG
© 2010 alta4 Geoinformatik AG
Google AJAX Search APIhttp://code.google.com/apis/ajaxsearch/
Amazon S3http://aws.amazon.com/s3
flickrhttp://www.flickr.com/services/api/
twitterhttp://apiwiki.twitter.com/
del.icio.ushttp://delicious.com/help/api
© 2010 alta4 Geoinformatik AG
Can FLEX do REST?
© 2010 alta4 Geoinformatik AG
With the HTTPService Component
you can only do a GET or a POST, no PUT or DELETE
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’)
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)
© 2010 alta4 Geoinformatik AG
DEMO
© 2010 alta4 Geoinformatik AG
© 2010 alta4 Geoinformatik AG
BlazeDS
© 2010 alta4 Geoinformatik AG
What is it?
“BlazeDS is a server-based Java remoting and web messaging technology”
© 2010 alta4 Geoinformatik AG
Servlet Container
Your Application
DatabaseBlazeDS
RemotingMessagingProxying
AMF/HTTP
© 2010 alta4 Geoinformatik AG
Without BlazeDS Flex applications can access back-end data using either the HTTPService or WebService components
BlazeDS is a series of data services that provide your Flex applications with additional data connectivity options:
Remoting Service (directly invoke methods of Java objects deployed in your application server)Message Service (provides a complete publish/subscribe infrastructure allowing Flex clients and the server to exchange messages in real time)HTTP Proxy Service (make cross-domain(!) service requests)
© 2010 alta4 Geoinformatik AG
Servlet Container
Your Application
BlazeDS
HTTP Proxy Service
© 2010 alta4 Geoinformatik AG
Alternatives?
© 2010 alta4 Geoinformatik AG
Putting it all together
© 2010 alta4 Geoinformatik AG
Technologies/Tools for Development
Flex + BlazeDS (RIA)JavaJersey (JAX-RS/JSR 311) -> Annotation + POJO = RESTApache Maven (Build Manager for Java Projects)IntelliJ Idea / MyEclipse (Java IDEs) Adobe Flex Builder (Flex IDE)Apache Tomcat (Server/Servlet Container)
© 2010 alta4 Geoinformatik AG
DEMO
© 2010 alta4 Geoinformatik AG
QUESTIONS?
© 2010 alta4 Geoinformatik AG
THANK YOU!