Skip to content

Commit d0d3fff

Browse files
committed
Merge pull request eugenp#1 from eugenp/master
Update from original
2 parents bc7240e + ac38b95 commit d0d3fff

493 files changed

Lines changed: 11216 additions & 1425 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
The "REST with Spring" Classes
33
==============================
4-
This is what I'm working on: <br/>
5-
**[>> THE REST WITH SPRING CLASSES](http://www.baeldung.com/rest-with-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=25off)**
4+
After 5 months of work, here's the Master Class: <br/>
5+
**[>> THE REST WITH SPRING MASTER CLASS](http://www.baeldung.com/rest-with-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=rws#master-class)**
66

77

88
Spring Tutorials

‎RestEasy Example/pom.xml‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>resteasy-tutorial</artifactId>
8+
<version>1.0</version>
9+
<packaging>war</packaging>
10+
11+
<properties>
12+
<resteasy.version>3.0.14.Final</resteasy.version>
13+
</properties>
14+
15+
<build>
16+
<finalName>RestEasyTutorial</finalName>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-compiler-plugin</artifactId>
21+
<configuration>
22+
<source>1.8</source>
23+
<target>1.8</target>
24+
</configuration>
25+
</plugin>
26+
</plugins>
27+
</build>
28+
29+
<dependencies>
30+
31+
<!-- core library -->
32+
33+
<dependency>
34+
<groupId>org.jboss.resteasy</groupId>
35+
<artifactId>resteasy-servlet-initializer</artifactId>
36+
<version>${resteasy.version}</version>
37+
</dependency>
38+
39+
40+
<dependency>
41+
<groupId>org.jboss.resteasy</groupId>
42+
<artifactId>resteasy-client</artifactId>
43+
<version>${resteasy.version}</version>
44+
</dependency>
45+
46+
<!-- Optional library -->
47+
48+
<dependency>
49+
<groupId>org.jboss.resteasy</groupId>
50+
<artifactId>resteasy-jaxb-provider</artifactId>
51+
<version>${resteasy.version}</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>org.jboss.resteasy</groupId>
56+
<artifactId>resteasy-jackson-provider</artifactId>
57+
<version>${resteasy.version}</version>
58+
</dependency>
59+
60+
<!-- Junit Library -->
61+
62+
<dependency>
63+
<groupId>junit</groupId>
64+
<artifactId>junit</artifactId>
65+
<version>4.4</version>
66+
</dependency>
67+
68+
<dependency>
69+
<groupId>commons-io</groupId>
70+
<artifactId>commons-io</artifactId>
71+
<version>2.4</version>
72+
</dependency>
73+
74+
</dependencies>
75+
76+
77+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.baeldung.client;
2+
3+
import com.baeldung.model.Movie;
4+
import javax.ws.rs.*;
5+
import javax.ws.rs.core.MediaType;
6+
import javax.ws.rs.core.Response;
7+
import java.util.List;
8+
9+
@Path("/movies")
10+
public interface ServicesInterface {
11+
12+
@GET
13+
@Path("/getinfo")
14+
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
15+
Movie movieByImdbId(@QueryParam("imdbId") String imdbId);
16+
17+
@GET
18+
@Path("/listmovies")
19+
@Produces({ "application/json" })
20+
List<Movie> listMovies();
21+
22+
@POST
23+
@Path("/addmovie")
24+
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
25+
Response addMovie(Movie movie);
26+
27+
@PUT
28+
@Path("/updatemovie")
29+
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
30+
Response updateMovie(Movie movie);
31+
32+
@DELETE
33+
@Path("/deletemovie")
34+
Response deleteMovie(@QueryParam("imdbId") String imdbID);
35+
36+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.baeldung.model;
2+
3+
import javax.xml.bind.annotation.XmlAccessType;
4+
import javax.xml.bind.annotation.XmlAccessorType;
5+
import javax.xml.bind.annotation.XmlType;
6+
7+
@XmlAccessorType(XmlAccessType.FIELD)
8+
@XmlType(name = "movie", propOrder = { "imdbId", "title" })
9+
public class Movie {
10+
11+
protected String imdbId;
12+
protected String title;
13+
14+
public Movie(String imdbId, String title) {
15+
this.imdbId = imdbId;
16+
this.title = title;
17+
}
18+
19+
public Movie() {}
20+
21+
public String getImdbId() {
22+
return imdbId;
23+
}
24+
25+
public void setImdbId(String imdbId) {
26+
this.imdbId = imdbId;
27+
}
28+
29+
public String getTitle() {
30+
return title;
31+
}
32+
33+
public void setTitle(String title) {
34+
this.title = title;
35+
}
36+
37+
@Override
38+
public boolean equals(Object o) {
39+
if (this == o)
40+
return true;
41+
if (o == null || getClass() != o.getClass())
42+
return false;
43+
44+
Movie movie = (Movie) o;
45+
46+
if (imdbId != null ? !imdbId.equals(movie.imdbId) : movie.imdbId != null)
47+
return false;
48+
return title != null ? title.equals(movie.title) : movie.title == null;
49+
50+
}
51+
52+
@Override
53+
public int hashCode() {
54+
int result = imdbId != null ? imdbId.hashCode() : 0;
55+
result = 31 * result + (title != null ? title.hashCode() : 0);
56+
return result;
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return "Movie{" +
62+
"imdbId='" + imdbId + '\'' +
63+
", title='" + title + '\'' +
64+
'}';
65+
}
66+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.baeldung.server;
2+
3+
import com.baeldung.model.Movie;
4+
import javax.ws.rs.*;
5+
import javax.ws.rs.core.MediaType;
6+
import javax.ws.rs.core.Response;
7+
import java.util.ArrayList;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
import java.util.Map;
11+
import java.util.stream.Collectors;
12+
13+
@Path("/movies")
14+
public class MovieCrudService {
15+
16+
private Map<String, Movie> inventory = new HashMap<String, Movie>();
17+
18+
@GET
19+
@Path("/getinfo")
20+
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
21+
public Movie movieByImdbId(@QueryParam("imdbId") String imdbId) {
22+
23+
System.out.println("*** Calling getinfo for a given ImdbID***");
24+
25+
if (inventory.containsKey(imdbId)) {
26+
return inventory.get(imdbId);
27+
} else
28+
return null;
29+
}
30+
31+
@POST
32+
@Path("/addmovie")
33+
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
34+
public Response addMovie(Movie movie) {
35+
36+
System.out.println("*** Calling addMovie ***");
37+
38+
if (null != inventory.get(movie.getImdbId())) {
39+
return Response.status(Response.Status.NOT_MODIFIED).entity("Movie is Already in the database.").build();
40+
}
41+
42+
inventory.put(movie.getImdbId(), movie);
43+
return Response.status(Response.Status.CREATED).build();
44+
}
45+
46+
@PUT
47+
@Path("/updatemovie")
48+
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
49+
public Response updateMovie(Movie movie) {
50+
51+
System.out.println("*** Calling updateMovie ***");
52+
53+
if (null == inventory.get(movie.getImdbId())) {
54+
return Response.status(Response.Status.NOT_MODIFIED).entity("Movie is not in the database.\nUnable to Update").build();
55+
}
56+
57+
inventory.put(movie.getImdbId(), movie);
58+
return Response.status(Response.Status.OK).build();
59+
}
60+
61+
@DELETE
62+
@Path("/deletemovie")
63+
public Response deleteMovie(@QueryParam("imdbId") String imdbId) {
64+
65+
System.out.println("*** Calling deleteMovie ***");
66+
67+
if (null == inventory.get(imdbId)) {
68+
return Response.status(Response.Status.NOT_FOUND).entity("Movie is not in the database.\nUnable to Delete").build();
69+
}
70+
71+
inventory.remove(imdbId);
72+
return Response.status(Response.Status.OK).build();
73+
}
74+
75+
@GET
76+
@Path("/listmovies")
77+
@Produces({ "application/json" })
78+
public List<Movie> listMovies() {
79+
80+
return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new));
81+
}
82+
83+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.server;
2+
3+
import javax.ws.rs.ApplicationPath;
4+
import javax.ws.rs.core.Application;
5+
import java.util.HashSet;
6+
import java.util.Map;
7+
import java.util.Set;
8+
9+
@ApplicationPath("/rest")
10+
public class RestEasyServices extends Application {
11+
12+
private Set<Object> singletons = new HashSet<Object>();
13+
14+
public RestEasyServices() {
15+
singletons.add(new MovieCrudService());
16+
}
17+
18+
@Override
19+
public Set<Object> getSingletons() {
20+
return singletons;
21+
}
22+
23+
@Override
24+
public Set<Class<?>> getClasses() {
25+
return super.getClasses();
26+
}
27+
28+
@Override
29+
public Map<String, Object> getProperties() {
30+
return super.getProperties();
31+
}
32+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<configuration scan="true" scanPeriod="10 seconds">
2+
3+
</configuration>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<jboss-deployment-structure>
3+
<deployment>
4+
<exclude-subsystems>
5+
<subsystem name="resteasy"/>
6+
</exclude-subsystems>
7+
<exclusions>
8+
<module name="javaee.api"/><module name="javax.ws.rs.api"/>
9+
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
10+
</exclusions>
11+
<local-last value="true"/>
12+
</deployment>
13+
</jboss-deployment-structure>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 4.2//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
3+
<jboss-web>
4+
</jboss-web>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
5+
6+
<display-name>RestEasy Example</display-name>
7+
8+
<context-param>
9+
<param-name>resteasy.servlet.mapping.prefix</param-name>
10+
<param-value>/rest</param-value>
11+
</context-param>
12+
13+
</web-app>

0 commit comments

Comments
 (0)