SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
4/3/2013
1
Implementing RESTful Services
JAX-RS
CS213
03-Apr-2013
JAX-RS Features
• Annotation based
– No need for any configuration in web.xml
– New version of Servlet specification doesn’t
require a web.xml file at all.
• Flexible Deployment Option
– Servlet container
– JAX-RS aware container
• Easy Data Handling Mechanism
4/3/2013
2
Core Annotations
• URL Templates
– @Path
– Defines URI mappings and templates
– Applied on the resource class (most of other annotations are
for methods)
• MIME handling
– @Provides, @Consumes
– What MIME types does the resource produce and consume
• HTTP methods
– @GET, @POST, @PUT, @DELETE
– Identifies which HTTP method the Java method is interested in
Parameter
• @PathParam
– Allows you to extract URI
template segments
– /customers/1234
– /customers/{id}
• @QueryParam
– Access to specific
parameter URI query string
– /customers?city=Lahore
• @MatrixParam
– /customers;city=Lahore
• @FormParam
• @HeaderParam
– Access to a specific HTTP
Header
• @CoockieParam
– Access to a specific cookie
value
• @Context
– Access to contextual
information such as URI or
Request object
• @DefaultValue
4/3/2013
3
Parameter Handling
• HTTP request values are automatically
mapped to
– String and primitive types
– Class types that have a constructor that takes a
String parameter
– Class types that have a static valueOf(String val)
method to prepare an instance of that class
– List , Arrays or Set of above types when there are
multiple values
– Byte array or string for payload (POST or PUT)
Return Types
• Null (Status 204)
– Nothing is returned or a null value is retuned
• WebApplicationException
• An Entity/Object
– Marshaled/serialized to its string representation
• Response
• GenericEntity (embedded in response object)
4/3/2013
4
Poll Service Example
public class PollService {
String getPoll(int id) {
// return some JSON
}
// other methods
}
public class PollService {
String getPoll(int id) {
// return some JSON
}
// other methods
}
Example with JAX-RS Annotations
@Path("/polls")
public class PollService {
@Path("/{poll-id}")
@GET
@Provides("application/json")
String getPoll(@PathParam("poll-id") int id) {
...
}
}
@Path("/polls")
public class PollService {
@Path("/{poll-id}")
@GET
@Provides("application/json")
String getPoll(@PathParam("poll-id") int id) {
...
}
}
Define base URL of this resource
class. All request starting with this
context shall be routed to this class
This method will be
called for all GET type
requests of the form
/polls/12345
Automatically convert
and inject value of
URL segment into id
parameter.
Defines extension to
base URL and path
segment
4/3/2013
5
Example with POST
@Path("/polls")
public class PollService {
...
@POST
@Consumes("application/json")
Response createPoll(String data) {
...
}
}
@Path("/polls")
public class PollService {
...
@POST
@Consumes("application/json")
Response createPoll(String data) {
...
}
}
We will talk about it in
next slide.
Un-annotated parameters
assumed to be incoming
message body. There can
be only one!
What content types are
expected from client?
To be invoked on POST requests,
i.e. CREATE a resource, message
body will contain poll data.
Response Object
• Core Classes in JAX-RS
– Response and ResponseBuilder
• Objective
– Customize response code
– Specify certain response headers
– Specify redirect URLs
– Lot more..
Response createPoll(String data) {
...
ResponseBuilder rb = Response.status(201);
rb.type("application/json")
.header("Location", "/polls/"+id);
return rb.build();
}
Response createPoll(String data) {
...
ResponseBuilder rb = Response.status(201);
rb.type("application/json")
.header("Location", "/polls/"+id);
return rb.build();
}
4/3/2013
6
Default Response Codes
• GET and PUT
– 200 (OK)
• DELETE and POST
– 200 (OK) if content sent back with response
– 204 (NO CONTENT) if no content sent back or a
null is returned.
Example with Query Parameters
• Process requests of the form
– /polls?sort=title
@Path("/polls")
public class PollService {
...
@GET
@Produces({"application/json","application/xml"})
Response listPoll(
@DefaultValue("cdate") @QueryParam("sort") String order) {
...
}
}
@Path("/polls")
public class PollService {
...
@GET
@Produces({"application/json","application/xml"})
Response listPoll(
@DefaultValue("cdate") @QueryParam("sort") String order) {
...
}
}
4/3/2013
7
Frameworks
• JBoss RESTeasy
• Sun Jersey
• CXF
• Axis2
• Spring
That’s All
• JAX-RS Documentation
– http://jersey.java.net/nonav/documentation/snap
shot/index.html
• Java6 Tutorial
– http://docs.oracle.com/javaee/6/tutorial/doc/gijq
y.html

Contenu connexe

En vedette

En vedette (6)

Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Data file handling
Data file handlingData file handling
Data file handling
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
file handling c++
file handling c++file handling c++
file handling c++
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similaire à Rest services with Jax-rs

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
 
Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSKatrien Verbert
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RSArun Gupta
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC AnnotationsJordan Silva
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring FrameworkArcadian Learning
 
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
 
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
 
Building Restful Web Services with Java
Building Restful Web Services with JavaBuilding Restful Web Services with Java
Building Restful Web Services with JavaVassil Popovski
 
JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesLudovic Champenois
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
RestFull Webservices with JAX-RS
RestFull Webservices with JAX-RSRestFull Webservices with JAX-RS
RestFull Webservices with JAX-RSNeil Ghosh
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with JerseyScott Leberknight
 
Advance java session 3
Advance java session 3Advance java session 3
Advance java session 3Smita B Kumar
 
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
 
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
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngineMichaelRog
 
