SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
Introduction to JAX-RS
Developing RESTful Web services with JAX-RS
Freitag, 19. April 13
What is JAX-RS?
• JAX-RS: Java API for RESTful Services
• An annotation driven API to help developers build RESTful
Web services and clients in Java.
• resources are described by POJOs + annotations
• uses an http centric programming model
• is included in Java EE
Freitag, 19. April 13
What are RESTful Services?
• The way a RESTful application works:
• resources are identified by URIs
• (JAX-RS maps these resources to Java classes)
• clients read/write/modify/delete resources only via
standard http requests (GET, PUT, POST, DELETE)
• requests and responses contain resource representations
in formats identified by media types (MIME types)
• responses contain URIs that link to further resources
Freitag, 19. April 13
Pricipals of RESTful Web
Services
• give every resource (information unit) an ID
• use only the standard set of http methods
• use http links (URIs) to define relations
between resources
• you may use multiple representations (e.g. XML,
JSON, text)
• use stateless communications
• the server does not keep session information
Freitag, 19. April 13
Resources are always
identified by URIs
• JAX-RS maps a resource to a Java class
• a POJO (Plain Old Java Object)
• the resource ID is provided by the @PATH
annotation
• the value is a relative URI; the base URI is provides by the
deployment context (deployment descriptor) or parent
resource
• use embeded parameters for a variable part of the URI
Freitag, 19. April 13
Example of Resource URIs
• retrieving information about the customer of a
purchase order with known ID:
@Path("orders/{order_id}")
public class OrderResource {
@GET
@Path("customer")
CustomerResource getCustomer(...) {...}
}
variable part of URI
Freitag, 19. April 13
The Standard Set of Methods
• in contrast to SOAP-based Web services REST
uses a standard set of methods
• JAX-RS routes the request to the appropriate resource
class and method
• the method's return value is mapped to the response
Method Purpose Annotation
GET read (possible to cache it) @GET
POST update @POST
PUT create @PUT
DELETE remove @DELETE
Freitag, 19. April 13
Mapping of Parameters
• parameter annotations specify the mapping of
request parameters to Java parameters
@Path("properties/{name}")
public class SystemProperty {
@GET
Property get(@PathParam("name") String name)
{...}
@PUT
Property set(@PathParam("name") String name,
String value) {...}
}
Freitag, 19. April 13
MIME type determines
Resource Representation
• the data may be offered in a variety of formats
• XML, JSON, XHTML, text…
• for different kinds of clients
• content negotiation is supported
• by specifying it in the accept header:
• e.g.: GET /myResource
Accept: application/json
• or URI based:
• e.g.: GET /myResource.json
Freitag, 19. April 13
Response to Content Negotiation
With Accept Header
• specify resonse to different accept headers:
@GET
@Produces({"application/xml","application/json"})
Order getOrder(@PathParam("order_id") String id){
...
}
@GET
@Produces("text/plain")
String getOrder2(@PathParam("order_id") String id){
...
}
Freitag, 19. April 13
Response to URL-based Content
Negotiation
• specify resonse to different URL endings:
@Path("/orders")
public class OrderResource {
@Path("{orderId}.xml")
@GET
public Order getOrderInXML(@PathParam("orderId")
String orderId) {
. . .
}
@Path("{orderId}.json")
@GET
public Order getOrderInJSON(@PathParam("orderId")
String orderId) {
. . .
}
}
Freitag, 19. April 13
Use http Links to Define
Relations Between Resources
• example where the response contains links
• link customer and product information to purchase order:
<order self="http://example.com/orders/101230">
<customer ref="http://example.com/customers/bar">
<product ref="http://example.com/products/21034"/>
<amount value="1"/>
</order>
Freitag, 19. April 13
JAX-RS Implementations
• every Java EE 6 application server implements it
• Java SE 6 and 7 do not implement it
• Jersey is the open source, production quality,
JAX-RS (JSR 311) Reference Implementation
• http://jersey.java.net
• may be used with a servlet container (e.g.Tomcat) or
with the mini-http-server build into Java SE 6 and 7
Freitag, 19. April 13
Jersey
• download the latest versions of the following
files and put them in your classpath:
• jersey-bundle.jar
• jsr311-api.jar
• asm.jar
Freitag, 19. April 13
Almost the simplest
example possible:
• defining a RESTful service to return Java system
properties
Freitag, 19. April 13
Deployment with the build-
in Server
• Jersey integrates itself into the Java build-in http-server
• when starting, it will scan the classpath for JAX-RS
annotated classes…
Freitag, 19. April 13
To Get It Going…
• javac -cp bin:lib/* -d bin src/sinfo/*.java
• java -cp bin:lib/* sinfo/ServerInfoBuildInServer
Apr 17, 2013 6:15:55 PM com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Scanning for root resource and provider classes in the paths:
bin
lib/asm-3.3.1.jar
lib/jersey-bundle-1.17.jar
Apr 17, 2013 6:15:55 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class sinfo.ServerInfo
Apr 17, 2013 6:15:55 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Apr 17, 2013 6:15:55 PM com.sun.jersey.server.impl.application.WebApplicationImp
Freitag, 19. April 13
A Simple Client
• the client may use Jersey as well to simplify the
coding:
Freitag, 19. April 13
To Get It Going…
• javac -cp bin:lib/* -d bin src/sinfo/*.java
• java -cp bin:lib/* sinfo/ServerInfoClient
Mac OS X
Freitag, 19. April 13
Returning a Java Object as
XML
• the Java API for XML Binding JAXB may be used
to let our service return all Java system
properties as XML
• JAXB converts a Java Object to XML
• we use the @XMLRootElement annotation
to translate a java.util.Properties object
into XML
Freitag, 19. April 13
Modified ServerInfo.java
Freitag, 19. April 13
The Object Containing the
System Properties
Freitag, 19. April 13
Testing the Modified Service With a
Browser
Freitag, 19. April 13

Más contenido relacionado

La actualidad más candente

SQL Server 2012 - FileTables
SQL Server 2012 - FileTables SQL Server 2012 - FileTables
SQL Server 2012 - FileTables Sperasoft
 
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
 
#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)Ghadeer AlHasan
 
Adventures in Linked Data Land (presentation by Richard Light)
Adventures in Linked Data Land (presentation by Richard Light)Adventures in Linked Data Land (presentation by Richard Light)
Adventures in Linked Data Land (presentation by Richard Light)jottevanger
 
Content migration Part 1: TERMINALFOUR t44u 2013
Content migration Part 1: TERMINALFOUR t44u 2013Content migration Part 1: TERMINALFOUR t44u 2013
Content migration Part 1: TERMINALFOUR t44u 2013Terminalfour
 
Building RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSBuilding RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSLuciano Resende
 
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OOVirtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OOPaolo Cristofaro
 

La actualidad más candente (7)

SQL Server 2012 - FileTables
SQL Server 2012 - FileTables SQL Server 2012 - FileTables
SQL Server 2012 - FileTables
 
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!
 
#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)
 
Adventures in Linked Data Land (presentation by Richard Light)
Adventures in Linked Data Land (presentation by Richard Light)Adventures in Linked Data Land (presentation by Richard Light)
Adventures in Linked Data Land (presentation by Richard Light)
 
Content migration Part 1: TERMINALFOUR t44u 2013
Content migration Part 1: TERMINALFOUR t44u 2013Content migration Part 1: TERMINALFOUR t44u 2013
Content migration Part 1: TERMINALFOUR t44u 2013
 
Building RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RSBuilding RESTful services using SCA and JAX-RS
Building RESTful services using SCA and JAX-RS
 
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OOVirtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
 

Destacado

Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Item basedcollaborativefilteringrecommendationalgorithms
Item basedcollaborativefilteringrecommendationalgorithmsItem basedcollaborativefilteringrecommendationalgorithms
Item basedcollaborativefilteringrecommendationalgorithmsAravindharamanan S
 
The design and implementation of an intelligent online recommender system
The design and implementation of an intelligent online recommender systemThe design and implementation of an intelligent online recommender system
The design and implementation of an intelligent online recommender systemAravindharamanan S
 
Big data-analytics-2013-peer-research-report
Big data-analytics-2013-peer-research-reportBig data-analytics-2013-peer-research-report
Big data-analytics-2013-peer-research-reportAravindharamanan S
 
Sql server 2012 tutorials analysis services multidimensional modeling
Sql server 2012 tutorials   analysis services multidimensional modelingSql server 2012 tutorials   analysis services multidimensional modeling
Sql server 2012 tutorials analysis services multidimensional modelingAravindharamanan S
 
Eecs6893 big dataanalytics-lecture1
Eecs6893 big dataanalytics-lecture1Eecs6893 big dataanalytics-lecture1
Eecs6893 big dataanalytics-lecture1Aravindharamanan S
 
Big data-analytics-for-smart-manufacturing-systems-report
Big data-analytics-for-smart-manufacturing-systems-reportBig data-analytics-for-smart-manufacturing-systems-report
Big data-analytics-for-smart-manufacturing-systems-reportAravindharamanan S
 
Introducing wcf in_net_framework_4
Introducing wcf in_net_framework_4Introducing wcf in_net_framework_4
Introducing wcf in_net_framework_4Aravindharamanan S
 

Destacado (18)

Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Item basedcollaborativefilteringrecommendationalgorithms
Item basedcollaborativefilteringrecommendationalgorithmsItem basedcollaborativefilteringrecommendationalgorithms
Item basedcollaborativefilteringrecommendationalgorithms
 
12 chapter 4
12 chapter 412 chapter 4
12 chapter 4
 
The design and implementation of an intelligent online recommender system
The design and implementation of an intelligent online recommender systemThe design and implementation of an intelligent online recommender system
The design and implementation of an intelligent online recommender system
 
Soap over-udp
Soap over-udpSoap over-udp
Soap over-udp
 
Android studio main window
Android studio main windowAndroid studio main window
Android studio main window
 
Big data-analytics-2013-peer-research-report
Big data-analytics-2013-peer-research-reportBig data-analytics-2013-peer-research-report
Big data-analytics-2013-peer-research-report
 
Tesi v.d.cuccaro
Tesi v.d.cuccaroTesi v.d.cuccaro
Tesi v.d.cuccaro
 
Sql server 2012 tutorials analysis services multidimensional modeling
Sql server 2012 tutorials   analysis services multidimensional modelingSql server 2012 tutorials   analysis services multidimensional modeling
Sql server 2012 tutorials analysis services multidimensional modeling
 
Dbi h315
Dbi h315Dbi h315
Dbi h315
 
Tutorial recommender systems
Tutorial recommender systemsTutorial recommender systems
Tutorial recommender systems
 
Eecs6893 big dataanalytics-lecture1
Eecs6893 big dataanalytics-lecture1Eecs6893 big dataanalytics-lecture1
Eecs6893 big dataanalytics-lecture1
 
Httpcore tutorial
Httpcore tutorialHttpcore tutorial
Httpcore tutorial
 
Android networking-2
Android networking-2Android networking-2
Android networking-2
 
Big data-analytics-for-smart-manufacturing-systems-report
Big data-analytics-for-smart-manufacturing-systems-reportBig data-analytics-for-smart-manufacturing-systems-report
Big data-analytics-for-smart-manufacturing-systems-report
 
Msstudio
MsstudioMsstudio
Msstudio
 
Introducing wcf in_net_framework_4
Introducing wcf in_net_framework_4Introducing wcf in_net_framework_4
Introducing wcf in_net_framework_4
 
Android web service client
Android web service clientAndroid web service client
Android web service client
 

Similar a Lab swe-2013intro jax-rs

JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesLudovic Champenois
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RSArun Gupta
 
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
 
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
 
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
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India
 
Rest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerRest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerKumaraswamy M
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6Yuval Ararat
 
Rest services with Jax-rs
Rest services with Jax-rsRest services with Jax-rs
Rest services with Jax-rsGuddu Spy
 
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
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
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
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyPayal Jain
 
Building Restful Web Services with Java
Building Restful Web Services with JavaBuilding Restful Web Services with Java
Building Restful Web Services with JavaVassil Popovski
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
Introduction to RESTful Webservices in JAVA
Introduction to RESTful Webservices  in JAVA Introduction to RESTful Webservices  in JAVA
Introduction to RESTful Webservices in JAVA psrpatnaik
 
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
 
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
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with JerseyScott Leberknight
 

Similar a Lab swe-2013intro jax-rs (20)

JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul services
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using 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
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
JAX - RS MuleSoft ESB
JAX - RS MuleSoft ESBJAX - RS MuleSoft ESB
JAX - RS MuleSoft ESB
 
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
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
 
Rest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerRest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swagger
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
Rest services with Jax-rs
Rest services with Jax-rsRest services with Jax-rs
Rest services with Jax-rs
 
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
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
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
 
Network Device Database Management with REST using Jersey
Network Device Database Management with REST using JerseyNetwork Device Database Management with REST using Jersey
Network Device Database Management with REST using Jersey
 
Building Restful Web Services with Java
Building Restful Web Services with JavaBuilding Restful Web Services with Java
Building Restful Web Services with Java
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Introduction to RESTful Webservices in JAVA
Introduction to RESTful Webservices  in JAVA Introduction to RESTful Webservices  in JAVA
Introduction to RESTful Webservices in JAVA
 
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
 
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
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
 

Último

Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Standkumarajju5765
 
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)sonalinghatmal
 
Joshua Minker Brand Exploration Sports Broadcaster .pptx
Joshua Minker Brand Exploration Sports Broadcaster .pptxJoshua Minker Brand Exploration Sports Broadcaster .pptx
Joshua Minker Brand Exploration Sports Broadcaster .pptxsportsworldproductio
 
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...amitlee9823
 
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Internship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkInternship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkSujalTamhane
 
Resumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying OnlineResumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying OnlineBruce Bennett
 
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...sonalitrivedi431
 
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...rightmanforbloodline
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.GabrielaMiletti
 
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdfssuserded2d4
 
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls DubaiDark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls Dubaikojalkojal131
 
Presentation for the country presentation
Presentation for the country presentationPresentation for the country presentation
Presentation for the country presentationjalal879
 
Guide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWNGuide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWNBruce Bennett
 
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...amitlee9823
 
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...ssifa0344
 

Último (20)

Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Janakpuri ☎ 9711199171 Book Your One night Stand
 
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
Toxicokinetics studies.. (toxicokinetics evaluation in preclinical studies)
 
Joshua Minker Brand Exploration Sports Broadcaster .pptx
Joshua Minker Brand Exploration Sports Broadcaster .pptxJoshua Minker Brand Exploration Sports Broadcaster .pptx
Joshua Minker Brand Exploration Sports Broadcaster .pptx
 
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Bidadi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jayanagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Devanahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Brigade Road Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
 
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Road Call Me 7737669865 Budget Friendly No Advance Booking
 
Internship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmkInternship Report].pdf iiwmoosmsosmshkssmk
Internship Report].pdf iiwmoosmsosmshkssmk
 
Resumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying OnlineResumes, Cover Letters, and Applying Online
Resumes, Cover Letters, and Applying Online
 
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hosur Road Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...
Hyderabad 💫✅💃 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATIS...
 
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
TEST BANK For An Introduction to Brain and Behavior, 7th Edition by Bryan Kol...
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.
 
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf0425-GDSC-TMU.pdf
 
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls DubaiDark Dubai Call Girls O525547819 Skin Call Girls Dubai
Dark Dubai Call Girls O525547819 Skin Call Girls Dubai
 
Presentation for the country presentation
Presentation for the country presentationPresentation for the country presentation
Presentation for the country presentation
 
Guide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWNGuide to a Winning Interview May 2024 for MCWN
Guide to a Winning Interview May 2024 for MCWN
 
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Ghatkopar Call On 9920725232 With Body to body massage ...
 
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...
Solution Manual for First Course in Abstract Algebra A, 8th Edition by John B...
 

Lab swe-2013intro jax-rs

  • 1. Introduction to JAX-RS Developing RESTful Web services with JAX-RS Freitag, 19. April 13
  • 2. What is JAX-RS? • JAX-RS: Java API for RESTful Services • An annotation driven API to help developers build RESTful Web services and clients in Java. • resources are described by POJOs + annotations • uses an http centric programming model • is included in Java EE Freitag, 19. April 13
  • 3. What are RESTful Services? • The way a RESTful application works: • resources are identified by URIs • (JAX-RS maps these resources to Java classes) • clients read/write/modify/delete resources only via standard http requests (GET, PUT, POST, DELETE) • requests and responses contain resource representations in formats identified by media types (MIME types) • responses contain URIs that link to further resources Freitag, 19. April 13
  • 4. Pricipals of RESTful Web Services • give every resource (information unit) an ID • use only the standard set of http methods • use http links (URIs) to define relations between resources • you may use multiple representations (e.g. XML, JSON, text) • use stateless communications • the server does not keep session information Freitag, 19. April 13
  • 5. Resources are always identified by URIs • JAX-RS maps a resource to a Java class • a POJO (Plain Old Java Object) • the resource ID is provided by the @PATH annotation • the value is a relative URI; the base URI is provides by the deployment context (deployment descriptor) or parent resource • use embeded parameters for a variable part of the URI Freitag, 19. April 13
  • 6. Example of Resource URIs • retrieving information about the customer of a purchase order with known ID: @Path("orders/{order_id}") public class OrderResource { @GET @Path("customer") CustomerResource getCustomer(...) {...} } variable part of URI Freitag, 19. April 13
  • 7. The Standard Set of Methods • in contrast to SOAP-based Web services REST uses a standard set of methods • JAX-RS routes the request to the appropriate resource class and method • the method's return value is mapped to the response Method Purpose Annotation GET read (possible to cache it) @GET POST update @POST PUT create @PUT DELETE remove @DELETE Freitag, 19. April 13
  • 8. Mapping of Parameters • parameter annotations specify the mapping of request parameters to Java parameters @Path("properties/{name}") public class SystemProperty { @GET Property get(@PathParam("name") String name) {...} @PUT Property set(@PathParam("name") String name, String value) {...} } Freitag, 19. April 13
  • 9. MIME type determines Resource Representation • the data may be offered in a variety of formats • XML, JSON, XHTML, text… • for different kinds of clients • content negotiation is supported • by specifying it in the accept header: • e.g.: GET /myResource Accept: application/json • or URI based: • e.g.: GET /myResource.json Freitag, 19. April 13
  • 10. Response to Content Negotiation With Accept Header • specify resonse to different accept headers: @GET @Produces({"application/xml","application/json"}) Order getOrder(@PathParam("order_id") String id){ ... } @GET @Produces("text/plain") String getOrder2(@PathParam("order_id") String id){ ... } Freitag, 19. April 13
  • 11. Response to URL-based Content Negotiation • specify resonse to different URL endings: @Path("/orders") public class OrderResource { @Path("{orderId}.xml") @GET public Order getOrderInXML(@PathParam("orderId") String orderId) { . . . } @Path("{orderId}.json") @GET public Order getOrderInJSON(@PathParam("orderId") String orderId) { . . . } } Freitag, 19. April 13
  • 12. Use http Links to Define Relations Between Resources • example where the response contains links • link customer and product information to purchase order: <order self="http://example.com/orders/101230"> <customer ref="http://example.com/customers/bar"> <product ref="http://example.com/products/21034"/> <amount value="1"/> </order> Freitag, 19. April 13
  • 13. JAX-RS Implementations • every Java EE 6 application server implements it • Java SE 6 and 7 do not implement it • Jersey is the open source, production quality, JAX-RS (JSR 311) Reference Implementation • http://jersey.java.net • may be used with a servlet container (e.g.Tomcat) or with the mini-http-server build into Java SE 6 and 7 Freitag, 19. April 13
  • 14. Jersey • download the latest versions of the following files and put them in your classpath: • jersey-bundle.jar • jsr311-api.jar • asm.jar Freitag, 19. April 13
  • 15. Almost the simplest example possible: • defining a RESTful service to return Java system properties Freitag, 19. April 13
  • 16. Deployment with the build- in Server • Jersey integrates itself into the Java build-in http-server • when starting, it will scan the classpath for JAX-RS annotated classes… Freitag, 19. April 13
  • 17. To Get It Going… • javac -cp bin:lib/* -d bin src/sinfo/*.java • java -cp bin:lib/* sinfo/ServerInfoBuildInServer Apr 17, 2013 6:15:55 PM com.sun.jersey.api.core.ClasspathResourceConfig init INFO: Scanning for root resource and provider classes in the paths: bin lib/asm-3.3.1.jar lib/jersey-bundle-1.17.jar Apr 17, 2013 6:15:55 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses INFO: Root resource classes found: class sinfo.ServerInfo Apr 17, 2013 6:15:55 PM com.sun.jersey.api.core.ScanningResourceConfig init INFO: No provider classes found. Apr 17, 2013 6:15:55 PM com.sun.jersey.server.impl.application.WebApplicationImp Freitag, 19. April 13
  • 18. A Simple Client • the client may use Jersey as well to simplify the coding: Freitag, 19. April 13
  • 19. To Get It Going… • javac -cp bin:lib/* -d bin src/sinfo/*.java • java -cp bin:lib/* sinfo/ServerInfoClient Mac OS X Freitag, 19. April 13
  • 20. Returning a Java Object as XML • the Java API for XML Binding JAXB may be used to let our service return all Java system properties as XML • JAXB converts a Java Object to XML • we use the @XMLRootElement annotation to translate a java.util.Properties object into XML Freitag, 19. April 13
  • 22. The Object Containing the System Properties Freitag, 19. April 13
  • 23. Testing the Modified Service With a Browser Freitag, 19. April 13