Sabyasachi Ghosh, Senior Application Engneer Oracle India, @neilghosh Developing RESTful Web services with JAX-RS
Java API for RESTful Web Services (JAX-RS) Standard annotation-driven API that aims to help developers build RESTful Web services in Java
RESTful Application Cycle Resources are identified by URIs ↓ Clients communicate with resources via requests using a standard set of methods ↓ Requests and responses contain resource representations in formats identified by media types ↓ Responses contain URIs that link to further resources
Give everything an ID
Standard set of methods
Link things together
Multiple representations
Stateless communications
ID is a URI http://example.com/widgets/foo http://example.com/customers/bar http://example.com/customers/bar/orders/2 http://example.com/orders/101230/customer
Resources are identified by URIs Resource == Java class POJO
No required interfaces ID provided by  @Path  annotation Value is relative URI, base URI is provided by deployment context or parent resource
Embedded parameters for non-fixed parts of the URI
Annotate class or “sub-resource locator” method
Resources are identified by URIs @Path("orders/{order_id}") public class OrderResource {   @GET  @Path("customer") CustomerResource getCustomer( @PathParam(“order_id”)int id ) {...} }
Standard Set of Methods Purpose Method Remove DELETE Update or create with a known ID PUT Update or create without a known ID POST Read, possibly cached GET
Standard Set of Methods Annotate resource class methods with standard method @GET ,  @PUT ,  @POST ,  @DELETE ,  @HEAD
@HttpMethod  meta-annotation allows extensions, e.g. WebDAV JAX-RS routes request to appropriate resource class and method
Flexible method signatures, annotations on parameters specify mapping from request
Return value mapped to response
Standard Set of Methods @Path("properties/ {name} ") public class SystemProperty { @GET Property get(@PathParam(" name ") String name) {...} @PUT Property set(@PathParam(" name ") String name, String value ) {...} }
Parameters Template parameters and Regular expressions @Path("customers/ {firstname}-{lastname} ") @Path(" { id : \\d+} ") Matrix Parameters example.cars.com/mercedes/e55;color=black/2006 Query Paremetsrs DELETE /orders/233?cancel=true
Multiple Representations Offer data in a variety of formats XML
JSON
(X)HTML Maximize reach
Support content negotiation Accept header GET /foo Accept: application/json
URI-based GET /foo.json
Content Negotiation: Accept Header Accept: application/xml Accept: application/json;q=1.0, text/xml;q=0.5, application/xml;q=0.5, @GET @Produces({"application/xml","application/json"}) Order getOrder(@PathParam(" order_id ") String id) { ... } @GET @Produces("text/plain") String getOrder2(@PathParam("order_id") String id) { ... }
Content Negotiation: URL-based @Path("/orders") public class OrderResource { @Path("{orderId}.xml")    @Produces(“application/xml”)   @GET    public Order getOrderInXML(@PathParam("orderId") String orderId) { . . .   } @Path("{orderId}.json")    @Produces(“application/json”)   @GET   public Order getOrderInJSON(@PathParam("orderId") String orderId) { . . .   } }
Content Negotiation import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.PathParam; @Path("/actor/{id}") @GET @Produces("application/json") @PathParam("id") import javax.inject.Inject; import javax.enterprise.context.RequestScoped; @RequestScoped public class ActorResource { @Inject DatbaseBean db; public Actor getActor(  int id) { return db.findActorById(id); } }
Link Things Together <order self=&quot; http://example.com/orders/101230 &quot;> <customer ref=&quot; http://example.com/customers/bar &quot;> <product ref=&quot; http://example.com/products/21034 &quot;/> <amount value=&quot;1&quot;/> </order>
Responses Contain Links HTTP/1.1 201 Created Date: Wed, 03 Jun 2009 16:41:58 GMT Server: Apache/1.3.6 Location:  http://example.com/properties/foo Content-Type: application/order+xml Content-Length: 184 <property self=&quot; http://example.com/properties/foo &quot;> <parent ref=&quot; http://example.com/properties/bar &quot;/> <name>Foo</name> <value>1</value> </order>

