Top Banner
© 2010 alta4 Geoinformatik AG Unleash the full power of RESTful communication with FLEX Christian Junk ESRI Developer Summit 2010, Palm Springs
35

Restful communication with Flex

May 26, 2015

Download

Technology

Christian Junk

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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Unleash the full power ofRESTful communication with FLEX

Christian JunkESRI Developer Summit 2010, Palm Springs

Page 2: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

RESTful communication with FLEX

Christian JunkESRI Developer Summit 2010, Palm Springs

Page 3: Restful communication with Flex

© 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)

Page 4: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

What‘s it all about?

Page 5: Restful communication with Flex

© 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

Page 6: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Agenda

REST CRUDely SummarizedCan FLEX do REST?BlazeDS in 5 MinutesPutting it all together (demo)

Page 7: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

REST(Representational State Transfer)

CRUDely Summarized

Page 8: Restful communication with Flex

© 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

Page 9: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

HTTP Client REST ResourceHTTP Request

RESPONSE CODE 200 (OK) + BODY

GET REQUEST

Page 10: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

HTTP Client REST ResourceHTTP Request

RESPONSE CODE 200 (OK) + BODY

GET REQUEST

Page 11: Restful communication with Flex

© 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

Page 12: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

HTTP Client REST ResourceHTTP Request

RESPONSE CODE 200 (OK) + BODY

GET REQUEST

Page 13: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Uniform interface (verbs)REST reduces the syntax of web servicesto a small fixed set of database-derivedverbs

REST Concepts

Page 14: Restful communication with Flex

© 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.

Page 15: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

HTTP Client REST ResourceHTTP Request

RESPONSE CODE 200 (OK) + BODY

GET REQUEST

Page 16: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

State RepresentationsData and state transferred between client and server:- XML, JSON, Atom, XHTML, etc.

REST Concepts

Page 17: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

http://api.twitter.com/ESRI/favorites.json

Page 18: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

http://api.twitter.com/ESRI/favorites.xml

Page 19: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Page 20: Restful communication with Flex

© 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

Page 21: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Can FLEX do REST?

Page 22: Restful communication with Flex

© 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)

Page 23: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

DEMO

Page 24: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Page 25: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

BlazeDS

Page 26: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

What is it?

“BlazeDS is a server-based Java remoting and web messaging technology”

Page 27: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Servlet Container

Your Application

DatabaseBlazeDS

RemotingMessagingProxying

AMF/HTTP

Page 28: Restful communication with Flex

© 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)

Page 29: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Servlet Container

Your Application

BlazeDS

HTTP Proxy Service

Page 30: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Alternatives?

Page 31: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

Putting it all together

Page 32: Restful communication with Flex

© 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)

Page 33: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

DEMO

Page 34: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

QUESTIONS?

Page 35: Restful communication with Flex

© 2010 alta4 Geoinformatik AG

THANK YOU!