SlideShare a Scribd company logo
1 of 31
Download to read offline
The following is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.
The development, release, and timing of any
features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.




                                                      1
<Insert Picture Here>




Creating RESTful Web Services using JAX-RS
Ludovic Champenois
Architect GlassFish – NetBeans - Eclipse
Agenda


• REST and JAX-RS      <Insert Picture Here>

• Deployment Options
• Demo
• Status
• Q&A




                                          3
REST is an Architectural Style


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




                                                          4
RESTful Web Services


• Application of REST architectural style to services
 that utilize Web standards:

• URIs, HTTP, MIME, HTML, XML, Atom, RDF, ...




                                                        5
Java API for RESTful Web Services (JAX-RS)


• Standard annotation-driven API that aims to help
  developers build RESTful Web services in Java™
• JSR 311
• Part of Java EE 6 now




                                                     6
RESTful Application Cycle


            Resources are identified by URIs
                             ↓
 Clients communicate with resources via requests using a
              standard set of HTTP methods
                             ↓
Requests and responses contain resource representations in
            formats identified by media types
                             ↓
   Responses contain URIs that link to further resources




                                                             7
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




                                              8
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




                                                       9
Resources are identified by URIs


@Path("properties")
public class SystemProperties {
  @GET
  List<SystemProperty> getProperties(...) {...}

    @Path("{name}")
    SystemProperty getProperty(...) {...}
}




                                                  10
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




                                                     11
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



                                                        12
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) {...}

}



                                                   13
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




                                                          14
Resource Representations
Static and dynamic content negotiation

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




                                                         15
Resource Representations


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

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




                                                   16
Responses Contain Links



HTTP/1.1 201 Created
Date: Wed, 08 Dec 2010 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>




                                                      17
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




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




                                            19
Agenda


• REST and JAX-RS      <Insert Picture Here>

• Deployment Options
• Demo
• Status
• Q&A




                                         20
Java SE Deployment


• RuntimeDelegate is used to create instances of a
  desired endpoint class
• Application supplies configuration information
  – List of resource classes and providers as subclass of
    Application
• Implementations can support any Java type
   – Jersey supports Grizzly and the LW HTTP server in Sun's
     JDK.




                                                               21
Example Java SE Deployment



Application app = ...
RuntimeDelegate rd =
RuntimeDelegate.getInstance();
Adapter a = rd.createEndpoint(app,
Adapter.class);

