CleanUp and reformatting Code; dependency fix in pom.xml
This commit is contained in:
parent
31fbff34eb
commit
37acdef2a7
|
@ -1,104 +1,77 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>resteasy-tutorial</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>war</packaging>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>resteasy-tutorial</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jboss</id>
|
||||
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<resteasy.version>3.0.14.Final</resteasy.version>
|
||||
</properties>
|
||||
|
||||
<properties>
|
||||
<resteasy.version>3.0.14.Final</resteasy.version>
|
||||
<resteasy.scope>runtime</resteasy.scope>
|
||||
</properties>
|
||||
<build>
|
||||
<finalName>RestEasyTutorial</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<build>
|
||||
<finalName>RestEasyTutorial</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
|
||||
<dependencies>
|
||||
<!-- core library -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>jaxrs-api</artifactId>
|
||||
<version>3.0.12.Final</version>
|
||||
<scope>${resteasy.scope}</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-servlet-initializer</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
<scope>${resteasy.scope}</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
|
||||
<groupId>org.jboss.spec.javax.ws.rs</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-client</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
<scope>${resteasy.scope}</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-servlet-initializer</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-client</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jackson-provider</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
<scope>${resteasy.scope}</scope>
|
||||
</dependency>
|
||||
<!-- Optional library -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxb-provider</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
<scope>${resteasy.scope}</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jaxb-provider</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Junit Library -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-jackson-provider</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.4</version>
|
||||
</dependency>
|
||||
<!-- Junit Library -->
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -9,35 +9,28 @@ import java.util.List;
|
|||
@Path("/movies")
|
||||
public interface ServicesInterface {
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/getinfo")
|
||||
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
Movie movieByImdbId(@QueryParam("imdbId") String imdbId);
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/listmovies")
|
||||
@Produces({"application/json"})
|
||||
@Produces({ "application/json" })
|
||||
List<Movie> listMovies();
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/addmovie")
|
||||
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
Response addMovie(Movie movie);
|
||||
|
||||
|
||||
@PUT
|
||||
@Path("/updatemovie")
|
||||
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
Response updateMovie(Movie movie);
|
||||
|
||||
|
||||
@DELETE
|
||||
@Path("/deletemovie")
|
||||
Response deleteMovie(@QueryParam("imdbId") String imdbID);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,28 +5,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
|||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "movie", propOrder = {
|
||||
"actors",
|
||||
"awards",
|
||||
"country",
|
||||
"director",
|
||||
"genre",
|
||||
"imdbId",
|
||||
"imdbRating",
|
||||
"imdbVotes",
|
||||
"language",
|
||||
"metascore",
|
||||
"plot",
|
||||
"poster",
|
||||
"rated",
|
||||
"released",
|
||||
"response",
|
||||
"runtime",
|
||||
"title",
|
||||
"type",
|
||||
"writer",
|
||||
"year"
|
||||
})
|
||||
@XmlType(name = "movie", propOrder = { "actors", "awards", "country", "director", "genre", "imdbId", "imdbRating", "imdbVotes", "language", "metascore", "plot", "poster", "rated", "released", "response", "runtime", "title", "type", "writer", "year" })
|
||||
public class Movie {
|
||||
|
||||
protected String actors;
|
||||
|
@ -213,37 +192,22 @@ public class Movie {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Movie{" +
|
||||
"actors='" + actors + '\'' +
|
||||
", awards='" + awards + '\'' +
|
||||
", country='" + country + '\'' +
|
||||
", director='" + director + '\'' +
|
||||
", genre='" + genre + '\'' +
|
||||
", imdbId='" + imdbId + '\'' +
|
||||
", imdbRating='" + imdbRating + '\'' +
|
||||
", imdbVotes='" + imdbVotes + '\'' +
|
||||
", language='" + language + '\'' +
|
||||
", metascore='" + metascore + '\'' +
|
||||
", poster='" + poster + '\'' +
|
||||
", rated='" + rated + '\'' +
|
||||
", released='" + released + '\'' +
|
||||
", response='" + response + '\'' +
|
||||
", runtime='" + runtime + '\'' +
|
||||
", title='" + title + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", writer='" + writer + '\'' +
|
||||
", year='" + year + '\'' +
|
||||
'}';
|
||||
return "Movie{" + "actors='" + actors + '\'' + ", awards='" + awards + '\'' + ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + ", imdbId='" + imdbId + '\'' + ", imdbRating='" + imdbRating + '\''
|
||||
+ ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + ", metascore='" + metascore + '\'' + ", poster='" + poster + '\'' + ", rated='" + rated + '\'' + ", released='" + released + '\'' + ", response='" + response + '\''
|
||||
+ ", runtime='" + runtime + '\'' + ", title='" + title + '\'' + ", type='" + type + '\'' + ", writer='" + writer + '\'' + ", year='" + year + '\'' + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
Movie movie = (Movie) o;
|
||||
|
||||
if (imdbId != null ? !imdbId.equals(movie.imdbId) : movie.imdbId != null) return false;
|
||||
if (imdbId != null ? !imdbId.equals(movie.imdbId) : movie.imdbId != null)
|
||||
return false;
|
||||
return title != null ? title.equals(movie.title) : movie.title == null;
|
||||
|
||||
}
|
||||
|
|
|
@ -13,78 +13,71 @@ import java.util.stream.Collectors;
|
|||
@Path("/movies")
|
||||
public class MovieCrudService {
|
||||
|
||||
private Map<String,Movie> inventory = new HashMap<String, Movie>();
|
||||
|
||||
private Map<String, Movie> inventory = new HashMap<String, Movie>();
|
||||
|
||||
@GET
|
||||
@Path("/getinfo")
|
||||
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
|
||||
public Movie movieByImdbId(@QueryParam("imdbId") String imdbId){
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Movie movieByImdbId(@QueryParam("imdbId") String imdbId) {
|
||||
|
||||
System.out.println("*** Calling getinfo for a given ImdbID***");
|
||||
|
||||
if(inventory.containsKey(imdbId)){
|
||||
if (inventory.containsKey(imdbId)) {
|
||||
return inventory.get(imdbId);
|
||||
}else return null;
|
||||
} else
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/addmovie")
|
||||
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
|
||||
public Response addMovie(Movie movie){
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Response addMovie(Movie movie) {
|
||||
|
||||
System.out.println("*** Calling addMovie ***");
|
||||
|
||||
if (null!=inventory.get(movie.getImdbId())){
|
||||
return Response.status(Response.Status.NOT_MODIFIED)
|
||||
.entity("Movie is Already in the database.").build();
|
||||
if (null != inventory.get(movie.getImdbId())) {
|
||||
return Response.status(Response.Status.NOT_MODIFIED).entity("Movie is Already in the database.").build();
|
||||
}
|
||||
|
||||
inventory.put(movie.getImdbId(),movie);
|
||||
inventory.put(movie.getImdbId(), movie);
|
||||
|
||||
return Response.status(Response.Status.CREATED).build();
|
||||
}
|
||||
|
||||
|
||||
@PUT
|
||||
@Path("/updatemovie")
|
||||
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
|
||||
public Response updateMovie(Movie movie){
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Response updateMovie(Movie movie) {
|
||||
|
||||
System.out.println("*** Calling updateMovie ***");
|
||||
|
||||
if (null==inventory.get(movie.getImdbId())){
|
||||
return Response.status(Response.Status.NOT_MODIFIED)
|
||||
.entity("Movie is not in the database.\nUnable to Update").build();
|
||||
if (null == inventory.get(movie.getImdbId())) {
|
||||
return Response.status(Response.Status.NOT_MODIFIED).entity("Movie is not in the database.\nUnable to Update").build();
|
||||
}
|
||||
inventory.put(movie.getImdbId(),movie);
|
||||
inventory.put(movie.getImdbId(), movie);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@DELETE
|
||||
@Path("/deletemovie")
|
||||
public Response deleteMovie(@QueryParam("imdbId") String imdbId){
|
||||
public Response deleteMovie(@QueryParam("imdbId") String imdbId) {
|
||||
|
||||
System.out.println("*** Calling deleteMovie ***");
|
||||
|
||||
if (null==inventory.get(imdbId)){
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.entity("Movie is not in the database.\nUnable to Delete").build();
|
||||
if (null == inventory.get(imdbId)) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Movie is not in the database.\nUnable to Delete").build();
|
||||
}
|
||||
|
||||
inventory.remove(imdbId);
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/listmovies")
|
||||
@Produces({"application/json"})
|
||||
public List<Movie> listMovies(){
|
||||
@Produces({ "application/json" })
|
||||
public List<Movie> listMovies() {
|
||||
|
||||
return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<jboss-deployment-structure>
|
||||
<deployment>
|
||||
<exclude-subsystems>
|
||||
<subsystem name="resteasy" />
|
||||
</exclude-subsystems>
|
||||
<deployment>
|
||||
<exclude-subsystems>
|
||||
<subsystem name="resteasy" />
|
||||
</exclude-subsystems>
|
||||
|
||||
<exclusions>
|
||||
<module name="javaee.api" />
|
||||
<module name="javax.ws.rs.api"/>
|
||||
<module name="org.jboss.resteasy.resteasy-jaxrs" />
|
||||
</exclusions>
|
||||
<exclusions>
|
||||
<module name="javaee.api" />
|
||||
<module name="javax.ws.rs.api" />
|
||||
<module name="org.jboss.resteasy.resteasy-jaxrs" />
|
||||
</exclusions>
|
||||
|
||||
<local-last value="true" />
|
||||
</deployment>
|
||||
<local-last value="true" />
|
||||
</deployment>
|
||||
|
||||
</jboss-deployment-structure>
|
|
@ -1,13 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
|
||||
|
||||
<display-name>RestEasy Example</display-name>
|
||||
<display-name>RestEasy Example</display-name>
|
||||
|
||||
<context-param>
|
||||
<param-name>resteasy.servlet.mapping.prefix</param-name>
|
||||
<param-value>/rest</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>resteasy.servlet.mapping.prefix</param-name>
|
||||
<param-value>/rest</param-value>
|
||||
</context-param>
|
||||
|
||||
</web-app>
|
|
@ -21,14 +21,14 @@ import java.util.Locale;
|
|||
|
||||
public class RestEasyClientTest {
|
||||
|
||||
Movie transformerMovie=null;
|
||||
Movie batmanMovie=null;
|
||||
ObjectMapper jsonMapper=null;
|
||||
Movie transformerMovie = null;
|
||||
Movie batmanMovie = null;
|
||||
ObjectMapper jsonMapper = null;
|
||||
|
||||
@Before
|
||||
public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException {
|
||||
|
||||
jsonMapper=new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
jsonMapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
jsonMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
|
||||
jsonMapper.setDateFormat(sdf);
|
||||
|
@ -69,7 +69,7 @@ public class RestEasyClientTest {
|
|||
@Test
|
||||
public void testMovieByImdbId() {
|
||||
|
||||
String transformerImdbId="tt0418279";
|
||||
String transformerImdbId = "tt0418279";
|
||||
|
||||
ResteasyClient client = new ResteasyClientBuilder().build();
|
||||
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest"));
|
||||
|
@ -82,7 +82,6 @@ public class RestEasyClientTest {
|
|||
System.out.println(movies);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddMovie() {
|
||||
|
||||
|
@ -99,10 +98,9 @@ public class RestEasyClientTest {
|
|||
}
|
||||
|
||||
moviesResponse.close();
|
||||
System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
|
||||
System.out.println("Response Code: " + Response.Status.OK.getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteMovi1e() {
|
||||
|
||||
|
@ -116,14 +114,13 @@ public class RestEasyClientTest {
|
|||
|
||||
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
|
||||
System.out.println(moviesResponse.readEntity(String.class));
|
||||
throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus());
|
||||
throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus());
|
||||
}
|
||||
|
||||
moviesResponse.close();
|
||||
System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
|
||||
System.out.println("Response Code: " + Response.Status.OK.getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUpdateMovie() {
|
||||
|
||||
|
@ -137,11 +134,11 @@ public class RestEasyClientTest {
|
|||
moviesResponse = simple.updateMovie(batmanMovie);
|
||||
|
||||
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
|
||||
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
|
||||
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
|
||||
}
|
||||
|
||||
moviesResponse.close();
|
||||
System.out.println("Response Code: "+Response.Status.OK.getStatusCode());
|
||||
System.out.println("Response Code: " + Response.Status.OK.getStatusCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
"metascore": "66",
|
||||
"imdbRating": "7.6",
|
||||
"imdbVotes": "256,000",
|
||||
"imdbID": "tt0096895",
|
||||
"imdbId": "tt0096895",
|
||||
"type": "movie",
|
||||
"response": "True"
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
"metascore": "61",
|
||||
"imdbRating": "7.1",
|
||||
"imdbVotes": "492,225",
|
||||
"imdbID": "tt0418279",
|
||||
"imdbId": "tt0418279",
|
||||
"type": "movie",
|
||||
"response": "True"
|
||||
}
|
Loading…
Reference in New Issue