SlideShare una empresa de Scribd logo
1 de 25
Using Java to implement REST Web
Services: JAX-RS

Web Technology
2II25
Dr. Katrien Verbert
Dr. ir. Natasha Stash
Dr. George Fletcher
Restful Web Services Frameworks and APIs

• JAX-RS - The Java API for RESTful Web Services
• uses annotations to make plain old Java objects (POJOs) and
  resources available through HTTP
• Sun Reference Project: Jersey
• Other Vendors: CXF (Apache), RESTEasy(JBoss) and Restlet

• JAX-RS tutorial:
   http://docs.oracle.com/javaee/6/tutorial/doc/gilik.html
JAX-RS HTTP

• Templated mapping and subresources
   @Path
• MIME handling
   @Provides, @Consumes
• HTTP methods
   @GET, @POST, @UPDATE, @DELETE, @HEAD,
   @OPTIONS, @HttpMethod
• Caching
   evaluatePreconditions
Example
package com.sun.jersey.samples.helloworld.resources;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;


// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {


    // The Java method will process HTTP GET requests
    @GET
    // The Java method will produce content identified by the MIME Media
    // type "text/plain"
    @Produces("text/plain")
    public String getClichedMessage() {
        // Return some cliched textual content
        return "Hello World";
    }
}
@Path Annotation and URI Path Templates

@Path annotation
    • identifies the URI path template to which the resource responds
    • is specified at the class or method level of a resource

URI path templates are URIs with variables embedded within the URI syntax
    • these variables are substituted at runtime
    • variables are denoted by braces ({ and })
         @Path("/users/{username}")
    • example request
         http://example.com/users/Galileo
@PathParam annotation

To obtain the value of the user name, the @PathParam
  annotation may be used on the method parameter of a
  request method

@Path("/users/{username}")
public class UserResource {


    @GET
    @Produces("text/xml")
    public String getUser(@PathParam("username") String userName) {
        ...
    }
}
Examples of URI Path Templates

 URI Path Template                     URI After Substitution

 http://example.com/{name1}/{name2}/   http://example.com/james/gatz/


 http://example.com/{question}/        http://example.com/why/why/why/
 {question}/{question}/

 http://example.com/maps/{location}    http://example.com/maps/Main%20Street
@Produces Annotation

@Produces annotation is used to specify the MIME media
 types or representations a resource can produce and
 send back to the client

• applied at the class level: default for all methods
• applied at the method level overrides any @Produces
  annotations applied at the class level
@produces annotation

@Path("/myResource")
@Produces("text/plain")
public class SomeResource {
    @GET
    public String doGetAsPlainText() {
        ...
    }


    @GET
    @Produces("text/html")
    public String doGetAsHtml() {
        ...
    }
}
@Consumes Annotation

@Consumes annotation is used to specify which MIME media
 types of representations a resource can accept


   @POST
   @Consumes("text/plain")
   public void postClichedMessage(String message) {
       // Store the message
   }
Develop Restful service in Netbeans




                03/28/11
Develop Restful service in Netbeans




                03/28/11
Develop Restful service in Netbeans




                03/28/11
Develop Restful service in Netbeans
package orders;
import javax.ws.rs.*;


@Path("order")
public class OrderResource {
    public OrderResource() {
    }


    @GET
    @Produces("application/xml")
    public Order getLastOrder() {
        return Orders.getLastOrder();
    }


    @PUT
    @Consumes("application/xml")
    public void putOrder(Order order) {
        Orders.setLastOrder(order);
    }
}
Develop Restful service in Netbeans
package orders;


public class Orders {


    private static Order lastOrder=new Order();


    public static Order getLastOrder() {
        return lastOrder;
    }


    public static void setLastOrder(Order lastOrder) {
        Orders.lastOrder = lastOrder;
    }




}
Deploy Restful service in Netbeans




                03/28/11
Test Restful service in Netbeans




                03/28/11
03/28/11
Testing Restful services

Netbeans test client does not work well with XML
  parameters

Better alternative:

RESTClient, a debugger for RESTful web services
https://addons.mozilla.org/nl/firefox/addon/restclient/




                      03/28/11
RESTClient




             03/28/11
Testing Restful services

If you pass XML strings as parameters, you need to specify
    this in the header




                    03/28/11
Add header parameters




              03/28/11
Add header parameters




              03/28/11
Placing an order




                   03/28/11
k.verbert@tue.nl
n.v.stash@tue.nl
g.l.fletcher@tue.nl




           03/28/11

Más contenido relacionado

La actualidad más candente

Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with JerseyScott Leberknight
 
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionseyelliando dias
 
WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0Jeffrey West
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web ServiceHoan Vu Tran
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scalab0ris_1
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8Andrei Jechiu
 
Designing a RESTful web service
Designing a RESTful web serviceDesigning a RESTful web service
Designing a RESTful web serviceFilip Blondeel
 
