SlideShare a Scribd company logo
1 of 39
Download to read offline
<Insert Picture Here>




Introduction to JAX-RS
Jitendra Kotamraju

Oct 2010
What this presentation is about ?


• Not the REST style per se
      – But, briefly ...
• The basics of JAX-RS




                                    2
Agenda

            •      What is JAX-RS ?
            •      JAX-RS Resources
            •      Standard Methods (uniform interface)
            •      JAX-RS Representations
            •      Lots of demos using JAX-RS API
                           – @Path, HTTP methods, @Produces/@Consumes
                           – XML, JSON, @xxParam, Response, Application,
                           – Sub-resource locators, Injection etc




                                                                           3
©2010 Oracle Corporation
Very Short REST Primer:
Buy This Book




                          4
REST is an Architectural Style



                    Set of constraints you apply to the
                    architecture of a distributed system
                       to induce desirable properties




                                                           5
©2010 Oracle Corporation
RESTful Web Services



                      Application of REST architectural
                       style to services that utilize Web
                       standards (URIs, HTTP, HTML,
                             XML, Atom, RDF etc.)



                                                            6
©2010 Oracle Corporation
Java API for RESTful Web Services
(JAX-RS)



Standard annotation-driven API that
    aims to help developers build
   RESTful Web services in Java




                                      7
Status of JAX-RS

• JSR 311: JAX-RS 1.1 released Nov 2009
• Part of Java EE 6; Not part of the Web profile!
• Specifies integration with technologies:
      – CDI 1.0
      – EBJ 3.1
      – Servlet 3.0
• Jersey implementation shipped with GlassFish 3.x
• 7 implementations
      – Apache CXF, Apache Wink, eXo, Jersey, RESTEasy,
          Restlet, Triaxrs



                                                          8
Sample JAX-RS application


                               GlassFish
                                 hello.war
   GET /hello/world HTTP/1.1
                                      JAX-RS
                                      resource

    HTTP/1.1 200 OK
    Content-Type: text/xml
    <hello world/>




                                                 9
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



                                                           10
Resources are identified by URIs


http://example.com/widgets/foo

http://example.com/customers/bar

http://example.com/customers/bar/orders/2

http://example.com/orders/101230/customer




                                            11
JAX-RS Resources
            • Resource == Java class
                         – POJO, EJB Stateless, Singleton Session Beans
                      – 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




                                                                                12
©2010 Oracle Corporation
JAX-RS Resource URIs
            @Path("properties")
            public class Props {
              @GET
              List<Prop> getProperties(...) {...}

            }


            http://.../context/properties




                                                    13
©2010 Oracle Corporation
JAX-RS Sub-resources


• Root resources can declare sub-resources that will
  match the unmatched part of the URI path
• Root resources implement sub-resource locator
  methods




                                                       14
JAX-RS Sub-resources
            @Path("properties")
            public class Props {

                   @GET
                   @Path("{name}")
                   Prop getProperty(@PathParam("name")String p){…}
            }


            GET http://.../context/properties/java.home




                                                                 15
©2010 Oracle Corporation
JAX-RS Sub-resources
            @Path("properties")
            public class Props {
              @GET
              @Path("java.home")
              Prop getProperty() {…}

                   @Path("{name}")
                   Object getProp(@PathParam("name")String name){
                       return new Dyna(name); }
            }
            public class Dyna {
              @GET Prop getProperty() {…}
            }



                                                                    16
©2010 Oracle Corporation
JAX-RS Sub-resources
            @Path("properties")
            public class Props {
              @GET
              @Path("java.home")
              Prop getProperty() {…}

                   @Path("{name}")
                   Object getProp(@PathParam("name")String name){
                       return new Dyna(name); }
            }
            public class Dyna {
              @GET Prop getProperty() {…}
            }

            GET http://.../context/properties/java.home
                                                                    17
