SlideShare a Scribd company logo
1 of 60
SDC  2008 REST  made simple with Java
Niklas Gustavsson [email_address] http://protocol7.com http://twitter.com/protocol7
REST made simple with Java
REST?
HTTP 1.1
Some HTTP history
Some HTTP history
HTTP used right
Constraints
Constraints Everything is a resource
Constraints A resource has an identifier http://example.com/reports/niklas
Constraints We transfer representations
Constraints All resources expose a uniform interface  GET, POST, PUT, DELETE
Constraints Hypermedia as the engine of application state
Constraints Client-server, Stateless, Cacheable, Layered
Why?
Why? It's easy! Well, it's not
Why? It's what the cool kids use
Why? Web has been successful, copy!
Why? It's what others use
Why? Interoperability on the right level
Frameworks!
JAX-RS (aka JSR-311)
Jersey  http://jersey.dev.java.net Restlets  http://www.restlet.org RESTeasy  http://www.jboss.org/resteasy CXF  http://cxf.apache.org
POJO based Annotation heavy
Resources
Code! Show me the code!
public class TimeReportService { private TimeReportDao reportDao; public TimeReport getReport(String username) { return reportDao.forUser(username); } public void saveReport(TimeReport report) { reportDao.update(report); }   ... }
Request mapping
 
@Path("reports") public class TimeReportService { private TimeReportDao reportDao; @GET public TimeReport getReport(String username) { return reportDao.forUser(username); } @PUT public void saveReport(TimeReport report) { reportDao.update(report); }   ... }
Parameters
@Path("reports/ {username} ") public class TimeReportService { @GET public TimeReport getReport(@PathParam("username")  String username) { return reportDao.forUser(username); } ... } http://example.com/report/ niklas
@GET public TimeReport getReport(@Context SecurityContext sc) { if(sc.isSecure()) { Principal user = sc.getUserPrincipal(); return reportDao.forUser(user.getName()); } else { ... throw error, redirect to login  }  }
@GET public TimeReport getReport(@CookieParam("username")  String username) { return reportDao.forUser(username); }
Any media type is allowed XML, JSON, text/plain, binary, ...
Entity providers MessageBodyReader, MessageBodyWriter
 
Standard Entity providers
Writing your own Entity provider
BEGIN:VEVENT DTSTART:20091102T080000Z DTEND:20091106T170000Z SUMMARY:OREDEV END:VEVENT
@Provider @Produces(&quot;text/calendar&quot;) public class TimeReportICalWriter implements  MessageBodyWriter<TimeReport> { public void writeTo(TimeReport t, Class<?> type, Type  genericType,Annotation[] annotations,MediaType  mediaType,MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) { PrintWriter wr = new PrintWriter(entityStream); ... for(TimeRange range : t.getRanges())  { wr.println(&quot;BEGIN:VEVENT&quot;); wr.println(&quot;DTSTART:&quot; + DF.format(range.getStartTime())); wr.println(&quot;DTEND:&quot; + DF.format(range.getEndTime())); wr.println(&quot;SUMMARY:&quot; + range.getDescription()); wr.println(&quot;END:VEVENT&quot;); } ... }
Request Response ResponseBuilder
Exception  Mapping
Application
 
public class TimeReportApplication extends Application { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = new HashSet<Class<?>>(); classes .add(TimeReportService.class); classes .add(TimeReportICalWriter.class); return  classes ; } }
Deployment
JAX-RS limitations
JAX-RS limitations Lifecycle support
JAX-RS limitations Conneg only http://example.com/report http://example.com/report.xml http://example.com/report.cal http://example.com/report.json
JAX-RS limitations Limited security support
JAX-RS limitations Leaky abstraction
JAX-RS limitations Weak support for links
Try it out! And have a look at the alternatives
Want more? http://github.com/protocol7/jax-rs-demo
Want more?
Questions?
[email_address]
Attributions http://www.flickr.com/photos/psd/421186578/ http://www.flickr.com/photos/sineout/2491569707/ http://www.flickr.com/photos/apelad/sets/72157594388426362/ http://www.flickr.com/photos/goopymart/289959670

More Related Content

What's hot

