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

Post on 11-May-2015

1.233 views 4 download

Tags:

description

Paul Sandoz The presentation focuses on three parts REST, JAX-RS and how JAX-RS integrates with Java EE 6. The REST style will be briefly introduced explaining what it is and what are the advantages. Then JAX-RS, the Java API for RESTful Web services, will be discussed. Where appropriate live coding demonstrations will be used to aid the explanations of JAX-RS features. Finally how JAX-RS integrates with Java EE 6 technologies such as Enterprise Java Beans (EJB) 3.1. Live coding demonstrations will be used.

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

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 studyFabrizio Giudci

- X1 -Le développement durable

Dominic Williams

11:00

12:00

- A2 -Integration of User Centered Design

in Agile Development of RIAJ. Borkenhagen, J. Desmazières

- I2 -Développement d'une application

iPhone pilotée par les testsEmmanuel Etasse, Van-Charles Tran

- J2 -La Tequila du développement Web

Nicolas Martignole

- X2 -Cloud Computing: anatomie et

pratiqueMarc-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 iceScrumClaude 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 jBehaveXavier Bourguignon

- X5 -NoSQL : Enfin de la biodiversité

dans l'écosystème des BDOlivier 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.comhttp://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 /fooAccept:application/properties+json

Resource representationsStatic 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 CreatedDate: Wed, 03 Jun 2009 16:41:58 GMTServer: Apache/1.3.6Location: http://example.com/properties/fooContent-Type: application/order+xmlContent-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 on23rd 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/