©2010 Oracle Corporation
JAX-RS Sub-resources
            @Path("properties")
            public class Props {
              @GET
              @Path("java.home")
              Prop getProperty() {…}

                   @Path("{name}")
                   Object getProp(@PathParam("name")String name){
                       return new Dyna(name); }
            }
            public class Dyna {
              @GET Prop getProperty() {…}
            }

            GET http://.../context/properties/java.home
                                                                    18
©2010 Oracle Corporation
JAX-RS Sub-resources
            @Path("properties")
            public class Props {
              @GET
              @Path("java.home")
              Prop getProperty() {…}

                   @Path("{name}")
                   Object getProp(@PathParam("name")String name){
                       return new Dyna(name); }
            }
            public class Dyna {
              @GET Prop getProperty() {…}
            }

            GET http://.../context/properties/java.home
                                                                    19
©2010 Oracle Corporation
JAX-RS Sub-resources
            @Path("properties")
            public class Props {
              @GET
              @Path("java.home")
              Prop getProperty() {…}

                   @Path("{name}")
                   Object getProp(@PathParam("name")String name){
                       return new Dyna(name); }
            }
            public class Dyna {
              @GET Prop getProperty() {…}
            }

            GET http://.../context/properties/java.tmp.dir
                                                                    20
©2010 Oracle Corporation
JAX-RS Sub-resources
            @Path("properties")
            public class Props {
              @GET
              @Path("java.home")
              Prop getProperty() {…}

                   @Path("{name}")
                   Object getProp(@PathParam("name")String name){
                       return new Dyna(name); }
            }
            public class Dyna {
              @GET Prop getProperty() {…}
            }

            GET http://.../context/properties/java.tmp.dir
                                                                    21
©2010 Oracle Corporation
JAX-RS Sub-resources
            @Path("properties")
            public class Props {
              @GET
              @Path("java.home")
              Prop getProperty() {…}

                   @Path("{name}")
                   Object getProp(@PathParam("name")String name){
                       return new Dyna(name); }
            }
            public class Dyna {
              @GET Prop getProperty() {…}
            }

            GET http://.../context/properties/java.tmp.dir
                                                                    22
©2010 Oracle Corporation
JAX-RS Sub-resources summary




• Sub-resource classes are processed at runtime
• Warning: easy to confuse sub-resource methods with
  sub-resource locators




                                                       23
Standard Set of Methods



     Method                    Purpose

    GET       Read, possibly cached

    POST      Update or create without a known ID

    PUT       Update or create with a known ID

    DELETE    Remove




                                                    24
JAX-RS 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



                                                            25
JAX-RS HTTP Methods

        @Path("properties/{name}")
        public class Props {

               @GET
               Prop get(@PathParam("name") String name)
                 {...}

               @PUT
               Prop set(@PathParam("name") String name,
                 String value) {...}

        }


                                                          26
©2010 Oracle Corporation
Resource Representations

• Representation format identified by media type. E.g.:
   – XML - application/properties+xml
   – JSON - application/properties+json
   – (X)HTML+microformats - application/xhtml+xml
• JAX-RS automates content negotiation
   – GET /foo
     Accept: application/properties+json




                                                          27
Resource Representations

• Annotate methods or classes with static capabilities
   – @Produces, @Consumes
• Use Variant, VariantListBuilder and
  Request.selectVariant for dynamic capabilities
      – Also supports language and encoding




                                                         28
JAX-RS Resource Representations

@GET
@Produces("application/properties+xml")
Prop getXml(@PathParam("name") String name) {
  ...
}

@GET
@Produces("text/plain")
String getText(@PathParam("name") String name)
{
  ...
}




                                                 29
JAX-RS Resource Representations

@POST
@Consumes("application/xml")
@Produces({"application/xml","application/json"})
Customer getCustomer(Source id) {
  …
  return customer;
}

@XmlRootElement
class Customer {
  public String first;
  public String last;
}



                                                30
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="http://example.com/properties/foo">
  <parent ref="http://example.com/properties/bar"/>
  <name>Foo</name>
  <value>1</value>
</order>




                                                      31
Responses Contain Links
• UriInfo provides information about deployment
  context, the request URI and the route to the resource