SCWCD 1. get post - url (cap1 - cap2 )
SCWCD 1. get   post - url (cap1 - cap2 )SCWCD 1. get   post - url (cap1 - cap2 )
SCWCD 1. get post - url (cap1 - cap2 )
Francesco Ierna
 

What's hot (20)

Dropwizard
DropwizardDropwizard
Dropwizard
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
 
Mule jdbc
Mule   jdbcMule   jdbc
Mule jdbc
 
From Open Source to Open API with Restlet
From Open Source to Open API with RestletFrom Open Source to Open API with Restlet
From Open Source to Open API with Restlet
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
Spring.io
Spring.ioSpring.io
Spring.io
 
Servlet Part 2
Servlet Part 2Servlet Part 2
Servlet Part 2
 
Birhanu distributive assignment
Birhanu distributive assignmentBirhanu distributive assignment
Birhanu distributive assignment
 
Spring4 whats up doc?
Spring4 whats up doc?Spring4 whats up doc?
Spring4 whats up doc?
 
Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring Session
 
Java Microservices with DropWizard
Java Microservices with DropWizardJava Microservices with DropWizard
Java Microservices with DropWizard
 
SCWCD 1. get post - url (cap1 - cap2 )
SCWCD 1. get   post - url (cap1 - cap2 )SCWCD 1. get   post - url (cap1 - cap2 )
SCWCD 1. get post - url (cap1 - cap2 )
 
Spring 4 - A&BP CC
Spring 4 - A&BP CCSpring 4 - A&BP CC
Spring 4 - A&BP CC
 
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
 
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaGetting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
 
RESTFul Web Services - Intro
RESTFul Web Services - IntroRESTFul Web Services - Intro
RESTFul Web Services - Intro
 
An introduction to consuming remote APIs with Drupal 7
An introduction to consuming remote APIs with Drupal 7An introduction to consuming remote APIs with Drupal 7
An introduction to consuming remote APIs with Drupal 7
 
Web Deployment With Visual Studio 2010
Web Deployment With Visual Studio 2010Web Deployment With Visual Studio 2010
Web Deployment With Visual Studio 2010
 
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphereAAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
 

Viewers also liked

Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architectures: Building Solutions for Web, Cloud, and MobileModern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Dan Mohl
 
Big Data At Spotify
Big Data At SpotifyBig Data At Spotify
Big Data At Spotify
Adam Kawa
 
Interactive Recommender Systems with Netflix and Spotify
Interactive Recommender Systems with Netflix and SpotifyInteractive Recommender Systems with Netflix and Spotify
Interactive Recommender Systems with Netflix and Spotify
Chris Johnson
 

Viewers also liked (15)

Spotify services - Leetspeak 2014
Spotify services - Leetspeak 2014Spotify services - Leetspeak 2014
Spotify services - Leetspeak 2014
 
Spotify services (SDC 2013)
Spotify services (SDC 2013)Spotify services (SDC 2013)
Spotify services (SDC 2013)
 
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architectures: Building Solutions for Web, Cloud, and MobileModern Software Architectures: Building Solutions for Web, Cloud, and Mobile
Modern Software Architectures: Building Solutions for Web, Cloud, and Mobile
 
Modern Software Architecture Styles and Patterns
Modern Software Architecture Styles and PatternsModern Software Architecture Styles and Patterns
Modern Software Architecture Styles and Patterns
 
The Modern Software Architect
The Modern Software ArchitectThe Modern Software Architect
The Modern Software Architect
 
Spotify architecture - Pressing play
Spotify architecture - Pressing playSpotify architecture - Pressing play
Spotify architecture - Pressing play
 
Spotify: Data center & Backend buildout
Spotify: Data center & Backend buildoutSpotify: Data center & Backend buildout
Spotify: Data center & Backend buildout
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture Patterns
 
Big Data At Spotify
Big Data At SpotifyBig Data At Spotify
Big Data At Spotify
 
A Spotify Presentation - Case studies
A Spotify Presentation - Case studiesA Spotify Presentation - Case studies
A Spotify Presentation - Case studies
 
Algorithmic Music Recommendations at Spotify
Algorithmic Music Recommendations at SpotifyAlgorithmic Music Recommendations at Spotify
Algorithmic Music Recommendations at Spotify
 
