Joine Music

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Saturday, 26 May 2007

RESTful Web Services: JSR-311 (TS-6411) at JavaOne 2007

Posted on 02:24 by Unknown
These are the notes which I took during the RESTful Web Services Technical Session at JavaOne 2007. Eventually the presentation audio will be available but until then this should provide a good overview of what was said.

Speakers: Paul Sandoz, Marc Hadley, Peter Liu

Definition
"REST" is the architectural style of the WWW. Note that "style" is not "architecture". Coined by Roy Fielding in his PhD thesis.

Tenets
Resources
- These can be considered as the Platonic ideal forms. They are identified by "Uniform Resource Identifiers" ( aka "URIs") and realised by "Representations" which are the equivalent of the shadows in our Platonic Cave metaphor.

Methods - Methods are how we interact with the resources. In the HTTP paradigm these are as you would expect GET, POST, etc. The key is that they are a small set and fixed for all resources. They facilitate the exchange of the representations.

Representations - Representations embody the state of a resouce r at time t. Therefore,you can see that there can be multiple, alternate representations of a given single resource R. It can be conceived of as a finite state machine.

REST vs. RPC
RPC
Few endpoints. Few nouns but many verbs e.g.:
musicdb.getRecordings("my_artist")
REST
Many resources, few fixed methods. Many nouns and few verbs e.g.:
GET /music/artist/my_artist/recordings
Caching
REST allows you to cache because caches can understand the semantics in the protocol. These are not embedded in the message as they are in RPC.

HTTP
HTTP is an application protocol. RESTful web services are "of the web". Don't hide / ignore elements in the network which help you - e.g. caches.

Why a Java REST API?
Lots of companies now offer them (Google, Amazon, eBay, etc.) to expose their services. Where both WS-* and REST APIs are offered, REST are more widely used. It is proposed that this is due to their simplicity (they are easy to consume with common web scripting scripting languages such as PHP) and ability to use web browsers for testing.

The current Java web APIs (e.g. the Servlet API) are too low level though they can be used to implement a REST Web Service. There are many opportunities to simplify development as there must be a better way:
  • High level
  • Declarative
  • Clearly maps to REST concepts
  • Takes care of the boilerplate code
  • Makes it easy to do the right thing
  • Provides a graceful fallback to a lower level API when it's needed
API Elements
Java doesn't really have a concept of a Representation or a Resource. If we try and code a REST servlet without the API we see that we would need to implement content negotiation (what form the Representation should take e.g. xml, text, etc.) and path parsing ( e.g. what Resource(s) have been requested ).