More Related Content

ODP
RESTful Web Services with JAX-RS
ODP
RESTing with JAX-RS
PPTX
Restful web services with java
PDF
RESTful Web services using JAX-RS
PDF
RESTful Web Services with Jersey
PDF
So various polymorphism in Scala
PPT
Using Java to implement RESTful Web Services: JAX-RS
PDF
JAX-RS 2.0: RESTful Web Services
RESTful Web Services with JAX-RS
RESTing with JAX-RS
Restful web services with java
RESTful Web services using JAX-RS
RESTful Web Services with Jersey
So various polymorphism in Scala
Using Java to implement RESTful Web Services: JAX-RS
JAX-RS 2.0: RESTful Web Services

What's hot (18)

PPT
Developing RESTful WebServices using Jersey
PPTX
Overview of RESTful web services
PDF
Jersey and JAX-RS
PDF
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
PPT
Introduction to JAX-RS
PDF
Java Web Programming [2/9] : Servlet Basic
PDF
Json to hive_schema_generator
PDF
OAuth: Trust Issues
PPTX
Rest with Java EE 6 , Security , Backbone.js
PPTX
RESTful Web Services
PDF
JAX RS 2.0 - OTN Bangalore 2013
PPT
JSP Standart Tag Lİbrary - JSTL
PPTX
jstl ( jsp standard tag library )
PDF
Csajsp Chapter5
DOC
Servlet basics
PDF
PPT
The RESTful Soa Datagrid with Oracle
PPTX
JSP- JAVA SERVER PAGES
Developing RESTful WebServices using Jersey
Overview of RESTful web services
Jersey and JAX-RS
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
Introduction to JAX-RS
Java Web Programming [2/9] : Servlet Basic
Json to hive_schema_generator
OAuth: Trust Issues
Rest with Java EE 6 , Security , Backbone.js
RESTful Web Services
JAX RS 2.0 - OTN Bangalore 2013
JSP Standart Tag Lİbrary - JSTL
jstl ( jsp standard tag library )
Csajsp Chapter5
Servlet basics
The RESTful Soa Datagrid with Oracle
JSP- JAVA SERVER PAGES
Ad

Viewers also liked (6)

ODT
Web Services JAX-RS RESTful y SOAP
PDF
Making Java REST with JAX-RS 2.0
PPSX
JSR 339 - Java API for RESTful Web Services
PDF
Easy REST APIs with Jersey and RestyGWT
PPTX
REST API Design for JAX-RS And Jersey
PDF
Lecture 7 Web Services JAX-WS & JAX-RS
Web Services JAX-RS RESTful y SOAP
Making Java REST with JAX-RS 2.0
JSR 339 - Java API for RESTful Web Services
Easy REST APIs with Jersey and RestyGWT
REST API Design for JAX-RS And Jersey
Lecture 7 Web Services JAX-WS & JAX-RS
Ad

Similar to RestFull Webservices with JAX-RS (20)

PDF
Spark IT 2011 - Developing RESTful Web services with JAX-RS
PDF
JAX-RS JavaOne Hyderabad, India 2011
PPTX
PPTX
Ppt on web development and this has all details
PPTX
JAX-RS. Developing RESTful APIs with Java
PPT
ReST-ful Resource Management
PDF
JAX-RS Creating RESTFul services
PPT
Web services - REST and SOAP
PDF
Lab swe-2013intro jax-rs
PDF
Building RESTful applications using Spring MVC
PDF
Introduction to JAX-RS @ SIlicon Valley Code Camp 2010
PPTX
Building Restful Web Services with Java
PPTX
6 Months Industrial Training in Spring Framework
PDF
RESTful Java With JAX RS 1st Edition Bill Burke
PDF
Web Services, for DevDays Belfast
PPTX
JAX-RS 2.0 and OData
PDF
RESTful Java With JAX RS 1st Edition Bill Burke
PPTX
RESTful application with JAX-RS and how to expose and test them
PPTX
Restful webservices
Spark IT 2011 - Developing RESTful Web services with JAX-RS
JAX-RS JavaOne Hyderabad, India 2011
Ppt on web development and this has all details
JAX-RS. Developing RESTful APIs with Java
ReST-ful Resource Management
JAX-RS Creating RESTFul services
Web services - REST and SOAP
Lab swe-2013intro jax-rs
Building RESTful applications using Spring MVC
Introduction to JAX-RS @ SIlicon Valley Code Camp 2010
Building Restful Web Services with Java
6 Months Industrial Training in Spring Framework
RESTful Java With JAX RS 1st Edition Bill Burke
Web Services, for DevDays Belfast
JAX-RS 2.0 and OData
RESTful Java With JAX RS 1st Edition Bill Burke
RESTful application with JAX-RS and how to expose and test them
Restful webservices