Music Recommendations at Scale with Spark
Music Recommendations at Scale with SparkMusic Recommendations at Scale with Spark
Music Recommendations at Scale with Spark
 
Scala Data Pipelines for Music Recommendations
Scala Data Pipelines for Music RecommendationsScala Data Pipelines for Music Recommendations
Scala Data Pipelines for Music Recommendations
 
Interactive Recommender Systems with Netflix and Spotify
Interactive Recommender Systems with Netflix and SpotifyInteractive Recommender Systems with Netflix and Spotify
Interactive Recommender Systems with Netflix and Spotify
 
From Idea to Execution: Spotify's Discover Weekly
From Idea to Execution: Spotify's Discover WeeklyFrom Idea to Execution: Spotify's Discover Weekly
From Idea to Execution: Spotify's Discover Weekly
 

Similar to Oredev 2009 JAX-RS

REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
elliando dias
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
jobandesther
 
Java Technology
Java TechnologyJava Technology
Java Technology
ifnu bima
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
b_kathir
 
05 status-codes
05 status-codes05 status-codes
05 status-codes
snopteck
 

Similar to Oredev 2009 JAX-RS (20)

REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
 
REST
RESTREST
REST
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2
 
Java Technology
Java TechnologyJava Technology
Java Technology
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Rapid JCR Applications Development with Sling
Rapid JCR Applications Development with SlingRapid JCR Applications Development with Sling
Rapid JCR Applications Development with Sling
 
Spring 4 Web App
Spring 4 Web AppSpring 4 Web App
Spring 4 Web App
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuse
 
CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
05 status-codes
05 status-codes05 status-codes
05 status-codes
 
112815 java ee8_davidd
112815 java ee8_davidd112815 java ee8_davidd
112815 java ee8_davidd
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 

More from Niklas Gustavsson (7)

Real-time web
Real-time webReal-time web
Real-time web
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Not only SQL
Not only SQL Not only SQL
Not only SQL
 
HTML5
HTML5HTML5
HTML5
 
The future is bright
The future is brightThe future is bright
The future is bright
 
CouchDB
CouchDBCouchDB
CouchDB
 
Apachecon Eu 2008 Mina
Apachecon Eu 2008 MinaApachecon Eu 2008 Mina
Apachecon Eu 2008 Mina
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

Oredev 2009 JAX-RS

Editor's Notes

  1. From Göteborg Callista
  2. From Göteborg Callista
  3. From Göteborg Callista
  4. From Göteborg Callista
  5. From Göteborg Callista
  6. From Göteborg Callista
  7. From Göteborg Callista
  8. From Göteborg Callista
  9. From Göteborg Callista
  10. From Göteborg Callista
  11. From Göteborg Callista
  12. From Göteborg Callista
  13. From Göteborg Callista
  14. From Göteborg Callista
  15. From Göteborg Callista
  16. From Göteborg Callista
  17. From Göteborg Callista
  18. From Göteborg Callista
  19. From Göteborg Callista
  20. From Göteborg Callista
  21. From Göteborg Callista
  22. From Göteborg Callista
  23. From Göteborg Callista
  24. From Göteborg Callista
  25. From Göteborg Callista
  26. From Göteborg Callista
  27. From Göteborg Callista
  28. From Göteborg Callista
  29. From Göteborg Callista
  30. From Göteborg Callista
  31. From Göteborg Callista
  32. From Göteborg Callista
  33. From Göteborg Callista
  34. From Göteborg Callista
  35. From Göteborg Callista
  36. From Göteborg Callista
  37. From Göteborg Callista
  38. From Göteborg Callista
  39. From Göteborg Callista
  40. From Göteborg Callista
  41. From Göteborg Callista
  42. From Göteborg Callista
  43. From Göteborg Callista
  44. From Göteborg Callista
  45. From Göteborg Callista
  46. From Göteborg Callista
  47. From Göteborg Callista
  48. From Göteborg Callista
  49. From Göteborg Callista
  50. From Göteborg Callista
  51. From Göteborg Callista
  52. From Göteborg Callista
  53. From Göteborg Callista
  54. From Göteborg Callista
  55. From Göteborg Callista
  56. From Göteborg Callista
  57. From Göteborg Callista