Paul Sandoz
2010
J4
JAX-RS and Java EE 6
Agilité iPhone Java Incubateur
8:15 Accueil des participantsAccueil des participantsAccueil des participantsAccueil des participants
8:40 Mot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateurs
9:00 Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes)
9:40
10:40
- A1 -
Le terrain Agile
Jean-Philippe Vigniel
- I1-
Hello iPhone
Stephane Tavera
- J1 -
NOSQL also means RDF stores: an
Android case study
Fabrizio Giudci
- X1 -
Le développement durable
Dominic Williams
11:00
12:00
- A2 -
Integration of User Centered Design
in Agile Development of RIA
J. Borkenhagen, J. Desmazières
- I2 -
Développement d'une application
iPhone pilotée par les tests
Emmanuel Etasse, Van-Charles Tran
- J2 -
La Tequila du développement Web
Nicolas Martignole
- X2 -
Cloud Computing: anatomie et
pratique
Marc-Elian Bégin
12:20
13:20
- A3 -
Adoption de l'Agilité par les usages
Xavier Warzee
- I3 -
Distribution d'applications iPhone
en Entreprise: Réalisation d'un
AppStore interne
Géraud de Laval
- J3 -
Vaadin - Rich Web Applications in
Server-side Java without Plug-ins or
JavaScript
Joonas Lehtinen
- X3 -
Les DVCS sont vos amis
Sébastien Douche
Pause repas (50 minutes)Pause repas (50 minutes)Pause repas (50 minutes)Pause repas (50 minutes)
14h10 Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes)
14h50
15h50
- A4 -
Scrum, introduction et mise en
oeuvre avec iceScrum
Claude Aubry
- I4 -
Agile iOS Development
Jérôme Layat, Alexander Osterwalder
- J4 -
JAX-RS and Java EE 6
Paul Sandoz
- X4 -
IT Design & Ergonomy
Pascal Petit, Aude Lussigny
16h10
17h10
- A5 -
Agilité : 10 ans déjà
Thierry Cros
- I5 -
Optimizing iOS applications
Marc-Antoine Scheurer
- J5 -
Ecrivez et automatisez vos tests
fonctionnels avec jBehave
Xavier Bourguignon
- X5 -
NoSQL : Enfin de la biodiversité
dans l'écosystème des BD
Olivier Mallassi
17h30
18h30
- A6 -
Lean engineering
Jean-Christophe Dubail
- I6 -
iPhone et Agile, l'amour vache
Guillaume Duquesnay
- J6 -
Let's make this test suite run faster
David Gageot
- X6 -
The feel of Scala
Mario Fusco
Mot de la fin & tombolaMot de la fin & tombolaMot de la fin & tombolaMot de la fin & tombola
Programme de la Conférence
www.soft-shake.ch
JAX-RS,
The Java API for
RESTful Web services,
and Java EE 6
paul.sandoz@oracle.com
http://blogs.sun.com/sandoz/
https://twitter.com/PaulSandoz/
Agenda
● REST and JAX-RS primer
● Deployment options
● Demonstration
● Status
● Q & A
Very short REST primer: buy this
book
...and these!
REST is an Architectural Style
Set of constraints
you apply to the architecture
of a distributed system
to induce desirable properties
RESTful Web services
Application of
REST architectural style to
services that utilize Web standards
(URIs, HTTP, HTML, XML, Atom, RDF
etc.)
Java API for RESTful Web Services
(JAX-RS)
Standard annotation-driven API
helping 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
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
Resources are identified by URIs
● Resource == Java class
● POJO
● No required interface
● ID provided by @Path annotation
● Value is relative URI path, base URI is provided by
deployment context or “super” resource
● Embedded parameters for non-fixed parts of the
URI path
● Annotate class or “sub-resource-locator” method
Resources are identified by URIs
@Path("properties")
public class SystemProperties {
@GET
List<SystemProperty> getProperties(...) {...}
@Path("{name}")
SystemProperty getProperty(...) {...}
}
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
Standard set of methods
● Annotate resource class methods with standard
method
● @GET, @PUT, @POST, @DELETE, @HEAD, @OPTIONS
● @HttpMethod meta-annotation allows extensions,
e.g. WebDAV or @PATCH
● 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) {...}
}
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
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
Resource representations
@GET
@Produces("application/properties+xml")
Property getXml(@PathParam("name") String name) {
...
}
@GET
@Produces("text/plain")
String getText(@PathParam("name") String name) {
...
}
Response contains 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>
Response contains 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
Response contains 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);
Agenda
● REST and JAX-RS primer
● Deployment options
● Demonstration
● Status
● Q & A
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
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);
Servlet deployment
● JAX-RS application packaged in WAR like a
servlet
● For JAX-RS aware containers (e.g. supporting
Servlet 3.0)
● Application subclass referenced to in web.xml
as servlet name
● Application subclass annotated with
@ApplicationPath, no web.xml required
Servlet deployment
● 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
● @Context HttpServletRequest hsr;
Java EE 6 deployment
● Annotate with @Path, or @Provider
● EJB 3.1 session or singleton bean
● A (managed) bean annotated with @ManagedBean
● A CDI (managed) bean annotated with scope, such
as @RequestScoped or @ApplicationScoped
– CDI is enabled with an empty WEB-INF/beans.xml file
● Full access to facilities of native component
model
● Resource injection: @EJB, @Resource
● Support for @Inject
Implementations
● Apache CXF
● Apache Wink
● JBoss RESTEasy
● Jersey
● Restlet
● Triaxrs
Agenda
● REST and JAX-RS primer
● Deployment options
● Demonstration
● Status
● Q & A
Agenda
● REST and JAX-RS primer
● Deployment options
● Demonstration
● Status
● Q & A
Status
● JAX-RS 1.1 maintenance released on
23rd
November 2009
● Jersey integrated into GlassFish 3.0, 3.0.1 and
3.1
● Possibly in-scope for any JAX-RS 2.0 effort
● Client API
● Hyperlinking
● Module view controller
● Parameter validation
● Better integration with @Inject
More information
● JSR
● http://jcp.org/en/jsr/detail?id=311
● http://jsr311.dev.java.net/
● mailto:users@jsr311.dev.java.net
● Jersey, the Reference Implementation
● http://jersey.dev.java.net/
● mailto:users@jersey.dev.java.net
● Blogs
● http://blogs.sun.com/sandoz/
● http://blogs.sun.com/japod/
● http://weblogs.java.net/blog/mhadley/
Q&Apaul.sandoz@oracle.com
http://blogs.sun.com/sandoz/
https://twitter.com/PaulSandoz/

soft-shake.ch - JAX-RS and Java EE 6

  • 1.
  • 2.
    Agilité iPhone JavaIncubateur 8:15 Accueil des participantsAccueil des participantsAccueil des participantsAccueil des participants 8:40 Mot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateursMot des organisateurs & Criée des orateurs 9:00 Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes)Keynote de Nicolas Martignole (30 minutes) 9:40 10:40 - A1 - Le terrain Agile Jean-Philippe Vigniel - I1- Hello iPhone Stephane Tavera - J1 - NOSQL also means RDF stores: an Android case study Fabrizio Giudci - X1 - Le développement durable Dominic Williams 11:00 12:00 - A2 - Integration of User Centered Design in Agile Development of RIA J. Borkenhagen, J. Desmazières - I2 - Développement d'une application iPhone pilotée par les tests Emmanuel Etasse, Van-Charles Tran - J2 - La Tequila du développement Web Nicolas Martignole - X2 - Cloud Computing: anatomie et pratique Marc-Elian Bégin 12:20 13:20 - A3 - Adoption de l'Agilité par les usages Xavier Warzee - I3 - Distribution d'applications iPhone en Entreprise: Réalisation d'un AppStore interne Géraud de Laval - J3 - Vaadin - Rich Web Applications in Server-side Java without Plug-ins or JavaScript Joonas Lehtinen - X3 - Les DVCS sont vos amis Sébastien Douche Pause repas (50 minutes)Pause repas (50 minutes)Pause repas (50 minutes)Pause repas (50 minutes) 14h10 Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes)Keynote de Regis Medina (30 minutes) 14h50 15h50 - A4 - Scrum, introduction et mise en oeuvre avec iceScrum Claude Aubry - I4 - Agile iOS Development Jérôme Layat, Alexander Osterwalder - J4 - JAX-RS and Java EE 6 Paul Sandoz - X4 - IT Design & Ergonomy Pascal Petit, Aude Lussigny 16h10 17h10 - A5 - Agilité : 10 ans déjà Thierry Cros - I5 - Optimizing iOS applications Marc-Antoine Scheurer - J5 - Ecrivez et automatisez vos tests fonctionnels avec jBehave Xavier Bourguignon - X5 - NoSQL : Enfin de la biodiversité dans l'écosystème des BD Olivier Mallassi 17h30 18h30 - A6 - Lean engineering Jean-Christophe Dubail - I6 - iPhone et Agile, l'amour vache Guillaume Duquesnay - J6 - Let's make this test suite run faster David Gageot - X6 - The feel of Scala Mario Fusco Mot de la fin & tombolaMot de la fin & tombolaMot de la fin & tombolaMot de la fin & tombola Programme de la Conférence www.soft-shake.ch
  • 3.
    JAX-RS, The Java APIfor RESTful Web services, and Java EE 6 paul.sandoz@oracle.com http://blogs.sun.com/sandoz/ https://twitter.com/PaulSandoz/
  • 4.
    Agenda ● REST andJAX-RS primer ● Deployment options ● Demonstration ● Status ● Q & A
  • 5.
    Very short RESTprimer: buy this book
  • 6.
  • 7.
    REST is anArchitectural Style Set of constraints you apply to the architecture of a distributed system to induce desirable properties
  • 8.
    RESTful Web services Applicationof REST architectural style to services that utilize Web standards (URIs, HTTP, HTML, XML, Atom, RDF etc.)
  • 9.
    Java API forRESTful Web Services (JAX-RS) Standard annotation-driven API helping developers build RESTful Web services in Java
  • 10.
    RESTful application cycle Resourcesare 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
  • 11.
    Resources are identifiedby URIs http://example.com/widgets/foo http://example.com/customers/bar http://example.com/customers/bar/orders/2 http://example.com/orders/101230/customer
  • 12.
    Resources are identifiedby URIs ● Resource == Java class ● POJO ● No required interface ● ID provided by @Path annotation ● Value is relative URI path, base URI is provided by deployment context or “super” resource ● Embedded parameters for non-fixed parts of the URI path ● Annotate class or “sub-resource-locator” method
  • 13.
    Resources are identifiedby URIs @Path("properties") public class SystemProperties { @GET List<SystemProperty> getProperties(...) {...} @Path("{name}") SystemProperty getProperty(...) {...} }
  • 14.
    Standard set ofmethods Method Purpose GET Read, possibly cached POST Update or create without a known ID PUT Update or create with a known ID DELETE Remove
  • 15.
    Standard set ofmethods ● Annotate resource class methods with standard method ● @GET, @PUT, @POST, @DELETE, @HEAD, @OPTIONS ● @HttpMethod meta-annotation allows extensions, e.g. WebDAV or @PATCH ● 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
  • 16.
    Standard set ofmethods @Path("properties/{name}") public class SystemProperty { @GET Property get(@PathParam("name") String name) {...} @PUT Property set(@PathParam("name") String name, String value) {...} }
  • 17.
    Resource representations ● Representationformat 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
  • 18.
    Resource representations Static anddynamic 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
  • 19.
    Resource representations @GET @Produces("application/properties+xml") Property getXml(@PathParam("name")String name) { ... } @GET @Produces("text/plain") String getText(@PathParam("name") String name) { ... }
  • 20.
    Response contains links HTTP/1.1201 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>
  • 21.
    Response contains 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
  • 22.
    Response contains links @ContextUriInfo 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);
  • 23.
    Agenda ● REST andJAX-RS primer ● Deployment options ● Demonstration ● Status ● Q & A
  • 24.
    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
  • 25.
    Java SE deployment Applicationapp = ... RuntimeDelegate rd = RuntimeDelegate.getInstance(); Adapter a = rd.createEndpoint(app, Adapter.class); SelectorThread st = GrizzlyServerFactory.create( "http://127.0.0.1:8084/", a);
  • 26.
    Servlet deployment ● JAX-RSapplication packaged in WAR like a servlet ● For JAX-RS aware containers (e.g. supporting Servlet 3.0) ● Application subclass referenced to in web.xml as servlet name ● Application subclass annotated with @ApplicationPath, no web.xml required
  • 27.
    Servlet deployment ● Fornon-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 ● @Context HttpServletRequest hsr;
  • 28.
    Java EE 6deployment ● Annotate with @Path, or @Provider ● EJB 3.1 session or singleton bean ● A (managed) bean annotated with @ManagedBean ● A CDI (managed) bean annotated with scope, such as @RequestScoped or @ApplicationScoped – CDI is enabled with an empty WEB-INF/beans.xml file ● Full access to facilities of native component model ● Resource injection: @EJB, @Resource ● Support for @Inject
  • 29.
    Implementations ● Apache CXF ●Apache Wink ● JBoss RESTEasy ● Jersey ● Restlet ● Triaxrs
  • 30.
    Agenda ● REST andJAX-RS primer ● Deployment options ● Demonstration ● Status ● Q & A
  • 31.
    Agenda ● REST andJAX-RS primer ● Deployment options ● Demonstration ● Status ● Q & A
  • 32.
    Status ● JAX-RS 1.1maintenance released on 23rd November 2009 ● Jersey integrated into GlassFish 3.0, 3.0.1 and 3.1 ● Possibly in-scope for any JAX-RS 2.0 effort ● Client API ● Hyperlinking ● Module view controller ● Parameter validation ● Better integration with @Inject
  • 33.
    More information ● JSR ●http://jcp.org/en/jsr/detail?id=311 ● http://jsr311.dev.java.net/ ● mailto:users@jsr311.dev.java.net ● Jersey, the Reference Implementation ● http://jersey.dev.java.net/ ● mailto:users@jersey.dev.java.net ● Blogs ● http://blogs.sun.com/sandoz/ ● http://blogs.sun.com/japod/ ● http://weblogs.java.net/blog/mhadley/
  • 34.