• UriBuilder provides facilities to easily construct URIs
  for resources




                                                            32
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);




                                                          33
©2010 Oracle Corporation
Demos




        34
The future of JAX-RS


• Possible features in scope for a JAX-RS 2.0 effort
      –   Client API
      –   Declarative hyperlinking
      –   Model View Controller
      –   Quality of Source
      –   Form validation
      –   Asynchronous/Comet/WebSocket
      –   Improved integration with JSR-330 and @Inject
      –   JAX-RS Modules




                                                          35
Information

•   JSR-311: http://jsr311.dev.java.net/
•   http://jersey.dev.java.net
•   mailto:users@jersey.dev.java.net
•   http://glassfish.dev.java.net




                                           36
Questions ?




              37
Servlet
   JAX-RS application packaged in WAR like a servlet
   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
   an init-param identifies the Application subclass
   Resource classes and providers can access Servlet
   request, context, config and response via injection




                                                         38
©2010 Oracle Corporation
Java EE

Resource class can be an EJB session or singleton bean
Providers can be an EJB stateless session or singleton
   bean
JAX-RS annotations on local interface or no-interface
   bean
If JCDI (JSR 299) also supported then
   Resource classes can be JCDI beans
   Providers can be JCDI beans with application
    scope
Full access to facilities of native component model, e.g.
  resource injection


                                                            39

More Related Content

What's hot

JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonJAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonArun Gupta
 
Json to hive_schema_generator
Json to hive_schema_generatorJson to hive_schema_generator
Json to hive_schema_generatorPayal Jain
 
04 darwino concepts and utility classes
04   darwino concepts and utility classes04   darwino concepts and utility classes
04 darwino concepts and utility classesdarwinodb
 
Oak Lucene Indexes
Oak Lucene IndexesOak Lucene Indexes
Oak Lucene IndexesChetan Mehrotra
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaAnatole Tresch
 
Java and SPARQL
Java and SPARQLJava and SPARQL
Java and SPARQLRaji Ghawi
 
10 jdbc
10 jdbc10 jdbc
10 jdbcsnopteck
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginsearchbox-com
 
Practical AtomPub Servers @ YAPC::Asia 2008
Practical AtomPub Servers @ YAPC::Asia 2008Practical AtomPub Servers @ YAPC::Asia 2008
Practical AtomPub Servers @ YAPC::Asia 2008Takeru INOUE
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scalab0ris_1
 
A first Draft to Java Configuration
A first Draft to Java ConfigurationA first Draft to Java Configuration
A first Draft to Java ConfigurationAnatole Tresch
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
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!Dan Allen
 
070517 Jena
070517 Jena070517 Jena
070517 Jenayuhana
 
JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013Jagadish Prasath
 
PHP Oracle
PHP OraclePHP Oracle
PHP OracleNur Hidayat
 
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextFind Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextCarsten Czarski
 
Object Relational model for SQLIite in android
Object Relational model for SQLIite  in android Object Relational model for SQLIite  in android
Object Relational model for SQLIite in android yugandhar vadlamudi
 

What's hot (20)

JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonJAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
 
Json to hive_schema_generator
Json to hive_schema_generatorJson to hive_schema_generator
Json to hive_schema_generator
 
04 darwino concepts and utility classes
04   darwino concepts and utility classes04   darwino concepts and utility classes
04 darwino concepts and utility classes
 
Oak Lucene Indexes
Oak Lucene IndexesOak Lucene Indexes
Oak Lucene Indexes
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache Tamaya
 
Java and SPARQL
Java and SPARQLJava and SPARQL
Java and SPARQL
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
 
Practical AtomPub Servers @ YAPC::Asia 2008
Practical AtomPub Servers @ YAPC::Asia 2008Practical AtomPub Servers @ YAPC::Asia 2008
Practical AtomPub Servers @ YAPC::Asia 2008
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
 
A first Draft to Java Configuration
A first Draft to Java ConfigurationA first Draft to Java Configuration
A first Draft to Java Configuration
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
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!
 
070517 Jena
070517 Jena070517 Jena
070517 Jena
 
JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
PHP Oracle
PHP OraclePHP Oracle
PHP Oracle
 
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextFind Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
 
Object Relational model for SQLIite in android
Object Relational model for SQLIite  in android Object Relational model for SQLIite  in android
Object Relational model for SQLIite in android
 

Viewers also liked

Spark IT 2011 - Developing RESTful Web services with JAX-RS
Spark IT 2011 - Developing RESTful Web services with JAX-RSSpark IT 2011 - Developing RESTful Web services with JAX-RS
Spark IT 2011 - Developing RESTful Web services with JAX-RSArun Gupta
 
TDC 2011: OSGi-enabled Java EE Application
TDC 2011: OSGi-enabled Java EE ApplicationTDC 2011: OSGi-enabled Java EE Application
TDC 2011: OSGi-enabled Java EE ApplicationArun Gupta
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration BackendArun Gupta
 
Java Summit Chennai: Java EE 7
Java Summit Chennai: Java EE 7Java Summit Chennai: Java EE 7
Java Summit Chennai: Java EE 7Arun Gupta
 
The Java EE 7 Platform: Developing for the Cloud
The Java EE 7 Platform: Developing for the CloudThe Java EE 7 Platform: Developing for the Cloud
The Java EE 7 Platform: Developing for the CloudArun Gupta
 
5050 dev nation
5050 dev nation5050 dev nation
5050 dev nationArun Gupta
 
Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012
Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012
Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012Arun Gupta
 

Viewers also liked (7)

Spark IT 2011 - Developing RESTful Web services with JAX-RS
Spark IT 2011 - Developing RESTful Web services with JAX-RSSpark IT 2011 - Developing RESTful Web services with JAX-RS
Spark IT 2011 - Developing RESTful Web services with JAX-RS
 
TDC 2011: OSGi-enabled Java EE Application
TDC 2011: OSGi-enabled Java EE ApplicationTDC 2011: OSGi-enabled Java EE Application
TDC 2011: OSGi-enabled Java EE Application
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 
Java Summit Chennai: Java EE 7
Java Summit Chennai: Java EE 7Java Summit Chennai: Java EE 7
Java Summit Chennai: Java EE 7
 
The Java EE 7 Platform: Developing for the Cloud
The Java EE 7 Platform: Developing for the CloudThe Java EE 7 Platform: Developing for the Cloud
The Java EE 7 Platform: Developing for the Cloud
 
5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
 
Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012
Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012
Java EE 7: Developing for the Cloud at Java Day, Istanbul, May 2012
 

Similar to Introduction to JAX-RS @ SIlicon Valley Code Camp 2010

RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RSArun Gupta
 
JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesLudovic Champenois
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6Yuval Ararat
 
XML Technologies for RESTful Services Development
XML Technologies for RESTful Services DevelopmentXML Technologies for RESTful Services Development
XML Technologies for RESTful Services Developmentruyalarcon
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
Lab swe-2013intro jax-rs
Lab swe-2013intro jax-rsLab swe-2013intro jax-rs
Lab swe-2013intro jax-rsAravindharamanan S
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India
 
Rest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerRest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerKumaraswamy M
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0Dmytro Chyzhykov
 
Javaone 2010
Javaone 2010Javaone 2010
Javaone 2010Hien Luu
 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all detailsgogijoshiajmer
 
Unsafe JAX-RS: Breaking REST API
Unsafe JAX-RS: Breaking REST APIUnsafe JAX-RS: Breaking REST API
Unsafe JAX-RS: Breaking REST APIMikhail Egorov
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010Arun Gupta
 
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX London
 
OrientDB introduction - NoSQL
OrientDB introduction - NoSQLOrientDB introduction - NoSQL
OrientDB introduction - NoSQLLuca Garulli
 
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalacheIasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalacheCodecamp Romania
 
JSUG - RESTful Web Services by Florian Motlik
JSUG - RESTful Web Services by Florian MotlikJSUG - RESTful Web Services by Florian Motlik
JSUG - RESTful Web Services by Florian MotlikChristoph Pickl
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 

Similar to Introduction to JAX-RS @ SIlicon Valley Code Camp 2010 (20)

RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RS
 
JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul services
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
XML Technologies for RESTful Services Development
XML Technologies for RESTful Services DevelopmentXML Technologies for RESTful Services Development
XML Technologies for RESTful Services Development
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
Lab swe-2013intro jax-rs
Lab swe-2013intro jax-rsLab swe-2013intro jax-rs
Lab swe-2013intro jax-rs
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
 
Rest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerRest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swagger
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0Making Java REST with JAX-RS 2.0
Making Java REST with JAX-RS 2.0
 
Javaone 2010
Javaone 2010Javaone 2010
Javaone 2010
 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all details
 
Jersey
JerseyJersey
Jersey
 
Unsafe JAX-RS: Breaking REST API
Unsafe JAX-RS: Breaking REST APIUnsafe JAX-RS: Breaking REST API
Unsafe JAX-RS: Breaking REST API
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
 
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
 
OrientDB introduction - NoSQL
OrientDB introduction - NoSQLOrientDB introduction - NoSQL
OrientDB introduction - NoSQL
 
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalacheIasi code camp 12 october 2013   jax-rs-jee-ecosystem - catalin mihalache
Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache
 
JSUG - RESTful Web Services by Florian Motlik
JSUG - RESTful Web Services by Florian MotlikJSUG - RESTful Web Services by Florian Motlik
JSUG - RESTful Web Services by Florian Motlik
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 

More from Arun Gupta

5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdfArun Gupta
 
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Arun Gupta
 
Machine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesMachine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesArun Gupta
 
Secure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerSecure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerArun Gupta
 
Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Arun Gupta
 
Why Amazon Cares about Open Source
Why Amazon Cares about Open SourceWhy Amazon Cares about Open Source
Why Amazon Cares about Open SourceArun Gupta
 
Machine learning using Kubernetes
Machine learning using KubernetesMachine learning using Kubernetes
Machine learning using KubernetesArun Gupta
 
Building Cloud Native Applications
Building Cloud Native ApplicationsBuilding Cloud Native Applications
Building Cloud Native ApplicationsArun Gupta
 
Chaos Engineering with Kubernetes
Chaos Engineering with KubernetesChaos Engineering with Kubernetes
Chaos Engineering with KubernetesArun Gupta
 
How to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMHow to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMArun Gupta
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Arun Gupta
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteArun Gupta
 
Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Arun Gupta
 
Mastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitMastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitArun Gupta
 
Top 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeTop 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeArun Gupta
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017Arun Gupta
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftArun Gupta
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersArun Gupta
 
Thanks Managers!
Thanks Managers!Thanks Managers!
Thanks Managers!Arun Gupta
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersArun Gupta
 

More from Arun Gupta (20)

5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf
 
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019
 
Machine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesMachine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and Kubernetes
 
Secure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerSecure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using Firecracker
 
Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019
 
Why Amazon Cares about Open Source
Why Amazon Cares about Open SourceWhy Amazon Cares about Open Source
Why Amazon Cares about Open Source
 
Machine learning using Kubernetes
Machine learning using KubernetesMachine learning using Kubernetes
Machine learning using Kubernetes
 
Building Cloud Native Applications
Building Cloud Native ApplicationsBuilding Cloud Native Applications
Building Cloud Native Applications
 
Chaos Engineering with Kubernetes
Chaos Engineering with KubernetesChaos Engineering with Kubernetes
Chaos Engineering with Kubernetes
 
How to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMHow to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAM
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 Keynote
 
Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018
 
Mastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitMastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv Summit
 
Top 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeTop 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's Landscape
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShift
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developers
 
