Beginning JAX-RS

  • Published on
    15-Jan-2015

  • View
    7.927

  • Download
    0

Embed Size (px)

DESCRIPTION

JAX-RSJAX-RS 2.0

Transcript

  • 1. Beginning JAX-RSDecember 13, 2012HASUNUMA Kenji Vice president, GlassFish Users Group Japank.hasunuma@coppermine.jpTwitter: @btnrouge

2. Whats REST? 3. RESTful Web?REST3 () () URI ()StatelessWeb 4. RESTful Static Web sites Weblog (Movable Type, WordPress, etc.) Google API Amazon API Twitter API Facebook APIREST3= 5. RESTful Old CGI Applications SOAP based Web service Apache Struts (A) JavaServer FacesPOST (StatelessWeb) 6. URI : : HTML : Web 7. GET POST PUT DELETE HEADOPTIONS 8. URI (Unied Resource Identier) Unix URL 9. URI = /say/hello/to/youyou to helloeverybodysay goodbye/write 10. JAX-RS History 11. JSR 311 : JAX-RS JSR Review : 2007-02-26 Early Draft Review : 2007-11-23 Public Review : 2008-06-02 Final Draft : 2008-09-22 Final Release : 2008-10-10 Java EE 6 (JSR 316) : 2009-12-10 12. Interlude (2008-10/2009-12) JAX-RS 0.9 - Last big changes - @ConsumeMime -> @Consumes - @ProduceMime -> @Produces JAX-RS 1.0 - Final releaseGlassFish v3 Prelude JAX-RS 1.1 - Maintenance releaseJava EE 6, EJB Integration 13. JSR 339 : JAX-RS 2.0JAX-RS 2.0 JSR Review : 2011-01-24 Early Draft Review 3 : 2012-07-07 Public Review : 2012-11-26 Final Draft : ? Final Release : ? Java EE 7 (JSR 342) : 2013 Q2 14. JAX-RS GlassFish Server Jersey (RI) Oracle WebLogic Server Fujitsu Interstage AS JBoss AS RESTEasy JBoss EAP IBM WebSphere ASApache WinkIBM WAS CE Apache GeronimoApache CXF Apache TomEE+Hitachi uCosminexus AS Tmax JEUS 15. Core Features 16. JAX-RS 17. JAX-RS JAX-RS 2.0 18. RESTJAX-RS (POJO) @GET, @POST, @PUT, @DELETE URI @Path / 19. POJO @Path EJB(Stateless or Singleton)EJBCDI 20. JAX-RS 2.0 CDIEJBCDI Bean Validation() : (Concurrency Utilities) 21. @Path(/hello)public class HelloResource {@GET@Consumes(application/x-www-urlencoded)@Produces(text/plain)public String sayHello(@QueryParam(q) String name) {return Hello, + name;}} 22. GET /hello?q=everybody@Path(/hello)public class HelloResource {@GET@Consumes(application/x-www-urlencoded)@Produces(text/plain) ResponseRequestpublic String sayHello(@QueryParam(q) String name) {return Hello, + name;}} 23. @QueryParam @FormParam@PathParamURI@MatrixParam Matrix URI@HeaderParam @CookieParam () 24. GET /hello/everybody : @PathParam@Path(/hello/{q})public class HelloResource {@GET@Consumes(application/x-www-urlencoded)@Produces(text/plain) ResponseRequestpublic String sayHello(@PathParam(q) String name) {return Hello, + name;}} 25. : @MatrixParamGET /position;latitude=35.75;longitude=139.72@Path("/position")public class PositionResource {@GETpublic String getPosition( @MatrixParam("latitude") double latitude, @MatrixParam("longitude") double longitude) { return String.format("%3.2f%s %3.2f%s", Math.abs(latitude), latitude == 0.0 ? "" : (latitude > 0.0 ? "N" : "S"), Math.abs(longitude), longitude == 0.0 ? "" : (longitude > 0.0 ? "E" : "W")); }} 26. JavaMIME JavaMIMEbyte[ ]StringMIME InputStream (*/*)Reader text/xmlJavaBean application/xml (JAXB)application/jsonMultivaluedMap application/x-www-urlencoded Booleantext/plainCharacter auto-boxing Number 27. MIME : MessageBodyReader MessageBodyWriter JAXBJAXB byte[ ]InputStream () 28. MIMEJAX-RS 2.0 : MessageBodyReader MessageBodyWriter / : /gzip JSR 339 29. APIJAX-RS 2.0// Step 1 : ClientClient client = ClientFactory.newClient();// Step 2 : (URI)WebTarget target = client.target(uri);// Step 3 : Response response = target.request().get(); 30. APIJAX-RS 2.0// Step 3a : ()String response =target.request().get(String.class);// Step 3b : Future response =target.request().async().get(String.class); 31. How to deploy 32. JAX-RS Web :1. Application2. (web.xml) uCosminexus() 33. Application@ApplicationPath(/app)public MyApplication extends Application { // }URL:http://hostname/context-root/app/hello 34. (Jersey)Jerseycom.sun.jersey.spi.container .servlet.ServletContainerJersey/app/* 35. (Jersey())@WebServlet(/app/*)public class MyServletContainerextends ServletContainer { // } 36. Extensions 37. @Context ServletCong ServletContext HttpServletRequest HttpServletResponse() HttpSession 38. @Provider @Provider () MessageBodyReader/Writer /(JAX-RS 2.0) EJB(JAX-RS 1.0) 39. Non-standardFeatures 40. JerseyAPI MIME Multipart OAuth gzip/ MVC 41. RESTEasyAPI MIME MultipartCDI OAuth gzip/ 42. Apache CXFAPI MIME Multipart (CXF) KerberosJAX-WS 43. Apache Wink API MIME Multipart WebSphere AS - 44. Conclusions 45. JAX-RSFinal release API (JEE6) JAX-RS 2.0 JAX-RS 46. JAX-RS = API JAX-RSREST Web JAX-RS 47. Beginning JAX-RSHASUNUMA Kenjik.hasunuma@coppermine.jpTwitter: @btnrouge