Course sites new user profile pages
Course sites new user profile pagesCourse sites new user profile pages
Course sites new user profile pagesWayan Wira
 

Similaire à Rest services with Jax-rs (20)

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!
 
Using Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: JAX-RSUsing Java to implement RESTful Web Services: JAX-RS
Using Java to implement RESTful Web Services: 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
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC Annotations
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework
 
Lab swe-2013intro jax-rs
Lab swe-2013intro jax-rsLab swe-2013intro jax-rs
Lab swe-2013intro jax-rs
 
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
 
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
 
Jersey
JerseyJersey
Jersey
 
Building Restful Web Services with Java
Building Restful Web Services with JavaBuilding Restful Web Services with Java
Building Restful Web Services with Java
 
JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul services
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
RestFull Webservices with JAX-RS
RestFull Webservices with JAX-RSRestFull Webservices with JAX-RS
RestFull Webservices with JAX-RS
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
 
Advance java session 3
Advance java session 3Advance java session 3
Advance java session 3
 
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
 
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
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngine
 
Course sites new user profile pages
Course sites new user profile pagesCourse sites new user profile pages
Course sites new user profile pages
 

Dernier

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Dernier (20)

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Rest services with Jax-rs

  • 1. 4/3/2013 1 Implementing RESTful Services JAX-RS CS213 03-Apr-2013 JAX-RS Features • Annotation based – No need for any configuration in web.xml – New version of Servlet specification doesn’t require a web.xml file at all. • Flexible Deployment Option – Servlet container – JAX-RS aware container • Easy Data Handling Mechanism
  • 2. 4/3/2013 2 Core Annotations • URL Templates – @Path – Defines URI mappings and templates – Applied on the resource class (most of other annotations are for methods) • MIME handling – @Provides, @Consumes – What MIME types does the resource produce and consume • HTTP methods – @GET, @POST, @PUT, @DELETE – Identifies which HTTP method the Java method is interested in Parameter • @PathParam – Allows you to extract URI template segments – /customers/1234 – /customers/{id} • @QueryParam – Access to specific parameter URI query string – /customers?city=Lahore • @MatrixParam – /customers;city=Lahore • @FormParam • @HeaderParam – Access to a specific HTTP Header • @CoockieParam – Access to a specific cookie value • @Context – Access to contextual information such as URI or Request object • @DefaultValue
  • 3. 4/3/2013 3 Parameter Handling • HTTP request values are automatically mapped to – String and primitive types – Class types that have a constructor that takes a String parameter – Class types that have a static valueOf(String val) method to prepare an instance of that class – List , Arrays or Set of above types when there are multiple values – Byte array or string for payload (POST or PUT) Return Types • Null (Status 204) – Nothing is returned or a null value is retuned • WebApplicationException • An Entity/Object – Marshaled/serialized to its string representation • Response • GenericEntity (embedded in response object)
  • 4. 4/3/2013 4 Poll Service Example public class PollService { String getPoll(int id) { // return some JSON } // other methods } public class PollService { String getPoll(int id) { // return some JSON } // other methods } Example with JAX-RS Annotations @Path("/polls") public class PollService { @Path("/{poll-id}") @GET @Provides("application/json") String getPoll(@PathParam("poll-id") int id) { ... } } @Path("/polls") public class PollService { @Path("/{poll-id}") @GET @Provides("application/json") String getPoll(@PathParam("poll-id") int id) { ... } } Define base URL of this resource class. All request starting with this context shall be routed to this class This method will be called for all GET type requests of the form /polls/12345 Automatically convert and inject value of URL segment into id parameter. Defines extension to base URL and path segment
  • 5. 4/3/2013 5 Example with POST @Path("/polls") public class PollService { ... @POST @Consumes("application/json") Response createPoll(String data) { ... } } @Path("/polls") public class PollService { ... @POST @Consumes("application/json") Response createPoll(String data) { ... } } We will talk about it in next slide. Un-annotated parameters assumed to be incoming message body. There can be only one! What content types are expected from client? To be invoked on POST requests, i.e. CREATE a resource, message body will contain poll data. Response Object • Core Classes in JAX-RS – Response and ResponseBuilder • Objective – Customize response code – Specify certain response headers – Specify redirect URLs – Lot more.. Response createPoll(String data) { ... ResponseBuilder rb = Response.status(201); rb.type("application/json") .header("Location", "/polls/"+id); return rb.build(); } Response createPoll(String data) { ... ResponseBuilder rb = Response.status(201); rb.type("application/json") .header("Location", "/polls/"+id); return rb.build(); }
  • 6. 4/3/2013 6 Default Response Codes • GET and PUT – 200 (OK) • DELETE and POST – 200 (OK) if content sent back with response – 204 (NO CONTENT) if no content sent back or a null is returned. Example with Query Parameters • Process requests of the form – /polls?sort=title @Path("/polls") public class PollService { ... @GET @Produces({"application/json","application/xml"}) Response listPoll( @DefaultValue("cdate") @QueryParam("sort") String order) { ... } } @Path("/polls") public class PollService { ... @GET @Produces({"application/json","application/xml"}) Response listPoll( @DefaultValue("cdate") @QueryParam("sort") String order) { ... } }
  • 7. 4/3/2013 7 Frameworks • JBoss RESTeasy • Sun Jersey • CXF • Axis2 • Spring That’s All • JAX-RS Documentation – http://jersey.java.net/nonav/documentation/snap shot/index.html • Java6 Tutorial – http://docs.oracle.com/javaee/6/tutorial/doc/gijq y.html