190 likes | 475 Views
JAX-RS – REST in Java. Agenda. Introduction Compare to SOAP Server code Client code Frameworks. Introduction. Representational state transfer (Roy Fieding) Every URL represents an object or a state Who uses it? Amazon AWS (EC2, S3, etc.) Flickr Del.ici.ous Ebay CRUD by HTTP methods
E N D
Agenda Introduction Compare to SOAP Server code Client code Frameworks
Introduction Representational state transfer (Roy Fieding) Every URL represents an object or a state Who uses it? Amazon AWS (EC2, S3, etc.) Flickr Del.ici.ous Ebay CRUD by HTTP methods Create → POST Read → GET Update → PUT Delete → DELETE
Compare to SOAP REST advantages Lightweight - not a lot of extra xml markup Human Readable Results Easy to build - no toolkits required SOAP advantages Easy to consume – sometimes Rigid - type checking, adheres to a contract Development tools
Server code Servlet API web.xml mapping doGet, doPost, doUpdate, doDelete Payload marshalling/unmarshalling Example JSR-311 (JAX-RS) Example
JAX-RS features Annotation based Deployment JAX-RS aware container javax.ws.rs.Application Servlet container Servlet Filter J2SE RuntimeDelegate.createEndpoint HTTP Data handling @Provider
JAX-RS HTTP Templated mapping and subresources @Path MIME handling @Provides, @Consumes HTTP methods @GET, @POST, @UPDATE, @DELETE, @HEAD, @OPTIONS, @HttpMethod Caching evaluatePreconditions
JAX RS data handling URI templates {name} {regex} Parameters @PathParam @QueryParam @FormParam @MatrixParam @HeaderParam @SessionParam @UriInfo @Encoded @CoockieParam @DefaultValue No annotation (entity) Return values Resporse GenericEntity Null Status 204 Entity (marshalled) Exceptions WebApplicationException Unchecked Filters, error pages Checked ServletException, WebServiceException @Provider extends ExceptionMapper
Entities Primitives String enum byte [], File, DataSource, etc. JAXB valueOf List, Set, SortedSet – not worked for me :-( @Provider MessageBodyReader MessageBodyWriter
Client code Old school – javascript, HttpClient REST oriented APIs No standard spec Framework offer good APIs org.jboss.resteasy.client.core com.sun.jersey.api.client
Frameworks Jboss resteasy Sun jersey CXF Axis2 Spring Others?