SelectorThread st = GrizzlyServerFactory.create(
    “http://127.0.0.1:8084/”, a);




                                                   22
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




                                                              23
Java EE


• Resource class can be an EJB session or singleton bean
  or CDI Beans
• Providers can be an EJB stateless session or singleton
  bean
• JAX-RS annotations on local interface or no-interface
  bean
• Full access to facilities of native component model, e.g.
  resource injection




                                                              24
EJB with JAX-RS




@Path("stateless-bean")
@Stateless
public class StatelessResource { … }

@Path("singleton-bean")
@Singleton
public class SingletonResource { … }




                                       25
CDI and JAX-RS
• General CDI requirement: beans.xml needs to be declared to
 enable CDI managed beans
  – e.g. empty WEB-INF/beans.xml in war
• Root resource classes need to be annotated with a CDI scope


    @Path("request-scoped")
    @RequestScoped
    public class RequestScopedResource { … }

    @Path("application-scoped")
    @ApplicationScoped
    public class ApplicationScopedResource { … }


                                                           26
Servlet 3.0 and JAX-RS

• No WEB-INF/web.xml for simple deployments
• Use extension of javax.ws.rs.Application and
 @javax.ws.rs.ApplicationPath

   @ApplicationPath("resources”)
   public class MyApp extends Application { ... }
• Use WEB-INF/web.xml for portable deployments
   <web-app version="3.0">
   <servlet>
     <servlet-name>Jersey Web
   Application</servlet-name>
     <servlet-class>...MyApp</servlet-class>


                                                    27
Agenda


• REST and JAX-RS                            <Insert Picture Here>

• Deployment Options
• Demo
   – Matching URLs,
   – Consuming POST Requests (@POST, @FormParam)
   – GlassFish Admin Backend: A REST Application
• Status
• Q&A




                                                               28
Agenda


• REST and JAX-RS      <Insert Picture Here>

• Deployment Options
• Demo
• Status
• Q&A




                                         29
Status


• JAX-RS 1.0: 18th October 2008
• JAX-RS 1.1: 23rd November 2009
   – Aligned with Java EE 6, but not in the Web profile!
• JAX-RS 2.0: Future<?>
   – Draft JSR 12th November 2010
   – Like to submit to JCP in December or early next year
   – http://bit.ly/bkXtay
• Implementations
   – Apache CXF, Apache Wink, eXo, Jersey, RESTEasy, Restlet,
     Triaxrs




                                                                30
Agenda


• REST and JAX-RS      <Insert Picture Here>

• Deployment Options
• Demo
• Status
• Q&A




                                         31

More Related Content

What's hot

Anypoint connectorfor ibm as 400
Anypoint connectorfor ibm as 400Anypoint connectorfor ibm as 400
Anypoint connectorfor ibm as 400himajareddys
 
File connector
File connectorFile connector
File connectorkrishashi
 
Concepts in mule
Concepts in muleConcepts in mule
Concepts in muleSindhu VL
 
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esbSend email attachment using smtp in mule esb
Send email attachment using smtp in mule esbPraneethchampion
 
Mule ESB - Mock Salesforce Interface
Mule ESB - Mock Salesforce InterfaceMule ESB - Mock Salesforce Interface
Mule ESB - Mock Salesforce Interfacekrishananth
 
File component in mule
File component in muleFile component in mule
File component in muleRajkattamuri
 
Message properties component in mule
Message properties component in muleMessage properties component in mule
Message properties component in muleKhan625
 

What's hot (15)

Mule soap
Mule soapMule soap
Mule soap
 
Anypoint connectorfor ibm as 400
Anypoint connectorfor ibm as 400Anypoint connectorfor ibm as 400
Anypoint connectorfor ibm as 400
 
File connector
File connectorFile connector
File connector
 
Mule Webservices
Mule WebservicesMule Webservices
Mule Webservices
 
Propertiesinmule
PropertiesinmulePropertiesinmule
Propertiesinmule
 
Configurare http mule
Configurare http muleConfigurare http mule
Configurare http mule
 
Xslt in mule
Xslt in muleXslt in mule
Xslt in mule
 
Concepts in mule
Concepts in muleConcepts in mule
Concepts in mule
 
Mule esb :Data Weave
Mule esb :Data WeaveMule esb :Data Weave
Mule esb :Data Weave
 
Send email attachment using smtp in mule esb
Send email attachment using smtp in mule esbSend email attachment using smtp in mule esb
Send email attachment using smtp in mule esb
 
Mule Message Properties Component
Mule Message Properties ComponentMule Message Properties Component
Mule Message Properties Component
 
xslt in mule
xslt in mulexslt in mule
xslt in mule
 
Mule ESB - Mock Salesforce Interface
Mule ESB - Mock Salesforce InterfaceMule ESB - Mock Salesforce Interface
Mule ESB - Mock Salesforce Interface
 
File component in mule
File component in muleFile component in mule
File component in mule
 
Message properties component in mule
Message properties component in muleMessage properties component in mule
Message properties component in mule
 

Similar to JAX-RS Creating RESTFul services

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
 
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 JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
JAX - RS MuleSoft ESB
JAX - RS MuleSoft ESBJAX - RS MuleSoft ESB
JAX - RS MuleSoft ESBAnkit Shah
 
Building Restful Web Services with Java
Building Restful Web Services with JavaBuilding Restful Web Services with Java
Building Restful Web Services with JavaVassil Popovski
 
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
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsSagara Gunathunga
 
RESTful Web Service using Swagger
RESTful Web Service using SwaggerRESTful Web Service using Swagger
RESTful Web Service using SwaggerHong-Jhih Lin
 
RESTful application with JAX-RS and how to expose and test them
RESTful application with JAX-RS and how to expose and test themRESTful application with JAX-RS and how to expose and test them
RESTful application with JAX-RS and how to expose and test themKumaraswamy M
 
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
 
JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup Sagara Gunathunga
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionArabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionJasonRafeMiller
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Arun Gupta
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you pownedDinis Cruz
 

Similar to JAX-RS Creating RESTFul services (20)

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
 
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 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
 
JAX - RS MuleSoft ESB
JAX - RS MuleSoft ESBJAX - RS MuleSoft ESB
JAX - RS MuleSoft ESB
 
Building Restful Web Services with Java
Building Restful Web Services with JavaBuilding Restful Web Services with Java
Building Restful Web Services with Java
 
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
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
Life outside WO
Life outside WOLife outside WO
Life outside WO
 
RESTful Web Service using Swagger
RESTful Web Service using SwaggerRESTful Web Service using Swagger
RESTful Web Service using Swagger
 
RESTful application with JAX-RS and how to expose and test them
RESTful application with JAX-RS and how to expose and test themRESTful application with JAX-RS and how to expose and test them
RESTful application with JAX-RS and how to expose and test them
 
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
 
JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
Andrei shakirin rest_cxf
Andrei shakirin rest_cxfAndrei shakirin rest_cxf
Andrei shakirin rest_cxf
 
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionArabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
 
Rest
RestRest
Rest
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you powned
 

More from Ludovic Champenois

Java EE 6, Eclipse, GlassFish @EclipseCon 2010
Java EE 6, Eclipse, GlassFish @EclipseCon 2010Java EE 6, Eclipse, GlassFish @EclipseCon 2010
Java EE 6, Eclipse, GlassFish @EclipseCon 2010Ludovic Champenois
 
Java EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConJava EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConLudovic Champenois
 
GlassFish v3, OSGi Equinox Felix
GlassFish v3, OSGi Equinox FelixGlassFish v3, OSGi Equinox Felix
GlassFish v3, OSGi Equinox FelixLudovic Champenois
 
GlassFish Tool Bundle for Eclipse
GlassFish Tool Bundle for EclipseGlassFish Tool Bundle for Eclipse
GlassFish Tool Bundle for EclipseLudovic Champenois
 

More from Ludovic Champenois (6)

JavaEE 6 tools coverage
JavaEE 6 tools coverageJavaEE 6 tools coverage
JavaEE 6 tools coverage
 
S313431 JPA 2.0 Overview
S313431 JPA 2.0 OverviewS313431 JPA 2.0 Overview
S313431 JPA 2.0 Overview
 
Java EE 6, Eclipse, GlassFish @EclipseCon 2010
Java EE 6, Eclipse, GlassFish @EclipseCon 2010Java EE 6, Eclipse, GlassFish @EclipseCon 2010
Java EE 6, Eclipse, GlassFish @EclipseCon 2010
 
Java EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConJava EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseCon
 
GlassFish v3, OSGi Equinox Felix
GlassFish v3, OSGi Equinox FelixGlassFish v3, OSGi Equinox Felix
GlassFish v3, OSGi Equinox Felix
 
GlassFish Tool Bundle for Eclipse
GlassFish Tool Bundle for EclipseGlassFish Tool Bundle for Eclipse
GlassFish Tool Bundle for Eclipse
 

JAX-RS Creating RESTFul services

  • 1. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 1
  • 2. <Insert Picture Here> Creating RESTful Web Services using JAX-RS Ludovic Champenois Architect GlassFish – NetBeans - Eclipse
  • 3. Agenda • REST and JAX-RS <Insert Picture Here> • Deployment Options • Demo • Status • Q&A 3
  • 4. REST is an Architectural Style • Set of constraints you apply to the architecture of a distributed system to induce desirable properties 4
  • 5. RESTful Web Services • Application of REST architectural style to services that utilize Web standards: • URIs, HTTP, MIME, HTML, XML, Atom, RDF, ... 5
  • 6. Java API for RESTful Web Services (JAX-RS) • Standard annotation-driven API that aims to help developers build RESTful Web services in Java™ • JSR 311 • Part of Java EE 6 now 6
  • 7. RESTful Application Cycle Resources are identified by URIs ↓ Clients communicate with resources via requests using a standard set of HTTP methods ↓ Requests and responses contain resource representations in formats identified by media types ↓ Responses contain URIs that link to further resources 7
  • 8. 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 8
  • 9. 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 9
  • 10. Resources are identified by URIs @Path("properties") public class SystemProperties { @GET List<SystemProperty> getProperties(...) {...} @Path("{name}") SystemProperty getProperty(...) {...} } 10
  • 11. 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 11
  • 12. 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 12
  • 13. 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) {...} } 13
  • 14. 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 14
  • 15. Resource Representations Static and dynamic content negotiation • Annotate methods or classes with static capabilities – @Produces, @Consumes • Use Variant, VariantListBuilder and Request.selectVariant for dynamic capabilities • Also supports language and encoding 15
  • 16. Resource Representations @GET @Produces("application/properties+xml") Property getXml(@PathParam("name") String name) { ... } @GET @Produces("text/plain") String getText(@PathParam("name") String name) { ... } 16
  • 17. Responses Contain Links HTTP/1.1 201 Created Date: Wed, 08 Dec 2010 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> 17
  • 18. 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 18
  • 19. 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); 19
  • 20. Agenda • REST and JAX-RS <Insert Picture Here> • Deployment Options • Demo • Status • Q&A 20
  • 21. Java SE Deployment • RuntimeDelegate is used to create instances of a desired endpoint class • Application supplies configuration information – List of resource classes and providers as subclass of Application • Implementations can support any Java type – Jersey supports Grizzly and the LW HTTP server in Sun's JDK. 21
  • 22. Example Java SE Deployment Application app = ... RuntimeDelegate rd = RuntimeDelegate.getInstance(); Adapter a = rd.createEndpoint(app, Adapter.class); SelectorThread st = GrizzlyServerFactory.create( “http://127.0.0.1:8084/”, a); 22
  • 23. 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 23
  • 24. Java EE • Resource class can be an EJB session or singleton bean or CDI Beans • Providers can be an EJB stateless session or singleton bean • JAX-RS annotations on local interface or no-interface bean • Full access to facilities of native component model, e.g. resource injection 24
  • 25. EJB with JAX-RS @Path("stateless-bean") @Stateless public class StatelessResource { … } @Path("singleton-bean") @Singleton public class SingletonResource { … } 25
  • 26. CDI and JAX-RS • General CDI requirement: beans.xml needs to be declared to enable CDI managed beans – e.g. empty WEB-INF/beans.xml in war • Root resource classes need to be annotated with a CDI scope @Path("request-scoped") @RequestScoped public class RequestScopedResource { … } @Path("application-scoped") @ApplicationScoped public class ApplicationScopedResource { … } 26
  • 27. Servlet 3.0 and JAX-RS • No WEB-INF/web.xml for simple deployments • Use extension of javax.ws.rs.Application and @javax.ws.rs.ApplicationPath @ApplicationPath("resources”) public class MyApp extends Application { ... } • Use WEB-INF/web.xml for portable deployments <web-app version="3.0"> <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>...MyApp</servlet-class> 27
  • 28. Agenda • REST and JAX-RS <Insert Picture Here> • Deployment Options • Demo – Matching URLs, – Consuming POST Requests (@POST, @FormParam) – GlassFish Admin Backend: A REST Application • Status • Q&A 28
  • 29. Agenda • REST and JAX-RS <Insert Picture Here> • Deployment Options • Demo • Status • Q&A 29
  • 30. Status • JAX-RS 1.0: 18th October 2008 • JAX-RS 1.1: 23rd November 2009 – Aligned with Java EE 6, but not in the Web profile! • JAX-RS 2.0: Future<?> – Draft JSR 12th November 2010 – Like to submit to JCP in December or early next year – http://bit.ly/bkXtay • Implementations – Apache CXF, Apache Wink, eXo, Jersey, RESTEasy, Restlet, Triaxrs 30
  • 31. Agenda • REST and JAX-RS <Insert Picture Here> • Deployment Options • Demo • Status • Q&A 31