More from Neil Ghosh (10)

PPTX
GOLD AG Report in IEEE Hyderabad AGM 2013
PPTX
Introduction to JavaFx and HTML5
PPTX
GOLD at IEEE Hyderabad SAGM 2012
PPT
Astronomy at Pecha Kuch Night Hyderabad Volume 9
PDF
Astro quiz
PPTX
IEEE GOLD STEP
PPT
Introduction to javaScript
PPT
Intro to web services
ODP
Creating REST Webservice With NetBeans
PPT
Edited
GOLD AG Report in IEEE Hyderabad AGM 2013
Introduction to JavaFx and HTML5
GOLD at IEEE Hyderabad SAGM 2012
Astronomy at Pecha Kuch Night Hyderabad Volume 9
Astro quiz
IEEE GOLD STEP
Introduction to javaScript
Intro to web services
Creating REST Webservice With NetBeans
Edited

Recently uploaded (20)

PPTX
Report in SIP_Distance_Learning_Technology_Impact.pptx
PDF
NewMind AI Journal Monthly Chronicles - August 2025
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
PPTX
maintenance powerrpoint for adaprive and preventive
PDF
【AI論文解説】高速・高品質な生成を実現するFlow Map Models(Part 1~3)
PPTX
Blending method and technology for hydrogen.pptx
PPTX
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
PDF
Intravenous drug administration application for pediatric patients via augmen...
PDF
The Basics of Artificial Intelligence - Understanding the Key Concepts and Te...
PPTX
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
PDF
ment.tech-How to Develop an AI Agent Healthcare App like Sully AI (1).pdf
PDF
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
PDF
Introduction to c language from lecture slides
PDF
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
PDF
Altius execution marketplace concept.pdf
PDF
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
PDF
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
PDF
Applying Agentic AI in Enterprise Automation
PDF
Peak of Data & AI Encore: Scalable Design & Infrastructure
PPTX
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
Report in SIP_Distance_Learning_Technology_Impact.pptx
NewMind AI Journal Monthly Chronicles - August 2025
Ebook - The Future of AI A Comprehensive Guide.pdf
maintenance powerrpoint for adaprive and preventive
【AI論文解説】高速・高品質な生成を実現するFlow Map Models(Part 1~3)
Blending method and technology for hydrogen.pptx
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
Intravenous drug administration application for pediatric patients via augmen...
The Basics of Artificial Intelligence - Understanding the Key Concepts and Te...
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
ment.tech-How to Develop an AI Agent Healthcare App like Sully AI (1).pdf
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
Introduction to c language from lecture slides
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
Altius execution marketplace concept.pdf
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
1_Keynote_Breaking Barriers_한계를 넘어서_Charith Mendis.pdf
Applying Agentic AI in Enterprise Automation
Peak of Data & AI Encore: Scalable Design & Infrastructure
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .

RestFull Webservices with JAX-RS

  • 1. Sabyasachi Ghosh, Senior Application Engneer Oracle India, @neilghosh Developing RESTful Web services with JAX-RS
  • 2. Java API for RESTful Web Services (JAX-RS) Standard annotation-driven API that aims to help developers build RESTful Web services in Java
  • 3. RESTful Application Cycle Resources are identified by URIs ↓ Clients communicate with resources via requests using a standard set of methods ↓ Requests and responses contain resource representations in formats identified by media types ↓ Responses contain URIs that link to further resources
  • 5. Standard set of methods
  • 9. ID is a URI http://example.com/widgets/foo http://example.com/customers/bar http://example.com/customers/bar/orders/2 http://example.com/orders/101230/customer
  • 10. Resources are identified by URIs Resource == Java class POJO
  • 11. No required interfaces ID provided by @Path annotation Value is relative URI, base URI is provided by deployment context or parent resource
  • 12. Embedded parameters for non-fixed parts of the URI
  • 13. Annotate class or “sub-resource locator” method
  • 14. Resources are identified by URIs @Path(&quot;orders/{order_id}&quot;) public class OrderResource { @GET @Path(&quot;customer&quot;) CustomerResource getCustomer( @PathParam(“order_id”)int id ) {...} }
  • 15. Standard Set of Methods Purpose Method Remove DELETE Update or create with a known ID PUT Update or create without a known ID POST Read, possibly cached GET
  • 16. Standard Set of Methods Annotate resource class methods with standard method @GET , @PUT , @POST , @DELETE , @HEAD
  • 17. @HttpMethod meta-annotation allows extensions, e.g. WebDAV JAX-RS routes request to appropriate resource class and method
  • 18. Flexible method signatures, annotations on parameters specify mapping from request
  • 19. Return value mapped to response
  • 20. Standard Set of Methods @Path(&quot;properties/ {name} &quot;) public class SystemProperty { @GET Property get(@PathParam(&quot; name &quot;) String name) {...} @PUT Property set(@PathParam(&quot; name &quot;) String name, String value ) {...} }
  • 21. Parameters Template parameters and Regular expressions @Path(&quot;customers/ {firstname}-{lastname} &quot;) @Path(&quot; { id : \\d+} &quot;) Matrix Parameters example.cars.com/mercedes/e55;color=black/2006 Query Paremetsrs DELETE /orders/233?cancel=true
  • 22. Multiple Representations Offer data in a variety of formats XML
  • 23. JSON
  • 25. Support content negotiation Accept header GET /foo Accept: application/json
  • 27. Content Negotiation: Accept Header Accept: application/xml Accept: application/json;q=1.0, text/xml;q=0.5, application/xml;q=0.5, @GET @Produces({&quot;application/xml&quot;,&quot;application/json&quot;}) Order getOrder(@PathParam(&quot; order_id &quot;) String id) { ... } @GET @Produces(&quot;text/plain&quot;) String getOrder2(@PathParam(&quot;order_id&quot;) String id) { ... }
  • 28. Content Negotiation: URL-based @Path(&quot;/orders&quot;) public class OrderResource { @Path(&quot;{orderId}.xml&quot;) @Produces(“application/xml”) @GET public Order getOrderInXML(@PathParam(&quot;orderId&quot;) String orderId) { . . . } @Path(&quot;{orderId}.json&quot;) @Produces(“application/json”) @GET public Order getOrderInJSON(@PathParam(&quot;orderId&quot;) String orderId) { . . . } }
  • 29. Content Negotiation import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.PathParam; @Path(&quot;/actor/{id}&quot;) @GET @Produces(&quot;application/json&quot;) @PathParam(&quot;id&quot;) import javax.inject.Inject; import javax.enterprise.context.RequestScoped; @RequestScoped public class ActorResource { @Inject DatbaseBean db; public Actor getActor( int id) { return db.findActorById(id); } }
  • 30. Link Things Together <order self=&quot; http://example.com/orders/101230 &quot;> <customer ref=&quot; http://example.com/customers/bar &quot;> <product ref=&quot; http://example.com/products/21034 &quot;/> <amount value=&quot;1&quot;/> </order>
  • 31. Responses Contain Links HTTP/1.1 201 Created Date: Wed, 03 Jun 2009 16:41:58 GMT Server: Apache/1.3.6 Location: http://example.com/properties/foo Content-Type: application/order+xml Content-Length: 184 <property self=&quot; http://example.com/properties/foo &quot;> <parent ref=&quot; http://example.com/properties/bar &quot;/> <name>Foo</name> <value>1</value> </order>
  • 32. Responses Contain Links UriInfo provides information about deployment context, the request URI and the route to the resource
  • 33. UriBuilder provides facilities to easily construct URIs for resources
  • 34. Responses Contain Links @Context UriInfo i; SystemProperty p = ... UriBuilder b = i.getBaseUriBuilder(); URI u = b.path(SystemProperties.class) .path(p.getName()).build(); List<URI> ancestors = i.getMatchedURIs(); URI parent = ancestors.get(1);
  • 35. Responses Contain Links UriBuilder builder = UriBuilder.fromPath(&quot;/customers/{id}&quot;); builder.scheme(&quot;http&quot;) .host(&quot;{hostname}&quot;) .queryParam(&quot;param={param}&quot;); http://{hostname}/customers/{id}?param={param} UriBuilder clone = builder.clone(); URI uri = clone.build(&quot;example.com&quot;, &quot;333&quot;, &quot;value&quot;); http://example.com/customers/333?param=value
  • 36. Response codes and Exception Successful HTTP : 200 to 399 200 – OK 204 – No Content Standard HTTP error : 400 to 599 404 – Not Found 406 - Not Acceptable 405 - Method Not Allowed java.lang.Exception java.lang.RuntimeException javax.ws.rs.WebApplicationException throw new WebApplicationException(Response.Status.NOT_FOUND);
  • 37. Stateless Communications Long lived identifiers
  • 39. Everything required to process a request contained in the request
  • 40. Deployment JAX-RS application packaged in WAR like a servlet
  • 41. For JAX-RS aware containers web.xml can point to Application subclass For non-JAX-RS aware containers web.xml points to implementation-specific Servlet ; and
  • 42. an init-param identifies the Application subclass Resource classes and providers can access Servlet request, context, config and response via injection
  • 43. JAX-RS 1.1 Integration with Java EE 6 – Servlets 3.0 No or Portable “web.xml” <web-app> <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>com.foo.MyApplication</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Jersey Web Application</servlet-name> <url-pattern>/ resources /*</url-pattern> </servlet-mapping> </web-app> public class MyApplication extends javax.ws.rs.core.Application { } @ApplicationPath(“resources”)
  • 44. JAX-RS Summary Java API for building RESTful Web Services
  • 49. JAX-RS 1.1 Jersey Client-side API Consume HTTP-based RESTful Services
  • 50. Easy-to-use Better than HttpURLConnection! Reuses JAX-RS API Resources and URI are first-class citizens Not part of JAX-RS yet com.sun.jersey.api.client
  • 51. JAX-RS 1.1 Jersey Client API – Code Sample Client client = Client.create(); WebResource resource = client.resource(“...”); //curl http://example.com/base String s = resource.get(String.class); //curl -HAccept:text/plain http://example.com/base String s = resource. accept(“text/plain”). get(String.class); http://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with
  • 52. JAX-RS 1.1 WADL Representation of Resources Machine processable description of HTTP-based Applications
  • 53. Generated OOTB for the application <application xmlns=&quot;http://research.sun.com/wadl/2006/10&quot;> <doc xmlns:jersey=&quot;http://jersey.dev.java.net/&quot; jersey:generatedBy=&quot;Jersey: 1.1.4.1 11/24/2009 01:37 AM&quot;/> <resources base=&quot; http://localhost:8080/HelloWADL/resources/ &quot;> <resource path=&quot;generic&quot;> <method id=&quot;getText&quot; name=&quot; GET &quot;> <response> <representation mediaType=&quot;text/plain&quot;/> </response> </method> <method id=&quot;putText&quot; name=&quot; PUT &quot;> <request> <representation mediaType=&quot;text/plain&quot;/> </request> </method> </resource> </resources> </application>
  • 58. Demo
  • 59. Sabyasachi Ghosh, Senior Application Engneer Oracle India, @neilghosh Developing RESTful Web services with JAX-RS Thank You