How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptxHarry Potter
 
Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEreneechemel
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection apiMatthieu Aubry
 

La actualidad más candente (20)

Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
RESTful Web Services with Jersey
RESTful Web Services with JerseyRESTful Web Services with Jersey
RESTful Web Services with Jersey
 
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
 
WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Services in Drupal 8
Services in Drupal 8Services in Drupal 8
Services in Drupal 8
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Designing a RESTful web service
Designing a RESTful web serviceDesigning a RESTful web service
Designing a RESTful web service
 
How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptx
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
L18 REST API Design
L18 REST API DesignL18 REST API Design
L18 REST API Design
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 

Destacado

Scalableenterpriseapplicationswith jee7andbeyond
Scalableenterpriseapplicationswith jee7andbeyondScalableenterpriseapplicationswith jee7andbeyond
Scalableenterpriseapplicationswith jee7andbeyondAndy Moncsek
 
What’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyWhat’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyMohamed Taman
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming PrimerIvano Malavolta
 
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 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesArun Gupta
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WSIndicThreads
 
Adopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS updateAdopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS updatePavel Bucek
 
Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web ServicesAngelin R
 
Web Service Presentation
Web Service PresentationWeb Service Presentation
Web Service Presentationguest0df6b0
 
JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013Jagadish Prasath
 
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...jaxLondonConference
 
Testing web services
Testing web servicesTesting web services
Testing web servicesTaras Lytvyn
 

Destacado (20)

Scalableenterpriseapplicationswith jee7andbeyond
Scalableenterpriseapplicationswith jee7andbeyondScalableenterpriseapplicationswith jee7andbeyond
Scalableenterpriseapplicationswith jee7andbeyond
 
What’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyWhat’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new Strategy
 
Server-Side Programming Primer
Server-Side Programming PrimerServer-Side Programming Primer
Server-Side Programming Primer
 
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
 
Overview of web services
Overview of web servicesOverview of web services
Overview of web services
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
 
Web services
Web servicesWeb services
Web services
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WS
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
Adopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS updateAdopt-a-jsr Mar 1 2017 JAX-RS update
Adopt-a-jsr Mar 1 2017 JAX-RS update
 
Restful Web Services
Restful Web ServicesRestful Web Services
Restful Web Services
 
Webservices
WebservicesWebservices
Webservices
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
Web service introduction
Web service introductionWeb service introduction
Web service introduction
 
Web servers
Web serversWeb servers
Web servers
 
Web Service Presentation
Web Service PresentationWeb Service Presentation
Web Service Presentation
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013JAX RS 2.0 - OTN Bangalore 2013
JAX RS 2.0 - OTN Bangalore 2013
 
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
Getting Started with WebSocket and Server-Sent Events using Java - Arun Gupta...
 
Testing web services
Testing web servicesTesting web services
Testing web services
 

Similar a Using Java to implement RESTful Web Services: 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
 
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
 
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
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
Building Restful Web Services with Java
Building Restful Web Services with JavaBuilding Restful Web Services with Java
Building Restful Web Services with JavaVassil Popovski
 
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
 
03 form-data
03 form-data03 form-data
03 form-datasnopteck
 
Rest services with Jax-rs
Rest services with Jax-rsRest services with Jax-rs
Rest services with Jax-rsGuddu Spy
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesLudovic Champenois
 
WhatsNewNIO2.pdf
WhatsNewNIO2.pdfWhatsNewNIO2.pdf
WhatsNewNIO2.pdfMohit Kumar
 
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
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeMarco Gralike
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011Shreedhar Ganapathy
 
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
 

Similar a Using Java to implement RESTful Web Services: 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!
 
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
 
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
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
Building Restful Web Services with Java
Building Restful Web Services with JavaBuilding Restful Web Services with Java
Building Restful Web Services with Java
 
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
 
REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
 
03 form-data
03 form-data03 form-data
03 form-data
 
Rest services with Jax-rs
Rest services with Jax-rsRest services with Jax-rs
Rest services with Jax-rs
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
JAX-RS Creating RESTFul services
JAX-RS Creating RESTFul servicesJAX-RS Creating RESTFul services
JAX-RS Creating RESTFul services
 
WhatsNewNIO2.pdf
WhatsNewNIO2.pdfWhatsNewNIO2.pdf
WhatsNewNIO2.pdf
 
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
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
How to connect redis and mule esb using spring data redis module
How to connect redis and mule esb using spring data redis moduleHow to connect redis and mule esb using spring data redis module
How to connect redis and mule esb using spring data redis module
 
Power tools in Java
Power tools in JavaPower tools in Java
Power tools in Java
 
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
 
SCDJWS 5. JAX-WS
SCDJWS 5. JAX-WSSCDJWS 5. JAX-WS
SCDJWS 5. JAX-WS
 