Automate Content Negotiation
Declare what content will be returned:
@ProduceMime("application/xml")
protected void doGet(HttpServletREquest request,
HttpServletResponse response)
URI Templates
Declare what method responds to which requests:
@URITemplate("/artists/{id}") public class Artist extends HttpServlet { ...
This means your container should only call this servlet when requests match this template. To take this one step farther we can combine and apply these annotations to a POJO:
@URITemplate("/artists/{id}")
@ProduceMime("application/xml")
public class Artist { @HttpMethod // Needed as we no longer implement HttpServlet InputStream getXml(@URIParam("id") String artist) { ... } @ProduceMime("application/json") @HttpMethod // Needed as we no longer implement HttpServlet InputStream getJson(@URIParam("id") String artist) { ... } @HttpMethod @UriTemplate("recordings") InputStream getRecordingsXml(@UriParam("id") String artist) { ... }
}
Declaring Resource Class Methods
@HttpMethod - The method name can then be anything with the default HTTP methods being taken from the annotated java method name. E.g:
@HttpMethod public XXX getXXX( ) { ... } @HttpMethod("GET") public XXX find( ) { ... }
Method Return Types HttpResponse - provide specialised subclasses for common types of response such as Redirect, Resource Creation, etc.

Representation - provide control of entity related headers such as media type, language, etc.

T - when a default media type can be determined. This is extensible via the SPI.
@HttpMethod
public Recording getRecording( )
Method Parameters
There may be multiple annotated with @URIParam, @QueryParam, @MatrixParam, @HeaderParam (flexible typing) plus zero or one of type Entity or T. E.g.:
@HttpMethod
public Recording updateRecording(
@URIParam("id") String id, Recording updatedRecording)
Deployment Options
  • Servlet and Java APIs for XML web service (JAX-WS) providers will be required by the JSR
  • The Sun Reference Implementation will also add support for Grizzly and the Java SE 6 lightweight HTTP server
  • Restlet support expected - for fall back if needed
  • SPI for other containers
Issues
  • Annotations vs. Classes and Interfaces?
    • Annotations are good for static information
    • Classes and Information are good for dynamic information
    • When to use? It is nice to replace a lot of logic with a nice annotation
  • Resource Lifecycle?
    • Per request, per session or singleton?
  • Container or API - what should go where?
    • Security
    • Filters / Guards
  • Other language support
    • Annotation support is difficult in JavaScript and Ruby
    • Low level APIs start to lose the benefits
Summary
  • High-level declarative programming model
  • REST concepts reflected in the API
  • Flexible typing, runtime takes care of common conversions
  • SPIs to extend capabilities
  • Pluggable support for types, containers, and resolvers
  • Flexible deployment options
Email ThisBlogThis!Share to XShare to Facebook
Posted in rest restful jsr311 java web2.0 javaone ts-6411 | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • (no title)
    The Significance and Importance of Quotes in JSTL EL I just spent a few hours debuggung a null pointer in a Portlet JSP I'm writing. It...
  • (no title)
    Agile Development Ramblings: Part I Introduction I've just completed my first Agile development project. We developed a fully functiona...
  • EJB 3.0 Outside the Container, Inside the JVM - Part 2: Configuring JPA Declaratively
    Welcome to part two of this blog entry introducing using EJB3.0 inside the JVM. Click here to view the first part. As we've seen, JPA ...
  • Reuse (ii): Definition of Done
    As I said in my previous post , our project has suddenly taken a new path. There are two bits of collateral which I'd recently produced...
  • Notes from the FindBugs BOF9231 at JavaOne 2007
    NOTE: These are my incomplete notes from the FindBugs BOF at JavaOne 2007. I got in late due to the crush outside so missed the start of th...
  • Writing Unit Tests to Ensure Your "@Transactional ... rollbackFor" Annotations are Honoured
    Thanks to Russ Hart for providing the info on how to get this to work.  I just cut and paste, and then blogged it. It's nice to write un...
  • (no title)
    Can Your Own Demo I found something great on t'internet the other day. I had been asked to do a demo of our new ystem to some users but...
  • JavaOne Bred Over-Enthusiasm...
    I want to build and fiddle with Wonderland , and my own JDK ! The problem is my graphics card sucks (I need acceleration) and I'm runnin...
  • Booting Apache Derby ("JavaDB") with your Java App's Startup
    If you're embedding the Derby RDBMS with your java desktop application and want it to start when you start your app, you need to make th...
  • STS and RTC – Getting them to Play Nice
    We’re developing our new app using Spring 3.0 RC1 and we want the best tools available. We’ve picked the following: SpringSource Tools ...

Categories

  • 0
  • 2008
  • ant maven pimp build javaone 2008
  • apple ipod touch
  • asm
  • blog new ruby
  • blogtag list
  • bond casinoroyale mashup mi6 film movie
  • build
  • bytecode
  • CI
  • cobertura
  • communityone 2008 nutter jvm scala jruby groovy davinci
  • communityone 2008 opensocial socialsite
  • communityone javaone keynote oreilly
  • configuration
  • cowley
  • css div layout column ie firefox safari example
  • custom
  • darkstar mpk20 wonderland java3d commaboration SL
  • dashboard rss communication news development
  • db2 database SQL max min howto tip
  • db2 database ibm lessons tips
  • db2 database load batch howto example
  • db2 import upload data howto command
  • debt technical java annotation
  • debugging tips javaone 2008
  • development web2.0
  • findbugs JavaOne 2008 pugh
  • findbugs JavaOne BOF notes
  • gafter closures java javaone notes
  • google trouble patriarchal patriarchy
  • groovy metaprogramming javaone 2008
  • grubby oss data generation project announce
  • guice javaone 2008
  • gwt maven howto example simple
  • howto
  • hudson
  • hudson CI javaone 2008
  • ibm
  • invokeDynamic jvm dynamic ruby javaone
  • itinerant web2.0 portable desktop
  • jacl was websphere wsadmin trace logging
  • james gosling sun java open source tech days second life SL
  • jar java manifest properties config howto tip
  • java
  • java applet javaone 2008 reloaded jnlp
  • java javafxscript javaone 2008 fxscript
  • java javaone 2007 07
  • java javaone 2008 bytecode cobertura asm singleton testability
  • javaone
  • javaone keynote gage schwarz javafx
  • javaone semantic web bof notes web3
  • jazz
  • jruby rails javaone charlesnutter thomasenebo
  • jruby ruby netbeans development
  • kill dead laptop computer rebuild restore
  • lessonslearned
  • mac osx java gui shellscript classpath problem solution
  • maven plugin unittest test packager
  • mylin mylar javaone eclipse 2008
  • netbeans development ide
  • netbeans development ide RC
  • netbeans maven2 profiling
  • netbeans ruby sun tech days visual web pack roman strobl
  • ola bini java javaone 2008 thoughtworks ruby jruby
  • openjdk java javaone javafx wonderland
  • overheard
  • pojo ejb3.0 jpa orm java example howto
  • rant
  • rest restful jsr311 java web2.0 javaone ts-6411
  • rome rss feed blog rss atom propono java javaone
  • rsa uml profile plugin howto
  • ruby inheritance example
  • ruby jruby rss xml hpricot
  • ruby unless example
  • scm
  • setup
  • subversion svn xp windows cleanup
  • sun java soa web2.0 netbeans opensource javacaps
  • sun tech days java derby database rdbms london
  • sun tech days london impressions
  • terracotta java javaone 2008 android gwt
  • tip
  • tips
  • vwp netbeans JPA howto
  • was jython scripting nfr ibm pmi jvm
  • was tpv jython scripting nfr ibm pmi
  • webrick ruby jruby actadiurna investigation code howto
  • workitem

Blog Archive

  • ►  2012 (1)
    • ►  October (1)
  • ►  2010 (8)
    • ►  November (1)
    • ►  October (3)
    • ►  June (1)
    • ►  May (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2009 (9)
    • ►  December (1)
    • ►  November (5)
    • ►  March (2)
    • ►  February (1)
  • ►  2008 (22)
    • ►  December (1)
    • ►  November (3)
    • ►  May (15)
    • ►  March (1)
    • ►  January (2)
  • ▼  2007 (53)
    • ►  December (1)
    • ►  November (3)
    • ►  September (3)
    • ►  August (2)
    • ►  July (3)
    • ►  June (1)
    • ▼  May (12)
      • Notes from the FindBugs BOF9231 at JavaOne 2007
      • JavaOne 2007 - Closures for the Java Language - TS...
      • RESTful Web Services: JSR-311 (TS-6411) at JavaOne...
      • JRuby on Rails - Agility for the Enterprise (TS-93...
      • JavaOne Bred Over-Enthusiasm...
      • Dynamic Languages in the JVM - Discussion Notes fr...
      • Notes: Beyond Blogging: Feeds In Action Technical ...
      • Project Wonderland BOF (BOF-1306) @ JavaOne 2007
      • JavaOne 2007 Day One Keynote - Ubiquitous JVMs
      • JavaOne 2007 (Day 1 – CommunityOne) Keynote with ...
      • JavaOne 2007 (Day 1 – CommunityOne) Hot, Damn Hot
      • Going to JavaOne 2007...
    • ►  April (5)
    • ►  March (13)
    • ►  February (7)
    • ►  January (3)
  • ►  2006 (35)
    • ►  December (8)
    • ►  October (1)
    • ►  August (1)
    • ►  July (5)
    • ►  June (8)
    • ►  May (3)
    • ►  April (7)
    • ►  March (2)
Powered by Blogger.

About Me

Unknown
View my complete profile