SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
Rest Web Service with Spring
The goal of this lab work is to develop a small application for cars renting.
The functionalities to implements are:
- Get a list of unrented cars
- Rent a car
- Get back a car
Those functionalities are defined by the following interface:
package web;
import java.util.List;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import dto.CarDTO;
public interface RentService {
@RequestMapping(value = "/entryPoint", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public ResourceSupport get();
/**
*
* @return all cars not rented
*/
@RequestMapping(value = "/car", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public List<CarDTO> getCars();
/**
* Return specifications of a car.
* @param plateNumber
* @return car specifications only (if not rented)
* @throws Exception no car with this plate number or already rented
*/
@RequestMapping(value = "/car/{plateNumber}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public CarDTO getCar(@PathVariable("plateNumber") String plateNumber) throws Exception;
/**
* Rent a car.
* @param plateNumber
* @return car specifications
* @throws Exception no car with this plate number or already rented
*/
@RequestMapping(value = "/car/{plateNumber}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
public void rentCar(@PathVariable("plateNumber") String plateNumber) throws Exception;
/**
* Get back a rented car.
* @param plateNumber
* @return actions to be done
* @throws Exception no car with this plate number or not rented
*/
@RequestMapping(value = "/car/{plateNumber}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
public void renderCar(@PathVariable("plateNumber") String plateNumber) throws Exception;
}
Get the application core on Github
The core of the application is on github at:
https://github.com/charroux/GradleSpringRestBasis
Download the entire project as zip file and uncompress it on your machine.
The project is a Gradle project (http://www.gradle.org/).
Gradle installation (if necessary)
Download gradle: http://www.gradle.org/downloads (binary version is enough).
Uncompress the file.
Set two environment variables:
If used under windows, without administrator rights, you can set a variable in a command window
with:
set GRADLE_HOME …
Don’t close the window to keep the variables set.
Add GRADLE_HOMEbin to the variable path to use gradle from anywhere on your machine.
Using Gradle
To convert the project into an Eclipse project: gradle eclipse
To build all the project: gradle build
To launch the embedded web server jetty : gradle jettyRunWar
Using Eclipse to edit the source files
Download and uncompress the Apache/Tomcat web server (version binary 7.x)
http://tomcat.apache.org/
Add a Server Runtime to Eclipse: Windows –> Preferences -> Server -> Runtime environments -> Add
Import the project into Eclipse: File -> import –> General -> Existing project into workspace
Server web launching: write clic on the project -> Run as -> Run on server
Study of the application
Imported under Eclipse (don’t forget to use the Gradle commands first), the project looks like this:
The file build.gradle is a configuration file for Gradle. It indicates which libraries are necessary:
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.hateoas:spring-hateoas:0.9.0.RELEASE'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.12'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
providedCompile 'org.apache.tomcat:tomcat-catalina:7.0.47'
testCompile group: 'junit', name: 'junit', version: '4.5'
}
It also declares witch plug-in can be used: eclipse, jetty…
The package model contains the data structure: here a unique class defining a car for renting.
The package services contains a cars container named CarManager: it allows to get a list of cars.
The package dto (for Data Transfert Object) contains a class declaring data to be sent through the
network: a java object will be converted into JSon object.
Finally, the package web contains the java interface RentService defining the functionalities and the
class to be coded.
The web part of the application is in the src folder:
It contains two configuration files:
- web.xml (Java standard for web application)
- do-servlet.xml defining the configuration of the Spring framework
Mainly do-servlet.xml declares the Spring controller implementing the RentService interface, and a
converter from Java to JSon (or vice versa):
<bean id="siteController" class="web.MyRentController"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonConverter" />
</list>
</property>
</bean>
<bean id="jsonConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json" />
</bean>
Questions to answer before starting coding
What is a HATEOAS?
Explain the pattern TDO? What is this pattern for?
How the Web Service can serve JSon form Java?
Look at the file web.xml. What are the following instructions for?
<servlet-
mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>
How the Web Service can serve JSon form Java ?
Rest controller coding
Implement the RentService interface into the Spring Controller MyRentController.
Test your code by requesting the following URI:
Or choose a car by its plate number:
Java client project
The core of the application is on github at:
https://github.com/charroux/GradleSpringRestClientBasis
Download the entire project as zip file and uncompress it on your machine.
The project is a Gradle project.
To convert the project into an Eclipse project: gradle eclipse
To build all the project: gradle build
The project should appear has follow:
Check if the URI of the web service is the right one in the file Client.java (it depends on the project
name at the server side).
Launch this file. Explain what’s happen.
Questions to answer before to continue
What is the class org.springframework.web.client.RestTemplate for?
Is it possible to choose which Java attributes are sent in JSon?
Client coding coding
Modify the Java client in order to send HTTP put, post and delete requests.
Web client coding (advanced users)
Using Java Script and JQuery, create a web interface for car renting:

Mais conteúdo relacionado

Mais procurados

Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Yakov Fain
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developersYakov Fain
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in AngularYakov Fain
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...Katy Slemon
 
ASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateMindfire Solutions
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVCRichard Paul
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVCGuy Nir
 
React native app with type script tutorial
React native app with type script tutorialReact native app with type script tutorial
React native app with type script tutorialKaty Slemon
 
RESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoTRESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoTYakov Fain
 
Angular js 2
Angular js 2Angular js 2
Angular js 2Ran Wahle
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework Yakov Fain
 
Java web application development
Java web application developmentJava web application development
Java web application developmentRitikRathaur
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC AnnotationsJordan Silva
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Hsuan Fu Lien
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with SpringJoshua Long
 

Mais procurados (20)

Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2Reactive Thinking in Java with RxJava2
Reactive Thinking in Java with RxJava2
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
SpringMVC
SpringMVCSpringMVC
SpringMVC
 
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
 
Intro react js
Intro react jsIntro react js
Intro react js
 
ASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewStateASP.NET Page life cycle and ViewState
ASP.NET Page life cycle and ViewState
 
React outbox
React outboxReact outbox
React outbox
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
React native app with type script tutorial
React native app with type script tutorialReact native app with type script tutorial
React native app with type script tutorial
 
RESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoTRESTful services and OAUTH protocol in IoT
RESTful services and OAUTH protocol in IoT
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
Java web application development
Java web application developmentJava web application development
Java web application development
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC Annotations
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 

Semelhante a Rest web service_with_spring_hateoas

Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular applicationmirrec
 
Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample ChapterSyed Shahul
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technologyMinal Maniar
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...OdessaJS Conf
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Steven Smith
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containersJosé Moreira
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Lou Sacco
 
Workshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSVisual Engineering
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applicationsAstrails
 
How to implement multiple layouts using React router V4.pptx
How to implement multiple layouts using React router V4.pptxHow to implement multiple layouts using React router V4.pptx
How to implement multiple layouts using React router V4.pptxBOSC Tech Labs
 

Semelhante a Rest web service_with_spring_hateoas (20)

Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample Chapter
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
 
Spring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
 
Love at first Vue
Love at first VueLove at first Vue
Love at first Vue
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
React loadable
React loadableReact loadable
React loadable
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containers
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014
 
Jdbc
JdbcJdbc
Jdbc
 
Workshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJS
 
Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
 
ReactJS
ReactJSReactJS
ReactJS
 
How to implement multiple layouts using React router V4.pptx
How to implement multiple layouts using React router V4.pptxHow to implement multiple layouts using React router V4.pptx
How to implement multiple layouts using React router V4.pptx
 

Último

How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 

Último (20)

Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 

Rest web service_with_spring_hateoas

  • 1. Rest Web Service with Spring The goal of this lab work is to develop a small application for cars renting. The functionalities to implements are: - Get a list of unrented cars - Rent a car - Get back a car Those functionalities are defined by the following interface: package web; import java.util.List; import org.springframework.hateoas.ResourceSupport; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import dto.CarDTO; public interface RentService { @RequestMapping(value = "/entryPoint", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ResponseBody public ResourceSupport get(); /** * * @return all cars not rented */ @RequestMapping(value = "/car", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ResponseBody public List<CarDTO> getCars(); /** * Return specifications of a car. * @param plateNumber * @return car specifications only (if not rented) * @throws Exception no car with this plate number or already rented */ @RequestMapping(value = "/car/{plateNumber}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ResponseBody public CarDTO getCar(@PathVariable("plateNumber") String plateNumber) throws Exception; /** * Rent a car. * @param plateNumber * @return car specifications * @throws Exception no car with this plate number or already rented */ @RequestMapping(value = "/car/{plateNumber}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) public void rentCar(@PathVariable("plateNumber") String plateNumber) throws Exception; /** * Get back a rented car. * @param plateNumber
  • 2. * @return actions to be done * @throws Exception no car with this plate number or not rented */ @RequestMapping(value = "/car/{plateNumber}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.OK) public void renderCar(@PathVariable("plateNumber") String plateNumber) throws Exception; } Get the application core on Github The core of the application is on github at: https://github.com/charroux/GradleSpringRestBasis Download the entire project as zip file and uncompress it on your machine. The project is a Gradle project (http://www.gradle.org/). Gradle installation (if necessary) Download gradle: http://www.gradle.org/downloads (binary version is enough). Uncompress the file. Set two environment variables: If used under windows, without administrator rights, you can set a variable in a command window with: set GRADLE_HOME … Don’t close the window to keep the variables set. Add GRADLE_HOMEbin to the variable path to use gradle from anywhere on your machine. Using Gradle To convert the project into an Eclipse project: gradle eclipse To build all the project: gradle build To launch the embedded web server jetty : gradle jettyRunWar Using Eclipse to edit the source files Download and uncompress the Apache/Tomcat web server (version binary 7.x) http://tomcat.apache.org/
  • 3. Add a Server Runtime to Eclipse: Windows –> Preferences -> Server -> Runtime environments -> Add Import the project into Eclipse: File -> import –> General -> Existing project into workspace Server web launching: write clic on the project -> Run as -> Run on server Study of the application Imported under Eclipse (don’t forget to use the Gradle commands first), the project looks like this: The file build.gradle is a configuration file for Gradle. It indicates which libraries are necessary: apply plugin: 'war' apply plugin: 'jetty' apply plugin: 'eclipse' apply plugin: 'eclipse-wtp' repositories { mavenCentral() } dependencies { compile 'org.springframework.hateoas:spring-hateoas:0.9.0.RELEASE' compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.12' compile group: 'log4j', name: 'log4j', version: '1.2.17' providedCompile 'org.apache.tomcat:tomcat-catalina:7.0.47'
  • 4. testCompile group: 'junit', name: 'junit', version: '4.5' } It also declares witch plug-in can be used: eclipse, jetty… The package model contains the data structure: here a unique class defining a car for renting. The package services contains a cars container named CarManager: it allows to get a list of cars. The package dto (for Data Transfert Object) contains a class declaring data to be sent through the network: a java object will be converted into JSon object. Finally, the package web contains the java interface RentService defining the functionalities and the class to be coded. The web part of the application is in the src folder: It contains two configuration files: - web.xml (Java standard for web application) - do-servlet.xml defining the configuration of the Spring framework Mainly do-servlet.xml declares the Spring controller implementing the RentService interface, and a converter from Java to JSon (or vice versa): <bean id="siteController" class="web.MyRentController"></bean> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="jsonConverter" /> </list> </property> </bean> <bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
  • 5. <property name="supportedMediaTypes" value="application/json" /> </bean> Questions to answer before starting coding What is a HATEOAS? Explain the pattern TDO? What is this pattern for? How the Web Service can serve JSon form Java? Look at the file web.xml. What are the following instructions for? <servlet- mapping> <servlet-name>default</servlet-name> <url-pattern>/static/*</url-pattern> </servlet-mapping> How the Web Service can serve JSon form Java ? Rest controller coding Implement the RentService interface into the Spring Controller MyRentController. Test your code by requesting the following URI: Or choose a car by its plate number: Java client project The core of the application is on github at: https://github.com/charroux/GradleSpringRestClientBasis Download the entire project as zip file and uncompress it on your machine. The project is a Gradle project. To convert the project into an Eclipse project: gradle eclipse To build all the project: gradle build The project should appear has follow:
  • 6. Check if the URI of the web service is the right one in the file Client.java (it depends on the project name at the server side). Launch this file. Explain what’s happen. Questions to answer before to continue What is the class org.springframework.web.client.RestTemplate for? Is it possible to choose which Java attributes are sent in JSon? Client coding coding Modify the Java client in order to send HTTP put, post and delete requests. Web client coding (advanced users) Using Java Script and JQuery, create a web interface for car renting: