Oredev 2009 JAX-RS

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    From Göteborg Callista

    1 Favorite

    Oredev 2009 JAX-RS - Presentation Transcript

    1. SDC 2008 REST made simple with Java
    2. Niklas Gustavsson [email_address] http://protocol7.com http://twitter.com/protocol7
    3. REST made simple with Java
    4. REST?
    5. HTTP 1.1
    6. Some HTTP history
    7. Some HTTP history
    8. HTTP used right
    9. Constraints
    10. Constraints Everything is a resource
    11. Constraints A resource has an identifier http://example.com/reports/niklas
    12. Constraints We transfer representations
    13. Constraints All resources expose a uniform interface GET, POST, PUT, DELETE
    14. Constraints Hypermedia as the engine of application state
    15. Constraints Client-server, Stateless, Cacheable, Layered
    16. Why?
    17. Why? It's easy! Well, it's not
    18. Why? It's what the cool kids use
    19. Why? Web has been successful, copy!
    20. Why? It's what others use
    21. Why? Interoperability on the right level
    22. Frameworks!
    23. JAX-RS (aka JSR-311)
    24. Jersey http://jersey.dev.java.net Restlets http://www.restlet.org RESTeasy http://www.jboss.org/resteasy CXF http://cxf.apache.org
    25. POJO based Annotation heavy
    26. Resources
    27. Code! Show me the code!
    28. public class TimeReportService { private TimeReportDao reportDao; public TimeReport getReport(String username) { return reportDao.forUser(username); } public void saveReport(TimeReport report) { reportDao.update(report); } ... }
    29. Request mapping
    30.  
    31. @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); } ... }
    32. Parameters
    33. @Path("reports/ {username} ") public class TimeReportService { @GET public TimeReport getReport(@PathParam("username") String username) { return reportDao.forUser(username); } ... } http://example.com/report/ niklas
    34. @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 } }
    35. @GET public TimeReport getReport(@CookieParam("username") String username) { return reportDao.forUser(username); }
    36. Any media type is allowed XML, JSON, text/plain, binary, ...
    37. Entity providers MessageBodyReader, MessageBodyWriter
    38.  
    39. Standard Entity providers
    40. Writing your own Entity provider
    41. BEGIN:VEVENT DTSTART:20091102T080000Z DTEND:20091106T170000Z SUMMARY:OREDEV END:VEVENT
    42. @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;); } ... }
    43. Request Response ResponseBuilder
    44. Exception Mapping
    45. Application
    46.  
    47. 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 ; } }
    48. Deployment
    49. JAX-RS limitations
    50. JAX-RS limitations Lifecycle support
    51. JAX-RS limitations Conneg only http://example.com/report http://example.com/report.xml http://example.com/report.cal http://example.com/report.json
    52. JAX-RS limitations Limited security support
    53. JAX-RS limitations Leaky abstraction
    54. JAX-RS limitations Weak support for links
    55. Try it out! And have a look at the alternatives
    56. Want more? http://github.com/protocol7/jax-rs-demo
    57. Want more?
    58. Questions?
    59. [email_address]
    60. 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

    + Niklas GustavssonNiklas Gustavsson, 3 weeks ago

    custom

    135 views, 1 favs, 0 embeds more stats

    Introduction to JAX-RS that I gave at Øredev 2009

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 135
      • 135 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 6
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories