CleanUp Code
This commit is contained in:
parent
783dc6bdc2
commit
71793635d3
|
@ -36,7 +36,7 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- core library -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.resteasy</groupId>
|
<groupId>org.jboss.resteasy</groupId>
|
||||||
<artifactId>jaxrs-api</artifactId>
|
<artifactId>jaxrs-api</artifactId>
|
||||||
|
@ -101,5 +101,4 @@
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,7 +1,6 @@
|
||||||
package com.baeldung.client;
|
package com.baeldung.client;
|
||||||
|
|
||||||
import com.baeldung.model.Movie;
|
import com.baeldung.model.Movie;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
|
|
||||||
package com.baeldung.model;
|
package com.baeldung.model;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlType;
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
|
||||||
|
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
@XmlType(name = "movie", propOrder = {
|
@XmlType(name = "movie", propOrder = {
|
||||||
"actors",
|
"actors",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.baeldung.server;
|
package com.baeldung.server;
|
||||||
|
|
||||||
import com.baeldung.model.Movie;
|
import com.baeldung.model.Movie;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
@ -11,23 +10,21 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@Path("/movies")
|
@Path("/movies")
|
||||||
public class MovieCrudService {
|
public class MovieCrudService {
|
||||||
|
|
||||||
|
|
||||||
private Map<String,Movie> inventory = new HashMap<String, Movie>();
|
private Map<String,Movie> inventory = new HashMap<String, Movie>();
|
||||||
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/getinfo")
|
@Path("/getinfo")
|
||||||
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
|
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
|
||||||
public Movie movieByImdbID(@QueryParam("imdbId") String imdbID){
|
public Movie movieByImdbId(@QueryParam("imdbId") String imdbId){
|
||||||
|
|
||||||
System.out.println("*** Calling getinfo for a given ImdbID***");
|
System.out.println("*** Calling getinfo for a given ImdbID***");
|
||||||
|
|
||||||
if(inventory.containsKey(imdbID)){
|
if(inventory.containsKey(imdbId)){
|
||||||
return inventory.get(imdbID);
|
return inventory.get(imdbId);
|
||||||
}else return null;
|
}else return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,16 +67,16 @@ public class MovieCrudService {
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/deletemovie")
|
@Path("/deletemovie")
|
||||||
public Response deleteMovie(@QueryParam("imdbId") String imdbID){
|
public Response deleteMovie(@QueryParam("imdbId") String imdbId){
|
||||||
|
|
||||||
System.out.println("*** Calling deleteMovie ***");
|
System.out.println("*** Calling deleteMovie ***");
|
||||||
|
|
||||||
if (null==inventory.get(imdbID)){
|
if (null==inventory.get(imdbId)){
|
||||||
return Response.status(Response.Status.NOT_FOUND)
|
return Response.status(Response.Status.NOT_FOUND)
|
||||||
.entity("Movie is not in the database.\nUnable to Delete").build();
|
.entity("Movie is not in the database.\nUnable to Delete").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory.remove(imdbID);
|
inventory.remove(imdbId);
|
||||||
return Response.status(Response.Status.OK).build();
|
return Response.status(Response.Status.OK).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +90,4 @@ public class MovieCrudService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
package com.baeldung.server;
|
package com.baeldung.server;
|
||||||
|
|
||||||
|
|
||||||
import javax.ws.rs.ApplicationPath;
|
import javax.ws.rs.ApplicationPath;
|
||||||
import javax.ws.rs.core.Application;
|
import javax.ws.rs.core.Application;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Admin on 29/01/2016.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ApplicationPath("/rest")
|
@ApplicationPath("/rest")
|
||||||
public class RestEasyServices extends Application {
|
public class RestEasyServices extends Application {
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
||||||
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
||||||
|
|
||||||
<xs:complexType name="movie">
|
|
||||||
<xs:sequence>
|
|
||||||
<xs:element name="actors" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="awards" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="country" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="director" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="genre" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="imdbID" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="imdbRating" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="imdbVotes" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="language" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="metascore" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="plot" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="poster" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="rated" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="released" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="response" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="runtime" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="title" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="type" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="writer" type="xs:string" minOccurs="0"/>
|
|
||||||
<xs:element name="year" type="xs:string" minOccurs="0"/>
|
|
||||||
</xs:sequence>
|
|
||||||
</xs:complexType>
|
|
||||||
</xs:schema>
|
|
||||||
|
|
|
@ -5,12 +5,9 @@
|
||||||
|
|
||||||
<display-name>RestEasy Example</display-name>
|
<display-name>RestEasy Example</display-name>
|
||||||
|
|
||||||
<!-- needed only if you want prepend a relative path to your services -->
|
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>resteasy.servlet.mapping.prefix</param-name>
|
<param-name>resteasy.servlet.mapping.prefix</param-name>
|
||||||
<param-value>/rest</param-value>
|
<param-value>/rest</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
|
@ -1,7 +0,0 @@
|
||||||
package baeldung.client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Admin on 29/01/2016.
|
|
||||||
*/
|
|
||||||
public class RestEasyClient {
|
|
||||||
}
|
|
|
@ -10,7 +10,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
|
||||||
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
|
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
Loading…
Reference in New Issue