SlideShare a Scribd company logo
1 of 14
Download to read offline
JAX-RS - REST web
services in the JEE
ecosystem
Catalin Mihalache
Java Architect / Project Manager at Pentalog
Oracle Certified Master, Java EE 5 Enterprise Architect
the examples: https://www.dropbox.com/s/z1cj30b9y7pznao/samples.zip
Agenda
• What is JAX-RS ?
• The use case
• JAX-RS resources
• Providers
• Handling exceptions
• Customizing the response
• More JAX-RS annotations!
• Q&A
What is JAX-RS ?
RESTful web services in JEE
• JSR 311 – a JEE6 specification
Available in JEE6 Application Servers: like JBoss6.x, JBoss7.x, Glassfish 3.x, IBM
WebSphere 8.x, Apache TomEE Plus

• JSR 339 – a JEE7 specification
Available in JEE7 Application Servers: Glassfish 4.x (waiting for JBoss8 & WebSphere9 ..)

• Open source implementations
JBoss RestEasy
Glassfish Jersey – the Reference Implementation
Apache CXF
Apache Wink

• Spring MVC
(the dark side of the Force ..)
Used samples
https://www.dropbox.com/s/z1cj30b9y7pznao/samples.zip
The use case - caveatEmptor

• TODO: an HTTP-based API able to manage the domain model and to be easily consumed
by JavaScript-based applications (yeah, hire a professional JS developer and let me do my job:
JAVA!!)
JAX-RS resources (1)
• The URLs:
–

http://www.caveatemptor.com/rest/retrieveAllCategories.do
http://www.caveatemptor.com/rest/retrieveCategory.do?id=13
http://www.caveatemptor.com/rest/retrieveItems.do?categId=13

–

unique & pretty URLs for each object / collection from the domain model:
http://www.caveatemptor.com/rest/categories
http://www.caveatemptor.com/rest/categories/13
http://www.caveatemptor.com/rest/categories/13/items

• The HTTP methods: • HTTP error codes -

GET, POST, PUT, DELETE

http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

–

2xx Success

–

3xx Redirection

–

4xx Client Error (401 Unauthorized, 404 Not found, 400 Bad request)

–

5xx Server Error (well ..)

• XML &&|| JSON
JAX-RS resources (2)
Case study – the simpleJaxRs project
• @Path, @PathParam, @ApplicationPath and
javax.ws.rs.core.Application
http://localhost:8080/simpleJaxRs/rs/categories
http://localhost:8080/simpleJaxRs/rs/categories/1
/simpleJaxRs
/rs
/categories
/categories/1

–
–
–
–

servlet context name
JAX-RS front-controller
instance of CategoriesResource
instance of CategoryResource with id = 1

(no XML configuration, just tons of Java annotations ..)

• XML & JSON; JAXB
–
–

●

(Java annotations everywhere ..)
Accept → @Produces
Content-Type → @Consumes

CRUD operations on same URL
@POST, @GET, @PUT, @DETELE
Providers
Case study – simpleJaxRs2 project
producing / consuming JSON without JAXB
• JEE6: No standard JSON – JAX-RS integration!
available in JEE7

• Converting Java objects into “something” (like JSON) &
vice-versa:
javax.ws.rs.ext.MessageBodyWriter
javax.ws.rs.ext.MessageBodyReader

• Jackson - JAX-RS integration – producing / consuming JSON
@Provider
@Consumes({MediaType.APPLICATION_JSON, "text/json"})
@Produces({MediaType.APPLICATION_JSON, "text/json"})
public class JacksonJsonProvider implements MessageBodyReader<Object>,
MessageBodyWriter<Object> { ... }

• @Provider - “provides” automatic registration & usage
Handling exceptions
Case study – caveatEmptor-rs project
• Managing Checked Exceptions (business exception)
javax.ws.rs.WebApplicationException
HTTP error code: 4xx

• Managing Unchecked Exceptions
javax.ws.rs.ext.ExceptionMapper
HTTP error code: 5xx (internal server error)
@Provider
public class RuntimeExceptionMapper
implements ExceptionMapper<RuntimeException>
{ ... }
Customizing the response
Case study – caveatEmptor-rs project
javax.ws.rs.core.Response

• Redirects
• Controlling the cache headers
•
More JAX-RS annotations!
• @javax.ws.rs.core.Context
–

javax.ws.rs.core.UriInfo
●