Más de Katrien Verbert

Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Katrien Verbert
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Katrien Verbert
 
Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Katrien Verbert
 
Explaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveExplaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveKatrien Verbert
 
Explaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedExplaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedKatrien Verbert
 
Designing Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedDesigning Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedKatrien Verbert
 
Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Katrien Verbert
 
Explainable AI for non-expert users
Explainable AI for non-expert usersExplainable AI for non-expert users
Explainable AI for non-expert usersKatrien Verbert
 
Towards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsTowards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsKatrien Verbert
 
Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Katrien Verbert
 
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Katrien Verbert
 
Learning analytics for feedback at scale
Learning analytics for feedback at scaleLearning analytics for feedback at scale
Learning analytics for feedback at scaleKatrien Verbert
 
Interactive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningInteractive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningKatrien Verbert
 
Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Katrien Verbert
 
Interactive Recommender Systems
Interactive Recommender SystemsInteractive Recommender Systems
Interactive Recommender SystemsKatrien Verbert
 
Web Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLWeb Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLKatrien Verbert
 
Information Visualisation: perception and principles
Information Visualisation: perception and principlesInformation Visualisation: perception and principles
Information Visualisation: perception and principlesKatrien Verbert
 
Web Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionWeb Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionKatrien Verbert
 
Information Visualisation: Introduction
Information Visualisation: IntroductionInformation Visualisation: Introduction
Information Visualisation: IntroductionKatrien Verbert
 

Más de Katrien Verbert (20)

Explainability methods
Explainability methodsExplainability methods
Explainability methods
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?
 
Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?Human-centered AI: how can we support end-users to interact with AI?
Human-centered AI: how can we support end-users to interact with AI?
 
Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?Human-centered AI: how can we support lay users to understand AI?
Human-centered AI: how can we support lay users to understand AI?
 
Explaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspectiveExplaining job recommendations: a human-centred perspective
Explaining job recommendations: a human-centred perspective
 
Explaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learnedExplaining recommendations: design implications and lessons learned
Explaining recommendations: design implications and lessons learned
 
Designing Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons LearnedDesigning Learning Analytics Dashboards: Lessons Learned
Designing Learning Analytics Dashboards: Lessons Learned
 
Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...Human-centered AI: towards the next generation of interactive and adaptive ex...
Human-centered AI: towards the next generation of interactive and adaptive ex...
 
Explainable AI for non-expert users
Explainable AI for non-expert usersExplainable AI for non-expert users
Explainable AI for non-expert users
 
Towards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methodsTowards the next generation of interactive and adaptive explanation methods
Towards the next generation of interactive and adaptive explanation methods
 
Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...Personalized food recommendations: combining recommendation, visualization an...
Personalized food recommendations: combining recommendation, visualization an...
 
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
Explaining and Exploring Job Recommendations: a User-driven Approach for Inte...
 
Learning analytics for feedback at scale
Learning analytics for feedback at scaleLearning analytics for feedback at scale
Learning analytics for feedback at scale
 
Interactive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learningInteractive recommender systems and dashboards for learning
Interactive recommender systems and dashboards for learning
 
Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”Interactive recommender systems: opening up the “black box”
Interactive recommender systems: opening up the “black box”
 
Interactive Recommender Systems
Interactive Recommender SystemsInteractive Recommender Systems
Interactive Recommender Systems
 
Web Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTMLWeb Information Systems Lecture 2: HTML
Web Information Systems Lecture 2: HTML
 
Information Visualisation: perception and principles
Information Visualisation: perception and principlesInformation Visualisation: perception and principles
Information Visualisation: perception and principles
 
Web Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: IntroductionWeb Information Systems Lecture 1: Introduction
Web Information Systems Lecture 1: Introduction
 
Information Visualisation: Introduction
Information Visualisation: IntroductionInformation Visualisation: Introduction
Information Visualisation: Introduction
 

Using Java to implement RESTful Web Services: JAX-RS

  • 1. Using Java to implement REST Web Services: JAX-RS Web Technology 2II25 Dr. Katrien Verbert Dr. ir. Natasha Stash Dr. George Fletcher
  • 2. Restful Web Services Frameworks and APIs • JAX-RS - The Java API for RESTful Web Services • uses annotations to make plain old Java objects (POJOs) and resources available through HTTP • Sun Reference Project: Jersey • Other Vendors: CXF (Apache), RESTEasy(JBoss) and Restlet • JAX-RS tutorial: http://docs.oracle.com/javaee/6/tutorial/doc/gilik.html
  • 3. JAX-RS HTTP • Templated mapping and subresources @Path • MIME handling @Provides, @Consumes • HTTP methods @GET, @POST, @UPDATE, @DELETE, @HEAD, @OPTIONS, @HttpMethod • Caching evaluatePreconditions
  • 4. Example package com.sun.jersey.samples.helloworld.resources; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.Path; // The Java class will be hosted at the URI path "/helloworld" @Path("/helloworld") public class HelloWorldResource { // The Java method will process HTTP GET requests @GET // The Java method will produce content identified by the MIME Media // type "text/plain" @Produces("text/plain") public String getClichedMessage() { // Return some cliched textual content return "Hello World"; } }
  • 5. @Path Annotation and URI Path Templates @Path annotation • identifies the URI path template to which the resource responds • is specified at the class or method level of a resource URI path templates are URIs with variables embedded within the URI syntax • these variables are substituted at runtime • variables are denoted by braces ({ and }) @Path("/users/{username}") • example request http://example.com/users/Galileo
  • 6. @PathParam annotation To obtain the value of the user name, the @PathParam annotation may be used on the method parameter of a request method @Path("/users/{username}") public class UserResource { @GET @Produces("text/xml") public String getUser(@PathParam("username") String userName) { ... } }
  • 7. Examples of URI Path Templates URI Path Template URI After Substitution http://example.com/{name1}/{name2}/ http://example.com/james/gatz/ http://example.com/{question}/ http://example.com/why/why/why/ {question}/{question}/ http://example.com/maps/{location} http://example.com/maps/Main%20Street
  • 8. @Produces Annotation @Produces annotation is used to specify the MIME media types or representations a resource can produce and send back to the client • applied at the class level: default for all methods • applied at the method level overrides any @Produces annotations applied at the class level
  • 9. @produces annotation @Path("/myResource") @Produces("text/plain") public class SomeResource { @GET public String doGetAsPlainText() { ... } @GET @Produces("text/html") public String doGetAsHtml() { ... } }
  • 10. @Consumes Annotation @Consumes annotation is used to specify which MIME media types of representations a resource can accept @POST @Consumes("text/plain") public void postClichedMessage(String message) { // Store the message }
  • 11. Develop Restful service in Netbeans 03/28/11
  • 12. Develop Restful service in Netbeans 03/28/11
  • 13. Develop Restful service in Netbeans 03/28/11
  • 14. Develop Restful service in Netbeans package orders; import javax.ws.rs.*; @Path("order") public class OrderResource { public OrderResource() { } @GET @Produces("application/xml") public Order getLastOrder() { return Orders.getLastOrder(); } @PUT @Consumes("application/xml") public void putOrder(Order order) { Orders.setLastOrder(order); } }
  • 15. Develop Restful service in Netbeans package orders; public class Orders { private static Order lastOrder=new Order(); public static Order getLastOrder() { return lastOrder; } public static void setLastOrder(Order lastOrder) { Orders.lastOrder = lastOrder; } }
  • 16. Deploy Restful service in Netbeans 03/28/11
  • 17. Test Restful service in Netbeans 03/28/11
  • 19. Testing Restful services Netbeans test client does not work well with XML parameters Better alternative: RESTClient, a debugger for RESTful web services https://addons.mozilla.org/nl/firefox/addon/restclient/ 03/28/11
  • 20. RESTClient 03/28/11
  • 21. Testing Restful services If you pass XML strings as parameters, you need to specify this in the header 03/28/11
  • 24. Placing an order 03/28/11

Notas del editor

  1. helloworld
  2. The @Consumes annotation is used to specify which MIME media types of representations a resource can accept, or consume, from the client. If @Consumes is applied at the class level, all the response methods accept the specified MIME types by default. If applied at the method level, @Consumes overrides any @Consumes annotations applied at the class level.If a resource is unable to consume the MIME type of a client request, the JAX-RS runtime sends back an HTTP 415 ( “ Unsupported Media Type ” ) error.The value of @Consumes is an array of String of acceptable MIME types. For example:@Consumes({"text/plain,text/html"})The following example shows how to apply @Consumes at both the class and method levels:@Path("/myResource")@Consumes("multipart/related")public class SomeResource { @POST public String doPost(MimeMultipart mimeMultipartData) { ... } @POST @Consumes("application/x-www-form-urlencoded") public String doPost2(FormURLEncodedProperties formData) { ... }}The doPost method defaults to the MIME media type of the @Consumes annotation at the class level. The doPost2 method overrides the class level @Consumes annotation to specify that it can accept URL-encoded form data.If no resource methods can respond to the requested MIME type, an HTTP 415 ( “ Unsupported Media Type ” ) error is returned to the client.The HelloWorld example discussed previously in this section can be modified to set the message by using @Consumes, as shown in the following code example:@POST@Consumes("text/plain")public void postClichedMessage(String message) { // Store the message}In this example, the Java method will consume representations identified by the MIME media type text/plain. Note that the resource method returns void. This means that no representation is returned and that a response with a status code of HTTP 204 ( “ No Content ” ) will be returned.