Thanks Managers!
Thanks Managers!Thanks Managers!
Thanks Managers!
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to Containers
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Introduction to JAX-RS @ SIlicon Valley Code Camp 2010

  • 1. <Insert Picture Here> Introduction to JAX-RS Jitendra Kotamraju Oct 2010
  • 2. What this presentation is about ? • Not the REST style per se – But, briefly ... • The basics of JAX-RS 2
  • 3. Agenda • What is JAX-RS ? • JAX-RS Resources • Standard Methods (uniform interface) • JAX-RS Representations • Lots of demos using JAX-RS API – @Path, HTTP methods, @Produces/@Consumes – XML, JSON, @xxParam, Response, Application, – Sub-resource locators, Injection etc 3 ©2010 Oracle Corporation
  • 4. Very Short REST Primer: Buy This Book 4
  • 5. REST is an Architectural Style Set of constraints you apply to the architecture of a distributed system to induce desirable properties 5 ©2010 Oracle Corporation
  • 6. RESTful Web Services Application of REST architectural style to services that utilize Web standards (URIs, HTTP, HTML, XML, Atom, RDF etc.) 6 ©2010 Oracle Corporation
  • 7. Java API for RESTful Web Services (JAX-RS) Standard annotation-driven API that aims to help developers build RESTful Web services in Java 7
  • 8. Status of JAX-RS • JSR 311: JAX-RS 1.1 released Nov 2009 • Part of Java EE 6; Not part of the Web profile! • Specifies integration with technologies: – CDI 1.0 – EBJ 3.1 – Servlet 3.0 • Jersey implementation shipped with GlassFish 3.x • 7 implementations – Apache CXF, Apache Wink, eXo, Jersey, RESTEasy, Restlet, Triaxrs 8
  • 9. Sample JAX-RS application GlassFish hello.war GET /hello/world HTTP/1.1 JAX-RS resource HTTP/1.1 200 OK Content-Type: text/xml <hello world/> 9
  • 10. 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 10
  • 11. Resources are identified by URIs http://example.com/widgets/foo http://example.com/customers/bar http://example.com/customers/bar/orders/2 http://example.com/orders/101230/customer 11
  • 12. JAX-RS Resources • Resource == Java class – POJO, EJB Stateless, Singleton Session Beans – 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 12 ©2010 Oracle Corporation
  • 13. JAX-RS Resource URIs @Path("properties") public class Props { @GET List<Prop> getProperties(...) {...} } http://.../context/properties 13 ©2010 Oracle Corporation
  • 14. JAX-RS Sub-resources • Root resources can declare sub-resources that will match the unmatched part of the URI path • Root resources implement sub-resource locator methods 14
  • 15. JAX-RS Sub-resources @Path("properties") public class Props { @GET @Path("{name}") Prop getProperty(@PathParam("name")String p){…} } GET http://.../context/properties/java.home 15 ©2010 Oracle Corporation
  • 16. JAX-RS Sub-resources @Path("properties") public class Props { @GET @Path("java.home") Prop getProperty() {…} @Path("{name}") Object getProp(@PathParam("name")String name){ return new Dyna(name); } } public class Dyna { @GET Prop getProperty() {…} } 16 ©2010 Oracle Corporation
  • 17. JAX-RS Sub-resources @Path("properties") public class Props { @GET @Path("java.home") Prop getProperty() {…} @Path("{name}") Object getProp(@PathParam("name")String name){ return new Dyna(name); } } public class Dyna { @GET Prop getProperty() {…} } GET http://.../context/properties/java.home 17 ©2010 Oracle Corporation
  • 18. JAX-RS Sub-resources @Path("properties") public class Props { @GET @Path("java.home") Prop getProperty() {…} @Path("{name}") Object getProp(@PathParam("name")String name){ return new Dyna(name); } } public class Dyna { @GET Prop getProperty() {…} } GET http://.../context/properties/java.home 18 ©2010 Oracle Corporation
  • 19. JAX-RS Sub-resources @Path("properties") public class Props { @GET @Path("java.home") Prop getProperty() {…} @Path("{name}") Object getProp(@PathParam("name")String name){ return new Dyna(name); } } public class Dyna { @GET Prop getProperty() {…} } GET http://.../context/properties/java.home 19 ©2010 Oracle Corporation
  • 20. JAX-RS Sub-resources @Path("properties") public class Props { @GET @Path("java.home") Prop getProperty() {…} @Path("{name}") Object getProp(@PathParam("name")String name){ return new Dyna(name); } } public class Dyna { @GET Prop getProperty() {…} } GET http://.../context/properties/java.tmp.dir 20 ©2010 Oracle Corporation
  • 21. JAX-RS Sub-resources @Path("properties") public class Props { @GET @Path("java.home") Prop getProperty() {…} @Path("{name}") Object getProp(@PathParam("name")String name){ return new Dyna(name); } } public class Dyna { @GET Prop getProperty() {…} } GET http://.../context/properties/java.tmp.dir 21 ©2010 Oracle Corporation
  • 22. JAX-RS Sub-resources @Path("properties") public class Props { @GET @Path("java.home") Prop getProperty() {…} @Path("{name}") Object getProp(@PathParam("name")String name){ return new Dyna(name); } } public class Dyna { @GET Prop getProperty() {…} } GET http://.../context/properties/java.tmp.dir 22 ©2010 Oracle Corporation
  • 23. JAX-RS Sub-resources summary • Sub-resource classes are processed at runtime • Warning: easy to confuse sub-resource methods with sub-resource locators 23
  • 24. Standard Set of Methods Method Purpose GET Read, possibly cached POST Update or create without a known ID PUT Update or create with a known ID DELETE Remove 24
  • 25. JAX-RS 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 25
  • 26. JAX-RS HTTP Methods @Path("properties/{name}") public class Props { @GET Prop get(@PathParam("name") String name) {...} @PUT Prop set(@PathParam("name") String name, String value) {...} } 26 ©2010 Oracle Corporation
  • 27. Resource Representations • Representation format identified by media type. E.g.: – XML - application/properties+xml – JSON - application/properties+json – (X)HTML+microformats - application/xhtml+xml • JAX-RS automates content negotiation – GET /foo Accept: application/properties+json 27
  • 28. Resource Representations • Annotate methods or classes with static capabilities – @Produces, @Consumes • Use Variant, VariantListBuilder and Request.selectVariant for dynamic capabilities – Also supports language and encoding 28
  • 29. JAX-RS Resource Representations @GET @Produces("application/properties+xml") Prop getXml(@PathParam("name") String name) { ... } @GET @Produces("text/plain") String getText(@PathParam("name") String name) { ... } 29
  • 30. JAX-RS Resource Representations @POST @Consumes("application/xml") @Produces({"application/xml","application/json"}) Customer getCustomer(Source id) { … return customer; } @XmlRootElement class Customer { public String first; public String last; } 30
  • 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="http://example.com/properties/foo"> <parent ref="http://example.com/properties/bar"/> <name>Foo</name> <value>1</value> </order> 31
  • 32. Responses Contain Links • UriInfo provides information about deployment context, the request URI and the route to the resource • UriBuilder provides facilities to easily construct URIs for resources 32
  • 33. 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); 33 ©2010 Oracle Corporation
  • 34. Demos 34
  • 35. The future of JAX-RS • Possible features in scope for a JAX-RS 2.0 effort – Client API – Declarative hyperlinking – Model View Controller – Quality of Source – Form validation – Asynchronous/Comet/WebSocket – Improved integration with JSR-330 and @Inject – JAX-RS Modules 35
  • 36. Information • JSR-311: http://jsr311.dev.java.net/ • http://jersey.dev.java.net • mailto:users@jersey.dev.java.net • http://glassfish.dev.java.net 36
  • 38. Servlet JAX-RS application packaged in WAR like a servlet 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 an init-param identifies the Application subclass Resource classes and providers can access Servlet request, context, config and response via injection 38 ©2010 Oracle Corporation
  • 39. Java EE Resource class can be an EJB session or singleton bean Providers can be an EJB stateless session or singleton bean JAX-RS annotations on local interface or no-interface bean If JCDI (JSR 299) also supported then Resource classes can be JCDI beans Providers can be JCDI beans with application scope Full access to facilities of native component model, e.g. resource injection 39