–

javax.ws.rs.core.HttpHeaders
●

–

An injectable interface that provides access to application and request URI
information.

An injectable interface that provides access to HTTP header information.

javax.ws.rs.core.SecurityContext
●

An injectable interface that provides access to security related information.

• @QueryParam
–

injects a query string parameters, just as @PathParam does

• @FormParam
–

injects a HTML form input's value, just as @PathParam does
A

Q&A
Please fill in your evaluation form
[JAX-RS - REST web services in the JEE ecosystem]
Catalin Mihalache

[12th of October 2013

More Related Content

What's hot

Flyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaFlyway: The agile database migration framework for Java
Flyway: The agile database migration framework for Java
Axel Fontaine
 
Utilized JAXB to generate POJOs automatically
Utilized JAXB to generate POJOs automaticallyUtilized JAXB to generate POJOs automatically
Utilized JAXB to generate POJOs automatically
Guo Albert
 

What's hot (20)

Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
 
Flywaydb
FlywaydbFlywaydb
Flywaydb
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesHibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance Techniques
 
File System On Steroids
File System On SteroidsFile System On Steroids
File System On Steroids
 
Liquibase
LiquibaseLiquibase
Liquibase
 
Advance java session 15
Advance java session 15Advance java session 15
Advance java session 15
 
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
 
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
 
Flyway: The agile database migration framework for Java
Flyway: The agile database migration framework for JavaFlyway: The agile database migration framework for Java
Flyway: The agile database migration framework for Java
 
Liquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOpsLiquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOps
 
Liquibase få kontroll på dina databasförändringar
Liquibase   få kontroll på dina databasförändringarLiquibase   få kontroll på dina databasförändringar
Liquibase få kontroll på dina databasförändringar
 
Advance java session 20
Advance java session 20Advance java session 20
Advance java session 20
 
Silicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your databaseSilicon Valley JUG - How to generate customized java 8 code from your database
Silicon Valley JUG - How to generate customized java 8 code from your database
 
XML parsing using jaxb
XML parsing using jaxbXML parsing using jaxb
XML parsing using jaxb
 
Utilized JAXB to generate POJOs automatically
Utilized JAXB to generate POJOs automaticallyUtilized JAXB to generate POJOs automatically
Utilized JAXB to generate POJOs automatically
 
Database Change Management as a Service
Database Change Management as a ServiceDatabase Change Management as a Service
Database Change Management as a Service
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
JSR-222 Java Architecture for XML Binding
JSR-222 Java Architecture for XML BindingJSR-222 Java Architecture for XML Binding
JSR-222 Java Architecture for XML Binding
 
No Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with BootiqueNo Container: a Modern Java Stack with Bootique
No Container: a Modern Java Stack with Bootique
 

Viewers also liked

Intro CodeCamp/IASI 16 oct 2010
Intro CodeCamp/IASI 16 oct 2010Intro CodeCamp/IASI 16 oct 2010
Intro CodeCamp/IASI 16 oct 2010
Codecamp Romania
 
Iasi code camp 12 october 2013 play oriented development - leon daniel
Iasi code camp 12 october 2013   play oriented development - leon danielIasi code camp 12 october 2013   play oriented development - leon daniel
Iasi code camp 12 october 2013 play oriented development - leon daniel
Codecamp Romania
 
Code camp iasi silviu niculita - machine learning for mere mortals with azu...
Code camp iasi   silviu niculita - machine learning for mere mortals with azu...Code camp iasi   silviu niculita - machine learning for mere mortals with azu...
Code camp iasi silviu niculita - machine learning for mere mortals with azu...
Codecamp Romania
 
Iasi code camp 12 october 2013 an invitation to agile product management - ...
Iasi code camp 12 october 2013   an invitation to agile product management - ...Iasi code camp 12 october 2013   an invitation to agile product management - ...
Iasi code camp 12 october 2013 an invitation to agile product management - ...
Codecamp Romania
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in android
Codecamp Romania
 
Managing technical debt - Dan Nicola - Florin Cardasim
Managing technical debt - Dan Nicola - Florin CardasimManaging technical debt - Dan Nicola - Florin Cardasim
Managing technical debt - Dan Nicola - Florin Cardasim
Codecamp Romania
 
Angajatori de Top Iasi - Nov 2013
Angajatori de Top Iasi - Nov 2013Angajatori de Top Iasi - Nov 2013
Angajatori de Top Iasi - Nov 2013
Codecamp Romania
 
Iasi code camp 12 october 2013 typescript vs coffeescript - vlad iliescu
Iasi code camp 12 october 2013   typescript vs coffeescript - vlad iliescuIasi code camp 12 october 2013   typescript vs coffeescript - vlad iliescu
Iasi code camp 12 october 2013 typescript vs coffeescript - vlad iliescu
Codecamp Romania
 

Viewers also liked (18)

The bigrewrite
The bigrewriteThe bigrewrite
The bigrewrite
 
Eugen Constantinescu - Genivi - Codecamp 10 may 2014
Eugen Constantinescu - Genivi - Codecamp 10 may 2014Eugen Constantinescu - Genivi - Codecamp 10 may 2014
Eugen Constantinescu - Genivi - Codecamp 10 may 2014
 
The bigrewrite
The bigrewriteThe bigrewrite
The bigrewrite
 
Intro CodeCamp/IASI 16 oct 2010
Intro CodeCamp/IASI 16 oct 2010Intro CodeCamp/IASI 16 oct 2010
Intro CodeCamp/IASI 16 oct 2010
 
Iulian dogariu the sad story of the server etc
Iulian dogariu   the sad story of the server etcIulian dogariu   the sad story of the server etc
Iulian dogariu the sad story of the server etc
 
Iasi code camp 12 october 2013 play oriented development - leon daniel
Iasi code camp 12 october 2013   play oriented development - leon danielIasi code camp 12 october 2013   play oriented development - leon daniel
Iasi code camp 12 october 2013 play oriented development - leon daniel
 
Ana milutinovic quality awareness when practicing agile testing
Ana milutinovic   quality awareness when practicing agile testingAna milutinovic   quality awareness when practicing agile testing
Ana milutinovic quality awareness when practicing agile testing
 
Code camp iasi silviu niculita - machine learning for mere mortals with azu...
Code camp iasi   silviu niculita - machine learning for mere mortals with azu...Code camp iasi   silviu niculita - machine learning for mere mortals with azu...
Code camp iasi silviu niculita - machine learning for mere mortals with azu...
 
Cristi Ursachi - Xamarin - CodeCamp 10 may 2014
Cristi Ursachi  - Xamarin - CodeCamp 10 may 2014Cristi Ursachi  - Xamarin - CodeCamp 10 may 2014
Cristi Ursachi - Xamarin - CodeCamp 10 may 2014
 
Iasi code camp 12 october 2013 an invitation to agile product management - ...
Iasi code camp 12 october 2013   an invitation to agile product management - ...Iasi code camp 12 october 2013   an invitation to agile product management - ...
Iasi code camp 12 october 2013 an invitation to agile product management - ...
 
Ccp
CcpCcp
Ccp
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in android
 
Managing technical debt - Dan Nicola - Florin Cardasim
Managing technical debt - Dan Nicola - Florin CardasimManaging technical debt - Dan Nicola - Florin Cardasim
Managing technical debt - Dan Nicola - Florin Cardasim
 
Codecamp Iasi 7 mai 2011 Exception tail.com
Codecamp Iasi 7 mai 2011 Exception tail.comCodecamp Iasi 7 mai 2011 Exception tail.com
Codecamp Iasi 7 mai 2011 Exception tail.com
 
Angajatori de Top Iasi - Nov 2013
Angajatori de Top Iasi - Nov 2013Angajatori de Top Iasi - Nov 2013
Angajatori de Top Iasi - Nov 2013
 
Mihai mahulea the zen of test driven development
Mihai mahulea   the zen of test driven developmentMihai mahulea   the zen of test driven development
Mihai mahulea the zen of test driven development
 
Vlad Zelinschi - Embrace Native JavaScript (the anti-plugins talk) - Codecamp...
Vlad Zelinschi - Embrace Native JavaScript (the anti-plugins talk) - Codecamp...Vlad Zelinschi - Embrace Native JavaScript (the anti-plugins talk) - Codecamp...
Vlad Zelinschi - Embrace Native JavaScript (the anti-plugins talk) - Codecamp...
 
Iasi code camp 12 october 2013 typescript vs coffeescript - vlad iliescu
Iasi code camp 12 october 2013   typescript vs coffeescript - vlad iliescuIasi code camp 12 october 2013   typescript vs coffeescript - vlad iliescu
Iasi code camp 12 october 2013 typescript vs coffeescript - vlad iliescu
 

Similar to Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache

Andrei Niculae - JavaEE6 - 24mai2011
Andrei Niculae - JavaEE6 - 24mai2011Andrei Niculae - JavaEE6 - 24mai2011
Andrei Niculae - JavaEE6 - 24mai2011
Agora Group
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
Mert Çalışkan
 

Similar to Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache (20)

Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3 Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...
 
Deep Dive Hands-on in Java EE 6 - Oredev 2010
Deep Dive Hands-on in Java EE 6 - Oredev 2010Deep Dive Hands-on in Java EE 6 - Oredev 2010
Deep Dive Hands-on in Java EE 6 - Oredev 2010
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More Power
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
 
Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011
 
JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul services
 
Andrei Niculae - JavaEE6 - 24mai2011
Andrei Niculae - JavaEE6 - 24mai2011Andrei Niculae - JavaEE6 - 24mai2011
Andrei Niculae - JavaEE6 - 24mai2011
 
Prototype-1
Prototype-1Prototype-1
Prototype-1
 
Prototype-1
Prototype-1Prototype-1
Prototype-1
 
OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6
 
Java EE 8 Update
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
 
Java EE 6 & GlassFish v3 @ DevNexus
Java EE 6 & GlassFish v3 @ DevNexusJava EE 6 & GlassFish v3 @ DevNexus
Java EE 6 & GlassFish v3 @ DevNexus
 
Java EE8 - by Kito Mann
Java EE8 - by Kito Mann Java EE8 - by Kito Mann
Java EE8 - by Kito Mann
 
GlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and FutureGlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and Future
 
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
 

More from Codecamp Romania

More from Codecamp Romania (20)

Cezar chitac the edge of experience
Cezar chitac   the edge of experienceCezar chitac   the edge of experience
Cezar chitac the edge of experience
 
Cloud powered search
Cloud powered searchCloud powered search
Cloud powered search
 
Business analysis techniques exercise your 6-pack
Business analysis techniques   exercise your 6-packBusiness analysis techniques   exercise your 6-pack
Business analysis techniques exercise your 6-pack
 
Bpm company code camp - configuration or coding with pega
Bpm company   code camp - configuration or coding with pegaBpm company   code camp - configuration or coding with pega
Bpm company code camp - configuration or coding with pega
 
Andrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseAndrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabase
 
Agility and life
Agility and lifeAgility and life
Agility and life
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10
 
The case for continuous delivery
The case for continuous deliveryThe case for continuous delivery
The case for continuous delivery
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2d
 
Sizing epics tales from an agile kingdom
Sizing epics   tales from an agile kingdomSizing epics   tales from an agile kingdom
Sizing epics tales from an agile kingdom
 
Scale net apps in aws
Scale net apps in awsScale net apps in aws
Scale net apps in aws
 
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
 
Parallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowParallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflow
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in android
 
Kickstart your own freelancing career
Kickstart your own freelancing careerKickstart your own freelancing career
Kickstart your own freelancing career
 
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu   the soft stuff is the hard stuff. the agile soft skills toolkitIonut grecu   the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
 
Ecma6 in the wild
Ecma6 in the wildEcma6 in the wild
Ecma6 in the wild
 
Diana antohi me against myself or how to fail and move forward
Diana antohi   me against myself  or how to fail  and move forwardDiana antohi   me against myself  or how to fail  and move forward
Diana antohi me against myself or how to fail and move forward
 
Codecamp2015 pimp yourpipeline-saade-jens-1.1
Codecamp2015 pimp yourpipeline-saade-jens-1.1Codecamp2015 pimp yourpipeline-saade-jens-1.1
Codecamp2015 pimp yourpipeline-saade-jens-1.1
 
Code camp iasi silviu niculita - machine learning for mere mortals with azu...
Code camp iasi   silviu niculita - machine learning for mere mortals with azu...Code camp iasi   silviu niculita - machine learning for mere mortals with azu...
Code camp iasi silviu niculita - machine learning for mere mortals with azu...
 

Recently uploaded

Recently uploaded (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Iasi code camp 12 october 2013 jax-rs-jee-ecosystem - catalin mihalache

  • 1.
  • 2. JAX-RS - REST web services in the JEE ecosystem Catalin Mihalache Java Architect / Project Manager at Pentalog Oracle Certified Master, Java EE 5 Enterprise Architect the examples: https://www.dropbox.com/s/z1cj30b9y7pznao/samples.zip
  • 3. Agenda • What is JAX-RS ? • The use case • JAX-RS resources • Providers • Handling exceptions • Customizing the response • More JAX-RS annotations! • Q&A
  • 4. What is JAX-RS ? RESTful web services in JEE • JSR 311 – a JEE6 specification Available in JEE6 Application Servers: like JBoss6.x, JBoss7.x, Glassfish 3.x, IBM WebSphere 8.x, Apache TomEE Plus • JSR 339 – a JEE7 specification Available in JEE7 Application Servers: Glassfish 4.x (waiting for JBoss8 & WebSphere9 ..) • Open source implementations JBoss RestEasy Glassfish Jersey – the Reference Implementation Apache CXF Apache Wink • Spring MVC (the dark side of the Force ..)
  • 6. The use case - caveatEmptor • TODO: an HTTP-based API able to manage the domain model and to be easily consumed by JavaScript-based applications (yeah, hire a professional JS developer and let me do my job: JAVA!!)
  • 7. JAX-RS resources (1) • The URLs: – http://www.caveatemptor.com/rest/retrieveAllCategories.do http://www.caveatemptor.com/rest/retrieveCategory.do?id=13 http://www.caveatemptor.com/rest/retrieveItems.do?categId=13 – unique & pretty URLs for each object / collection from the domain model: http://www.caveatemptor.com/rest/categories http://www.caveatemptor.com/rest/categories/13 http://www.caveatemptor.com/rest/categories/13/items • The HTTP methods: • HTTP error codes - GET, POST, PUT, DELETE http://en.wikipedia.org/wiki/List_of_HTTP_status_codes – 2xx Success – 3xx Redirection – 4xx Client Error (401 Unauthorized, 404 Not found, 400 Bad request) – 5xx Server Error (well ..) • XML &&|| JSON
  • 8. JAX-RS resources (2) Case study – the simpleJaxRs project • @Path, @PathParam, @ApplicationPath and javax.ws.rs.core.Application http://localhost:8080/simpleJaxRs/rs/categories http://localhost:8080/simpleJaxRs/rs/categories/1 /simpleJaxRs /rs /categories /categories/1 – – – – servlet context name JAX-RS front-controller instance of CategoriesResource instance of CategoryResource with id = 1 (no XML configuration, just tons of Java annotations ..) • XML & JSON; JAXB – – ● (Java annotations everywhere ..) Accept → @Produces Content-Type → @Consumes CRUD operations on same URL @POST, @GET, @PUT, @DETELE
  • 9. Providers Case study – simpleJaxRs2 project producing / consuming JSON without JAXB • JEE6: No standard JSON – JAX-RS integration! available in JEE7 • Converting Java objects into “something” (like JSON) & vice-versa: javax.ws.rs.ext.MessageBodyWriter javax.ws.rs.ext.MessageBodyReader • Jackson - JAX-RS integration – producing / consuming JSON @Provider @Consumes({MediaType.APPLICATION_JSON, "text/json"}) @Produces({MediaType.APPLICATION_JSON, "text/json"}) public class JacksonJsonProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> { ... } • @Provider - “provides” automatic registration & usage
  • 10. Handling exceptions Case study – caveatEmptor-rs project • Managing Checked Exceptions (business exception) javax.ws.rs.WebApplicationException HTTP error code: 4xx • Managing Unchecked Exceptions javax.ws.rs.ext.ExceptionMapper HTTP error code: 5xx (internal server error) @Provider public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> { ... }
  • 11. Customizing the response Case study – caveatEmptor-rs project javax.ws.rs.core.Response • Redirects • Controlling the cache headers •
  • 12. More JAX-RS annotations! • @javax.ws.rs.core.Context – javax.ws.rs.core.UriInfo ● – javax.ws.rs.core.HttpHeaders ● – An injectable interface that provides access to application and request URI information. An injectable interface that provides access to HTTP header information. javax.ws.rs.core.SecurityContext ● An injectable interface that provides access to security related information. • @QueryParam – injects a query string parameters, just as @PathParam does • @FormParam – injects a HTML form input's value, just as @PathParam does
  • 13. A Q&A
  • 14. Please fill in your evaluation form [JAX-RS - REST web services in the JEE ecosystem] Catalin Mihalache [12th of October 2013