From c14e7ad1a17b34a60b74a4a4b63e8850567365d6 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sat, 30 Jan 2016 17:48:56 +0100 Subject: [PATCH 001/142] RestEasy Tutorial, CRUD Services example --- RestEasy Example/pom.xml | 91 +++ .../src/main/java/com/baeldung/Movie.java | 535 ++++++++++++++++++ .../baeldung/client/ServicesInterface.java | 44 ++ .../server/service/MovieCrudService.java | 94 +++ .../server/service/RestEasyServices.java | 40 ++ .../src/main/resources/schema1.xsd | 29 + .../main/webapp/WEB-INF/classes/logback.xml | 3 + .../WEB-INF/jboss-deployment-structure.xml | 16 + .../src/main/webapp/WEB-INF/jboss-web.xml | 4 + .../src/main/webapp/WEB-INF/web.xml | 51 ++ .../com/baeldung/server/RestEasyClient.java | 50 ++ .../resources/server/movies/transformer.json | 22 + 12 files changed, 979 insertions(+) create mode 100644 RestEasy Example/pom.xml create mode 100644 RestEasy Example/src/main/java/com/baeldung/Movie.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java create mode 100644 RestEasy Example/src/main/resources/schema1.xsd create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/web.xml create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/resources/server/movies/transformer.json diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml new file mode 100644 index 0000000000..b16c5e8267 --- /dev/null +++ b/RestEasy Example/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + com.baeldung + resteasy-tutorial + 1.0 + war + + + + jboss + http://repository.jboss.org/nexus/content/groups/public/ + + + + + 3.0.14.Final + runtime + + + + RestEasyTutorial + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + org.jboss.resteasy + jaxrs-api + 3.0.12.Final + ${resteasy.scope} + + + + org.jboss.resteasy + resteasy-servlet-initializer + ${resteasy.version} + ${resteasy.scope} + + + jboss-jaxrs-api_2.0_spec + org.jboss.spec.javax.ws.rs + + + + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + ${resteasy.scope} + + + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + + + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + ${resteasy.scope} + + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + ${resteasy.scope} + + + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/Movie.java new file mode 100644 index 0000000000..c0041d2e95 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/Movie.java @@ -0,0 +1,535 @@ + +package com.baeldung; + +import javax.xml.bind.annotation.XmlAccessType; +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" +}) +public class Movie { + + protected String actors; + protected String awards; + protected String country; + protected String director; + protected String genre; + protected String imdbID; + protected String imdbRating; + protected String imdbVotes; + protected String language; + protected String metascore; + protected String plot; + protected String poster; + protected String rated; + protected String released; + protected String response; + protected String runtime; + protected String title; + protected String type; + protected String writer; + protected String year; + + /** + * Recupera il valore della propriet� actors. + * + * @return + * possible object is + * {@link String } + * + */ + public String getActors() { + return actors; + } + + /** + * Imposta il valore della propriet� actors. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setActors(String value) { + this.actors = value; + } + + /** + * Recupera il valore della propriet� awards. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAwards() { + return awards; + } + + /** + * Imposta il valore della propriet� awards. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAwards(String value) { + this.awards = value; + } + + /** + * Recupera il valore della propriet� country. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCountry() { + return country; + } + + /** + * Imposta il valore della propriet� country. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCountry(String value) { + this.country = value; + } + + /** + * Recupera il valore della propriet� director. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDirector() { + return director; + } + + /** + * Imposta il valore della propriet� director. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDirector(String value) { + this.director = value; + } + + /** + * Recupera il valore della propriet� genre. + * + * @return + * possible object is + * {@link String } + * + */ + public String getGenre() { + return genre; + } + + /** + * Imposta il valore della propriet� genre. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setGenre(String value) { + this.genre = value; + } + + /** + * Recupera il valore della propriet� imdbID. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbID() { + return imdbID; + } + + /** + * Imposta il valore della propriet� imdbID. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbID(String value) { + this.imdbID = value; + } + + /** + * Recupera il valore della propriet� imdbRating. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbRating() { + return imdbRating; + } + + /** + * Imposta il valore della propriet� imdbRating. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbRating(String value) { + this.imdbRating = value; + } + + /** + * Recupera il valore della propriet� imdbVotes. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbVotes() { + return imdbVotes; + } + + /** + * Imposta il valore della propriet� imdbVotes. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbVotes(String value) { + this.imdbVotes = value; + } + + /** + * Recupera il valore della propriet� language. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLanguage() { + return language; + } + + /** + * Imposta il valore della propriet� language. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLanguage(String value) { + this.language = value; + } + + /** + * Recupera il valore della propriet� metascore. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMetascore() { + return metascore; + } + + /** + * Imposta il valore della propriet� metascore. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMetascore(String value) { + this.metascore = value; + } + + /** + * Recupera il valore della propriet� plot. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPlot() { + return plot; + } + + /** + * Imposta il valore della propriet� plot. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPlot(String value) { + this.plot = value; + } + + /** + * Recupera il valore della propriet� poster. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPoster() { + return poster; + } + + /** + * Imposta il valore della propriet� poster. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPoster(String value) { + this.poster = value; + } + + /** + * Recupera il valore della propriet� rated. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRated() { + return rated; + } + + /** + * Imposta il valore della propriet� rated. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRated(String value) { + this.rated = value; + } + + /** + * Recupera il valore della propriet� released. + * + * @return + * possible object is + * {@link String } + * + */ + public String getReleased() { + return released; + } + + /** + * Imposta il valore della propriet� released. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setReleased(String value) { + this.released = value; + } + + /** + * Recupera il valore della propriet� response. + * + * @return + * possible object is + * {@link String } + * + */ + public String getResponse() { + return response; + } + + /** + * Imposta il valore della propriet� response. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setResponse(String value) { + this.response = value; + } + + /** + * Recupera il valore della propriet� runtime. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRuntime() { + return runtime; + } + + /** + * Imposta il valore della propriet� runtime. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRuntime(String value) { + this.runtime = value; + } + + /** + * Recupera il valore della propriet� title. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Imposta il valore della propriet� title. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Recupera il valore della propriet� type. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Imposta il valore della propriet� type. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Recupera il valore della propriet� writer. + * + * @return + * possible object is + * {@link String } + * + */ + public String getWriter() { + return writer; + } + + /** + * Imposta il valore della propriet� writer. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setWriter(String value) { + this.writer = value; + } + + /** + * Recupera il valore della propriet� year. + * + * @return + * possible object is + * {@link String } + * + */ + public String getYear() { + return year; + } + + /** + * Imposta il valore della propriet� year. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setYear(String value) { + this.year = value; + } + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java new file mode 100644 index 0000000000..53e88961be --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -0,0 +1,44 @@ +package com.baeldung.client; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + + +public interface ServicesInterface { + + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + + + @POST + @Path("/addmovie") + @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Response addMovie(Movie movie); + + + @PUT + @Path("/updatemovie") + @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Response updateMovie(Movie movie); + + + @DELETE + @Path("/deletemovie") + Response deleteMovie(@QueryParam("imdbID") String imdbID); + + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java new file mode 100644 index 0000000000..d1973e7037 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java @@ -0,0 +1,94 @@ +package com.baeldung.server.service; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@Path("/movies") +public class MovieCrudService { + + + private Map inventory = new HashMap(); + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ + + System.out.println("*** Calling getinfo ***"); + + Movie movie=new Movie(); + movie.setImdbID(imdbID); + return movie; + } + + @POST + @Path("/addmovie") + @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(); + } + 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){ + + 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(); + } + inventory.put(movie.getImdbID(),movie); + return Response.status(Response.Status.OK).build(); + + } + + + @DELETE + @Path("/deletemovie") + 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(); + } + + inventory.remove(imdbID); + return Response.status(Response.Status.OK).build(); + } + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + public List listMovies(){ + + return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); + + } + + + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java new file mode 100644 index 0000000000..16b6200ad1 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java @@ -0,0 +1,40 @@ +package com.baeldung.server.service; + + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Created by Admin on 29/01/2016. + */ + + + +@ApplicationPath("/rest") +public class RestEasyServices extends Application { + + private Set singletons = new HashSet(); + + public RestEasyServices() { + singletons.add(new MovieCrudService()); + } + + @Override + public Set getSingletons() { + return singletons; + } + + @Override + public Set> getClasses() { + return super.getClasses(); + } + + @Override + public Map getProperties() { + return super.getProperties(); + } +} diff --git a/RestEasy Example/src/main/resources/schema1.xsd b/RestEasy Example/src/main/resources/schema1.xsd new file mode 100644 index 0000000000..0d74b7c366 --- /dev/null +++ b/RestEasy Example/src/main/resources/schema1.xsd @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml b/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml new file mode 100644 index 0000000000..d94e9f71ab --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000000..84d75934a7 --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000000..694bb71332 --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..c66d3b56ae --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,51 @@ + + + + RestEasy Example + + + + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap + + + + RestEasy Example + + + webAppRootKey + RestEasyExample + + + + + + resteasy.servlet.mapping.prefix + /rest + + + + + resteasy-servlet + + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher + + + javax.ws.rs.Application + com.baeldung.server.service.RestEasyServices + + + + + resteasy-servlet + /rest/* + + + + + index.html + + + + \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java new file mode 100644 index 0000000000..e711233979 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -0,0 +1,50 @@ +package com.baeldung.server; + +import com.baeldung.Movie; +import com.baeldung.client.ServicesInterface; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; + +import java.util.List; + +public class RestEasyClient { + + public static void main(String[] args) { + + Movie st = new Movie(); + st.setImdbID("12345"); + + /* + * Alternatively you can use this simple String to send + * instead of using a Student instance + * + * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; + */ + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + + ServicesInterface simple = target.proxy(ServicesInterface.class); + final List movies = simple.listMovies(); + + /* + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + + System.out.println("Server response : \n"); + System.out.println(response.readEntity(String.class)); + + response.close(); +*/ + } catch (Exception e) { + + e.printStackTrace(); + + } + } + +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/server/movies/transformer.json new file mode 100644 index 0000000000..2154868265 --- /dev/null +++ b/RestEasy Example/src/test/resources/server/movies/transformer.json @@ -0,0 +1,22 @@ +{ + "title": "Transformers", + "year": "2007", + "rated": "PG-13", + "released": "03 Jul 2007", + "runtime": "144 min", + "genre": "Action, Adventure, Sci-Fi", + "director": "Michael Bay", + "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", + "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", + "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", + "language": "English, Spanish", + "country": "USA", + "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", + "metascore": "61", + "imdbRating": "7.1", + "imdbVotes": "492,225", + "imdbID": "tt0418279", + "Type": "movie", + "response": "True" +} \ No newline at end of file From a85c9cbda573fc25ac4d0f133eaf6ed779611ad6 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sat, 30 Jan 2016 20:39:28 +0100 Subject: [PATCH 002/142] Added testCase for List All Movies and Add a Movie --- RestEasy Example/pom.xml | 29 +++++ .../baeldung/client/ServicesInterface.java | 6 +- .../java/com/baeldung/{ => model}/Movie.java | 45 +++++++- .../{service => }/MovieCrudService.java | 5 +- .../{service => }/RestEasyServices.java | 2 +- .../com/baeldung/server/RestEasyClient.java | 104 ++++++++++++++---- .../com/baeldung/server/movies/batman.json | 22 ++++ .../baeldung}/server/movies/transformer.json | 2 +- 8 files changed, 184 insertions(+), 31 deletions(-) rename RestEasy Example/src/main/java/com/baeldung/{ => model}/Movie.java (86%) rename RestEasy Example/src/main/java/com/baeldung/server/{service => }/MovieCrudService.java (96%) rename RestEasy Example/src/main/java/com/baeldung/server/{service => }/RestEasyServices.java (95%) create mode 100644 RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json rename RestEasy Example/src/test/resources/{ => com/baeldung}/server/movies/transformer.json (99%) diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index b16c5e8267..8dabfc863b 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -85,6 +85,35 @@ ${resteasy.scope} + + + + junit + junit + 4.4 + + + + commons-io + commons-io + 2.4 + + + + com.fasterxml.jackson.core + jackson-core + 2.7.0 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.7.0 + + + + + diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 53e88961be..2585c32438 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -1,15 +1,13 @@ package com.baeldung.client; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; - +@Path("/movies") public interface ServicesInterface { diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java similarity index 86% rename from RestEasy Example/src/main/java/com/baeldung/Movie.java rename to RestEasy Example/src/main/java/com/baeldung/model/Movie.java index c0041d2e95..052ba081c1 100644 --- a/RestEasy Example/src/main/java/com/baeldung/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -1,5 +1,5 @@ -package com.baeldung; +package com.baeldung.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -532,4 +532,47 @@ public class Movie { this.year = value; } + @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 + '\'' + + '}'; + } + + @Override + public boolean equals(Object o) { + 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; + return title != null ? title.equals(movie.title) : movie.title == null; + + } + + @Override + public int hashCode() { + int result = imdbID != null ? imdbID.hashCode() : 0; + result = 31 * result + (title != null ? title.hashCode() : 0); + return result; + } } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java similarity index 96% rename from RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java rename to RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index d1973e7037..60e0121966 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -1,11 +1,10 @@ -package com.baeldung.server.service; +package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java similarity index 95% rename from RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java rename to RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java index 16b6200ad1..8c57d2c9b4 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java @@ -1,4 +1,4 @@ -package com.baeldung.server.service; +package com.baeldung.server; import javax.ws.rs.ApplicationPath; diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java index e711233979..c77f494862 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -1,49 +1,111 @@ package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import javax.naming.NamingException; +import javax.ws.rs.core.Link; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.List; +import java.util.Locale; public class RestEasyClient { - public static void main(String[] args) { - Movie st = new Movie(); - st.setImdbID("12345"); + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; - /* - * Alternatively you can use this simple String to send - * instead of using a Student instance - * - * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; - */ + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + @Test + public void testListAllMovies() { try { ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ServicesInterface simple = target.proxy(ServicesInterface.class); - final List movies = simple.listMovies(); + final Response moviesResponse = simple.addMovie(batmanMovie); - /* - if (response.getStatus() != 200) { + if (moviesResponse.getStatus() != 201) { + System.out.println(moviesResponse.readEntity(String.class)); throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); + + moviesResponse.getStatus()); } - System.out.println("Server response : \n"); - System.out.println(response.readEntity(String.class)); + moviesResponse.close(); - response.close(); -*/ } catch (Exception e) { - e.printStackTrace(); - } } diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json new file mode 100644 index 0000000000..28061d5bf9 --- /dev/null +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json @@ -0,0 +1,22 @@ +{ + "title": "Batman", + "year": "1989", + "rated": "PG-13", + "released": "23 Jun 1989", + "runtime": "126 min", + "genre": "Action, Adventure", + "director": "Tim Burton", + "writer": "Bob Kane (Batman characters), Sam Hamm (story), Sam Hamm (screenplay), Warren Skaaren (screenplay)", + "actors": "Michael Keaton, Jack Nicholson, Kim Basinger, Robert Wuhl", + "plot": "The Dark Knight of Gotham City begins his war on crime with his first major enemy being the clownishly homicidal Joker.", + "language": "English, French", + "country": "USA, UK", + "awards": "Won 1 Oscar. Another 9 wins & 22 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTYwNjAyODIyMF5BMl5BanBnXkFtZTYwNDMwMDk2._V1_SX300.jpg", + "metascore": "66", + "imdbRating": "7.6", + "imdbVotes": "256,000", + "imdbID": "tt0096895", + "type": "movie", + "response": "True" +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json similarity index 99% rename from RestEasy Example/src/test/resources/server/movies/transformer.json rename to RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json index 2154868265..a3b033a8ba 100644 --- a/RestEasy Example/src/test/resources/server/movies/transformer.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json @@ -17,6 +17,6 @@ "imdbRating": "7.1", "imdbVotes": "492,225", "imdbID": "tt0418279", - "Type": "movie", + "type": "movie", "response": "True" } \ No newline at end of file From a2a026a503167a5e3a0fb2f3e8856686ce1428cc Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sun, 31 Jan 2016 11:05:11 +0100 Subject: [PATCH 003/142] Added testCase for all Services --- RestEasy Example/pom.xml | 15 -- .../baeldung/client/ServicesInterface.java | 10 +- .../com/baeldung/server/MovieCrudService.java | 15 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- .../com/baeldung/server/RestEasyClient.java | 112 ----------- .../baeldung/server/RestEasyClientTest.java | 189 ++++++++++++++++++ 6 files changed, 206 insertions(+), 137 deletions(-) delete mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 8dabfc863b..6935238d91 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -99,21 +99,6 @@ 2.4 - - com.fasterxml.jackson.core - jackson-core - 2.7.0 - - - - com.fasterxml.jackson.core - jackson-annotations - 2.7.0 - - - - - diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 2585c32438..7efed546d8 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -17,6 +17,12 @@ public interface ServicesInterface { Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -34,9 +40,5 @@ public interface ServicesInterface { Response deleteMovie(@QueryParam("imdbID") String imdbID); - @GET - @Path("/listmovies") - @Produces({"application/json"}) - List listMovies(); } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 60e0121966..18366e2faa 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -18,18 +18,21 @@ public class MovieCrudService { private Map inventory = new HashMap(); + @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ - System.out.println("*** Calling getinfo ***"); + System.out.println("*** Calling getinfo for a given ImdbID***"); + + if(inventory.containsKey(imdbID)){ + return inventory.get(imdbID); + }else return null; - Movie movie=new Movie(); - movie.setImdbID(imdbID); - return movie; } + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -41,6 +44,7 @@ public class MovieCrudService { return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is Already in the database.").build(); } + inventory.put(movie.getImdbID(),movie); return Response.status(Response.Status.CREATED).build(); @@ -54,7 +58,7 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + if (null==inventory.get(movie.getImdbID())){ return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is not in the database.\nUnable to Update").build(); } @@ -79,6 +83,7 @@ public class MovieCrudService { return Response.status(Response.Status.OK).build(); } + @GET @Path("/listmovies") @Produces({"application/json"}) diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index c66d3b56ae..ab3bc1aa83 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -33,7 +33,7 @@ javax.ws.rs.Application - com.baeldung.server.service.RestEasyServices + com.baeldung.server.RestEasyServices diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java deleted file mode 100644 index c77f494862..0000000000 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.baeldung.server; - -import com.baeldung.model.Movie; -import com.baeldung.client.ServicesInterface; -import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.naming.NamingException; -import javax.ws.rs.core.Link; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -public class RestEasyClient { - - - Movie transformerMovie=null; - Movie batmanMovie=null; - ObjectMapper jsonMapper=null; - - @BeforeClass - public static void loadMovieInventory(){ - - - - } - - @Before - public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - - - 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); - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { - String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { - String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); - - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - } - - @Test - public void testListAllMovies() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - - - @Test - public void testAddMovie() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - - ServicesInterface simple = target.proxy(ServicesInterface.class); - final Response moviesResponse = simple.addMovie(batmanMovie); - - if (moviesResponse.getStatus() != 201) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " - + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java new file mode 100644 index 0000000000..fb4205bcd7 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -0,0 +1,189 @@ +package com.baeldung.server; + +import com.baeldung.model.Movie; +import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.naming.NamingException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Locale; + +public class RestEasyClientTest { + + + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; + + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + + @Test + public void testListAllMovies() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testMovieByImdbID() { + + String transformerImdbId="tt0418279"; + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + + final Movie movies = simple.movieByImdbID(transformerImdbId); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(transformerMovie); + + if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { + //System.out.println(moviesResponse.readEntity(String.class)); + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testDeleteMovie() { + + String transformerImdbId="tt0418279"; + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.deleteMovie(transformerImdbId); + moviesResponse.close(); + + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println(moviesResponse.readEntity(String.class)); + throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testUpdateMovie() { + + try { + + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + batmanMovie.setImdbVotes("300,000"); + moviesResponse = simple.updateMovie(batmanMovie); + + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + //System.out.println(moviesResponse.readEntity(String.class)); + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file From 2fff2739690a712e5d87263c3f1c1c192f51ae9f Mon Sep 17 00:00:00 2001 From: oborkovskyi Date: Mon, 1 Feb 2016 16:12:47 +0200 Subject: [PATCH 004/142] Added guava19 test project --- guava19/pom.xml | 46 +++++++++ .../java/com/baeldung/guava/entity/User.java | 36 +++++++ .../com/baeldung/guava/CharMatcherTest.java | 33 +++++++ .../baeldung/guava/GuavaMiscUtilsTest.java | 95 +++++++++++++++++++ .../java/com/baeldung/guava/HashingTest.java | 34 +++++++ .../com/baeldung/guava/TypeTokenTest.java | 45 +++++++++ 6 files changed, 289 insertions(+) create mode 100644 guava19/pom.xml create mode 100644 guava19/src/main/java/com/baeldung/guava/entity/User.java create mode 100644 guava19/src/test/java/com/baeldung/guava/CharMatcherTest.java create mode 100644 guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java create mode 100644 guava19/src/test/java/com/baeldung/guava/HashingTest.java create mode 100644 guava19/src/test/java/com/baeldung/guava/TypeTokenTest.java diff --git a/guava19/pom.xml b/guava19/pom.xml new file mode 100644 index 0000000000..97c1b0ea4e --- /dev/null +++ b/guava19/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + com.baeldung + guava + 1.0-SNAPSHOT + + + + com.google.guava + guava + 19.0 + + + junit + junit + 4.12 + + + org.hamcrest + hamcrest-all + 1.3 + + + + + + maven-compiler-plugin + 3.3 + + true + true + 1.8 + 1.8 + UTF-8 + true + true + + + + + + \ No newline at end of file diff --git a/guava19/src/main/java/com/baeldung/guava/entity/User.java b/guava19/src/main/java/com/baeldung/guava/entity/User.java new file mode 100644 index 0000000000..be673edb10 --- /dev/null +++ b/guava19/src/main/java/com/baeldung/guava/entity/User.java @@ -0,0 +1,36 @@ +package com.baeldung.guava.entity; + +import com.google.common.base.MoreObjects; + +public class User{ + private long id; + private String name; + private int age; + + public User(long id, String name, int age) { + this.id = id; + this.name = name; + this.age = age; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(User.class) + .add("id", id) + .add("name", name) + .add("age", age) + .toString(); + } +} \ No newline at end of file diff --git a/guava19/src/test/java/com/baeldung/guava/CharMatcherTest.java b/guava19/src/test/java/com/baeldung/guava/CharMatcherTest.java new file mode 100644 index 0000000000..f890d9abc1 --- /dev/null +++ b/guava19/src/test/java/com/baeldung/guava/CharMatcherTest.java @@ -0,0 +1,33 @@ +package com.baeldung.guava; + +import com.google.common.base.CharMatcher; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class CharMatcherTest { + @Test + public void whenMatchingLetterOrString_ShouldReturnTrueForCorrectString() throws Exception { + String inputString = "someString789"; + boolean result = CharMatcher.javaLetterOrDigit().matchesAllOf(inputString); + + assertTrue(result); + } + + @Test + public void whenCollapsingString_ShouldReturnStringWithDashesInsteadOfWhitespaces() throws Exception { + String inputPhoneNumber = "8 123 456 123"; + String result = CharMatcher.whitespace().collapseFrom(inputPhoneNumber, '-'); + + assertEquals("8-123-456-123", result); + } + + @Test + public void whenCountingDigitsInString_ShouldReturnActualCountOfDigits() throws Exception { + String inputPhoneNumber = "8 123 456 123"; + int result = CharMatcher.digit().countIn(inputPhoneNumber); + + assertEquals(10, result); + } +} diff --git a/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java b/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java new file mode 100644 index 0000000000..4569019e60 --- /dev/null +++ b/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java @@ -0,0 +1,95 @@ +package com.baeldung.guava; + +import com.baeldung.guava.entity.User; +import com.google.common.base.CharMatcher; +import com.google.common.base.Throwables; +import com.google.common.collect.*; +import com.google.common.hash.HashCode; +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hashing; +import com.google.common.reflect.TypeToken; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; +import static org.hamcrest.core.AnyOf.anyOf; +import static org.junit.Assert.*; + +public class GuavaMiscUtilsTest { + + @Test + public void whenGettingLazyStackTrace_ListShouldBeReturned() throws Exception { + IllegalArgumentException e = new IllegalArgumentException("Some argument is incorrect"); + + List stackTraceElements = Throwables.lazyStackTrace(e); + + assertEquals(27, stackTraceElements.size()); + } + + @Test + public void multisetShouldCountHitsOfMultipleDuplicateObjects() throws Exception { + List userNames = Arrays.asList("David", "Eugene", "Alex", "Alex", "David", "David", "David"); + + Multiset userNamesMultiset = HashMultiset.create(userNames); + + assertEquals(7, userNamesMultiset.size()); + assertEquals(4, userNamesMultiset.count("David")); + assertEquals(2, userNamesMultiset.count("Alex")); + assertEquals(1, userNamesMultiset.count("Eugene")); + assertThat(userNamesMultiset.elementSet(), anyOf(containsInAnyOrder("Alex", "David", "Eugene"))); + } + + @Test + public void whenAddingNewConnectedRange_RangesShouldBeMerged() throws Exception { + RangeSet rangeSet = TreeRangeSet.create(); + + rangeSet.add(Range.closed(1, 10)); + rangeSet.add(Range.closed(5, 15)); + rangeSet.add(Range.closedOpen(10, 17)); + + assertTrue(rangeSet.encloses(Range.closedOpen(1, 17))); + assertTrue(rangeSet.encloses(Range.closed(2, 3))); + assertTrue(rangeSet.contains(15)); + assertFalse(rangeSet.contains(17)); + assertEquals(1, rangeSet.asDescendingSetOfRanges().size()); + } + + @Test + public void cartesianProductShouldReturnAllPossibleCombinations() throws Exception { + List first = Lists.newArrayList("value1", "value2"); + List second = Lists.newArrayList("value3", "value4"); + + List> cartesianProduct = Lists.cartesianProduct(first, second); + + List pair1 = Lists.newArrayList("value2", "value3"); + List pair2 = Lists.newArrayList("value2", "value4"); + List pair3 = Lists.newArrayList("value1", "value3"); + List pair4 = Lists.newArrayList("value1", "value4"); + + assertThat(cartesianProduct, anyOf(containsInAnyOrder(pair1, pair2, pair3, pair4))); + } + + @Test + public void multisetShouldRemoveOccurrencesOfSpecifiedObjects() throws Exception { + Multiset multisetToModify = HashMultiset.create(); + Multiset occurrencesToRemove = HashMultiset.create(); + + multisetToModify.add("John"); + multisetToModify.add("Max"); + multisetToModify.add("Alex"); + + occurrencesToRemove.add("Alex"); + occurrencesToRemove.add("John"); + + Multisets.removeOccurrences(multisetToModify, occurrencesToRemove); + + assertEquals(1, multisetToModify.size()); + assertTrue(multisetToModify.contains("Max")); + assertFalse(multisetToModify.contains("John")); + assertFalse(multisetToModify.contains("Alex")); + } +} \ No newline at end of file diff --git a/guava19/src/test/java/com/baeldung/guava/HashingTest.java b/guava19/src/test/java/com/baeldung/guava/HashingTest.java new file mode 100644 index 0000000000..9b4acde9f7 --- /dev/null +++ b/guava19/src/test/java/com/baeldung/guava/HashingTest.java @@ -0,0 +1,34 @@ +package com.baeldung.guava; + +import com.google.common.hash.HashCode; +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hashing; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class HashingTest { + @Test + public void whenHashingInSha384_hashFunctionShouldBeReturned() throws Exception { + int inputData = 15; + + HashFunction hashFunction = Hashing.sha384(); + HashCode hashCode = hashFunction.hashInt(inputData); + + assertEquals("0904b6277381dcfbdddd6b6c66e4e3e8f83d4690718d8e6f272c891f24773a12feaf8c449fa6e42240a621b2b5e3cda8", + hashCode.toString()); + } + + @Test + public void whenConcatenatingHashFunction_concatenatedHashShouldBeReturned() throws Exception { + int inputData = 15; + + HashFunction hashFunction = Hashing.concatenating(Hashing.crc32(), Hashing.crc32()); + HashFunction crc32Function = Hashing.crc32(); + + HashCode hashCode = hashFunction.hashInt(inputData); + HashCode crc32HashCode = crc32Function.hashInt(inputData); + + assertEquals(crc32HashCode.toString() + crc32HashCode.toString(), hashCode.toString()); + } +} diff --git a/guava19/src/test/java/com/baeldung/guava/TypeTokenTest.java b/guava19/src/test/java/com/baeldung/guava/TypeTokenTest.java new file mode 100644 index 0000000000..1923451f20 --- /dev/null +++ b/guava19/src/test/java/com/baeldung/guava/TypeTokenTest.java @@ -0,0 +1,45 @@ +package com.baeldung.guava; + +import com.google.common.reflect.TypeToken; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class TypeTokenTest { + @Test + public void whenCheckingIsAssignableFrom_shouldReturnTrueEvenIfGenericIsSpecified() throws Exception { + ArrayList stringList = new ArrayList<>(); + ArrayList intList = new ArrayList<>(); + boolean isAssignableFrom = stringList.getClass().isAssignableFrom(intList.getClass()); + + assertTrue(isAssignableFrom); + } + + @Test + public void whenCheckingIsSupertypeOf_shouldReturnFalseIfGenericIsSpecified() throws Exception { + TypeToken> listString = new TypeToken>() { + }; + TypeToken> integerString = new TypeToken>() { + }; + + boolean isSupertypeOf = listString.isSupertypeOf(integerString); + + assertFalse(isSupertypeOf); + } + + @Test + public void whenCheckingIsSubtypeOf_shouldReturnTrueIfClassIsExtendedFrom() throws Exception { + TypeToken> stringList = new TypeToken>() { + }; + TypeToken list = new TypeToken() { + }; + + boolean isSubtypeOf = stringList.isSubtypeOf(list); + + assertTrue(isSubtypeOf); + } +} From 032be8319e108f95f0d87d9f020a9f021186ef93 Mon Sep 17 00:00:00 2001 From: Dmitry Zinkevich Date: Thu, 14 Jan 2016 08:42:10 +0300 Subject: [PATCH 005/142] Add Elasticsearch Spring Data test cases --- spring-data-elasticsearch/.classpath | 31 +++++ spring-data-elasticsearch/.project | 29 ++++ spring-data-elasticsearch/README.md | 12 ++ spring-data-elasticsearch/pom.xml | 78 +++++++++++ .../main/java/com/baeldung/config/Config.java | 53 +++++++ .../com/baeldung/dao/ArticleRepository.java | 16 +++ .../main/java/com/baeldung/model/Article.java | 60 ++++++++ .../main/java/com/baeldung/model/Author.java | 28 ++++ .../com/baeldung/service/ArticleService.java | 15 ++ .../baeldung/service/ArticleServiceImpl.java | 54 ++++++++ .../src/main/resources/logback.xml | 20 +++ .../java/com/baeldung/ElasticSearchTest.java | 130 ++++++++++++++++++ 12 files changed, 526 insertions(+) create mode 100644 spring-data-elasticsearch/.classpath create mode 100644 spring-data-elasticsearch/.project create mode 100644 spring-data-elasticsearch/README.md create mode 100644 spring-data-elasticsearch/pom.xml create mode 100644 spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java create mode 100644 spring-data-elasticsearch/src/main/java/com/baeldung/dao/ArticleRepository.java create mode 100644 spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java create mode 100644 spring-data-elasticsearch/src/main/java/com/baeldung/model/Author.java create mode 100644 spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleService.java create mode 100644 spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java create mode 100644 spring-data-elasticsearch/src/main/resources/logback.xml create mode 100644 spring-data-elasticsearch/src/test/java/com/baeldung/ElasticSearchTest.java diff --git a/spring-data-elasticsearch/.classpath b/spring-data-elasticsearch/.classpath new file mode 100644 index 0000000000..698778fef3 --- /dev/null +++ b/spring-data-elasticsearch/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-data-elasticsearch/.project b/spring-data-elasticsearch/.project new file mode 100644 index 0000000000..09b9a781ed --- /dev/null +++ b/spring-data-elasticsearch/.project @@ -0,0 +1,29 @@ + + + spring-data-elasticsearch + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/spring-data-elasticsearch/README.md b/spring-data-elasticsearch/README.md new file mode 100644 index 0000000000..0dae92e0e7 --- /dev/null +++ b/spring-data-elasticsearch/README.md @@ -0,0 +1,12 @@ +## Spring Data Elasticsearch + +### Build the Project with Tests Running +``` +mvn clean install +``` + +### Run Tests Directly +``` +mvn test +``` + diff --git a/spring-data-elasticsearch/pom.xml b/spring-data-elasticsearch/pom.xml new file mode 100644 index 0000000000..7ac6dd0fcf --- /dev/null +++ b/spring-data-elasticsearch/pom.xml @@ -0,0 +1,78 @@ + + 4.0.0 + + org.baeldung + spring-data-elasticsearch + 0.0.1-SNAPSHOT + jar + + spring-data-elasticsearch + + + UTF-8 + 1.3.2.RELEASE + 4.2.2.RELEASE + 4.11 + 1.7.12 + 1.1.3 + 1.3.2.RELEASE + + + + + org.springframework + spring-core + ${org.springframework.version} + + + junit + junit-dep + ${junit.version} + test + + + org.springframework + spring-test + ${org.springframework.version} + test + + + org.springframework.data + spring-data-elasticsearch + ${elasticsearch.version} + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + org.slf4j + jcl-over-slf4j + ${org.slf4j.version} + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + + + + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + + + diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java b/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java new file mode 100644 index 0000000000..eb65e38f65 --- /dev/null +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java @@ -0,0 +1,53 @@ +package com.baeldung.config; + +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.node.NodeBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.elasticsearch.core.ElasticsearchOperations; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +@Configuration +@EnableElasticsearchRepositories(basePackages = "com.baeldung.dao") +@ComponentScan(basePackages = {"com.baeldung.service"}) +public class Config { + + private static Logger logger = LoggerFactory.getLogger(Config.class); + + @Bean + public NodeBuilder nodeBuilder() { + return new NodeBuilder(); + } + + @Bean + public ElasticsearchOperations elasticsearchTemplate() { + + try { + Path tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "elasticsearch_data"); + + ImmutableSettings.Builder elasticsearchSettings = ImmutableSettings.settingsBuilder() + .put("http.enabled", "false") + .put("path.data", tmpDir.toAbsolutePath().toString()); + + logger.debug(tmpDir.toAbsolutePath().toString()); + + return new ElasticsearchTemplate(nodeBuilder() + .local(true) + .settings(elasticsearchSettings.build()) + .node() + .client()); + } catch (IOException ioex) { + logger.error("Cannot create temp dir", ioex); + throw new RuntimeException(); + } + } +} diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/dao/ArticleRepository.java b/spring-data-elasticsearch/src/main/java/com/baeldung/dao/ArticleRepository.java new file mode 100644 index 0000000000..6ed86eff9b --- /dev/null +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/dao/ArticleRepository.java @@ -0,0 +1,16 @@ +package com.baeldung.dao; + +import com.baeldung.model.Article; +import com.baeldung.model.Article; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.elasticsearch.annotations.Query; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface ArticleRepository extends ElasticsearchRepository { + + Page
findByAuthorsName(String name, Pageable pageable); + + @Query("{\"bool\": {\"must\": [{\"match\": {\"authors.name\": \"?0\"}}]}}") + Page
findByAuthorsNameUsingCustomQuery(String name, Pageable pageable); +} diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java b/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java new file mode 100644 index 0000000000..17580ca0db --- /dev/null +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java @@ -0,0 +1,60 @@ +package com.baeldung.model; + +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldIndex; +import org.springframework.data.elasticsearch.annotations.FieldType; + +import java.util.List; + +@Document(indexName = "article", type = "article") +public class Article { + + @Id + private String id; + @Field(type = FieldType.String, index = FieldIndex.not_analyzed) + private String title; + @Field(type = FieldType.Nested) + private List authors; + + public Article() { + } + + public Article(String title) { + this.title = title; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public List getAuthors() { + return authors; + } + + public void setAuthors(List authors) { + this.authors = authors; + } + + @Override + public String toString() { + return "Article{" + + "id='" + id + '\'' + + ", title='" + title + '\'' + + ", authors=" + authors + + '}'; + } +} diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/model/Author.java b/spring-data-elasticsearch/src/main/java/com/baeldung/model/Author.java new file mode 100644 index 0000000000..09239efbe5 --- /dev/null +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/model/Author.java @@ -0,0 +1,28 @@ +package com.baeldung.model; + +public class Author { + + private String name; + + public Author() { + } + + public Author(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Author{" + + "name='" + name + '\'' + + '}'; + } +} diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleService.java b/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleService.java new file mode 100644 index 0000000000..052e22c67d --- /dev/null +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleService.java @@ -0,0 +1,15 @@ +package com.baeldung.service; + +import com.baeldung.model.Article; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface ArticleService { + Article save(Article article); + Article findOne(String id); + Iterable
findAll(); + Page
findByAuthorName(String name, Pageable pageable); + Page
findByAuthorNameUsingCustomQuery(String name, Pageable pageable); + long count(); + void delete(Article article); +} diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java b/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java new file mode 100644 index 0000000000..4dc100ec22 --- /dev/null +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java @@ -0,0 +1,54 @@ +package com.baeldung.service; + +import com.baeldung.dao.ArticleRepository; +import com.baeldung.model.Article; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +@Service +public class ArticleServiceImpl implements ArticleService { + + private ArticleRepository articleRepository; + + @Autowired + public void setArticleRepository(ArticleRepository articleRepository) { + this.articleRepository = articleRepository; + } + + @Override + public Article save(Article article) { + return articleRepository.save(article); + } + + @Override + public Article findOne(String id) { + return articleRepository.findOne(id); + } + + @Override + public Iterable
findAll() { + return articleRepository.findAll(); + } + + @Override + public Page
findByAuthorName(String name, Pageable pageable) { + return articleRepository.findByAuthorsName(name, pageable); + } + + @Override + public Page
findByAuthorNameUsingCustomQuery(String name, Pageable pageable) { + return articleRepository.findByAuthorsNameUsingCustomQuery(name, pageable); + } + + @Override + public long count() { + return articleRepository.count(); + } + + @Override + public void delete(Article article) { + articleRepository.delete(article); + } +} diff --git a/spring-data-elasticsearch/src/main/resources/logback.xml b/spring-data-elasticsearch/src/main/resources/logback.xml new file mode 100644 index 0000000000..37a9e2edbf --- /dev/null +++ b/spring-data-elasticsearch/src/main/resources/logback.xml @@ -0,0 +1,20 @@ + + + + + elasticsearch - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/ElasticSearchTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/ElasticSearchTest.java new file mode 100644 index 0000000000..07248149c2 --- /dev/null +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/ElasticSearchTest.java @@ -0,0 +1,130 @@ +package com.baeldung; + +import com.baeldung.config.Config; +import com.baeldung.model.Article; +import com.baeldung.model.Author; +import com.baeldung.service.ArticleService; +import org.elasticsearch.index.query.QueryBuilder; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; +import org.springframework.data.elasticsearch.core.query.SearchQuery; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import java.util.List; + +import static java.util.Arrays.asList; +import static org.elasticsearch.index.query.FilterBuilders.regexpFilter; +import static org.elasticsearch.index.query.QueryBuilders.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {Config.class}, loader = AnnotationConfigContextLoader.class) +public class ElasticSearchTest { + + @Autowired + private ElasticsearchTemplate elasticsearchTemplate; + @Autowired + private ArticleService articleService; + + private final Author johnSmith = new Author("John Smith"); + private final Author johnDoe = new Author("John Doe"); + + @Before + public void before() { + elasticsearchTemplate.deleteIndex(Article.class); + elasticsearchTemplate.createIndex(Article.class); + + Article article = new Article("Spring Data Elasticsearch"); + article.setAuthors(asList(johnSmith, johnDoe)); + articleService.save(article); + + article = new Article("Search engines"); + article.setAuthors(asList(johnDoe)); + articleService.save(article); + + article = new Article("Second Article About Elasticsearch"); + article.setAuthors(asList(johnSmith)); + articleService.save(article); + } + + @Test + public void givenArticleService_whenSaveArticle_thenIdIsAssigned() { + List authors = asList( + new Author("John Smith"), johnDoe); + + Article article = new Article("Making Search Elastic"); + article.setAuthors(authors); + + article = articleService.save(article); + assertNotNull(article.getId()); + } + + @Test + public void givenPersistedArticles_whenSearchByAuthorsName_thenRightFound() { + + Page
articleByAuthorName = articleService.findByAuthorName(johnSmith.getName(), new PageRequest(0, 10)); + assertEquals(2L, articleByAuthorName.getTotalElements()); + } + + @Test + public void givenCustomQuery_whenSearchByAuthorsName_thenArticleIsFound() { + + Page
articleByAuthorName = articleService.findByAuthorNameUsingCustomQuery("John Smith", new PageRequest(0, 10)); + assertEquals(3L, articleByAuthorName.getTotalElements()); + } + + + @Test + public void givenPersistedArticles_whenUseRegexQuery_thenRightArticlesFound() { + + SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withFilter(regexpFilter("title", ".*data.*")) + .build(); + List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + + assertEquals(1, articles.size()); + } + + @Test + public void givenSavedDoc_whenTitleUpdated_thenCouldFindByUpdatedTitle() { + SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(fuzzyQuery("title", "serch")) + .build(); + List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + + assertEquals(1, articles.size()); + + Article article = articles.get(0); + final String newTitle = "Getting started with Search Engines"; + article.setTitle(newTitle); + articleService.save(article); + + assertEquals(newTitle, articleService.findOne(article.getId()).getTitle()); + } + + @Test + public void givenSavedDoc_whenDelete_thenRemovedFromIndex() { + + final String articleTitle = "Spring Data Elasticsearch"; + + SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")) + .build(); + List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(1, articles.size()); + final long count = articleService.count(); + + articleService.delete(articles.get(0)); + + assertEquals(count - 1, articleService.count()); + } +} From 68f33a231298f75ed4d73d86a879491b4a05e4a1 Mon Sep 17 00:00:00 2001 From: Dmitry Zinkevich Date: Thu, 4 Feb 2016 15:10:06 +0300 Subject: [PATCH 006/142] Change index name to 'blog' and rename package to 'repository' --- .../src/main/java/com/baeldung/config/Config.java | 2 +- .../src/main/java/com/baeldung/model/Article.java | 2 +- .../baeldung/repository/ArticleRepository.java | 15 +++++++++++++++ .../com/baeldung/service/ArticleServiceImpl.java | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 spring-data-elasticsearch/src/main/java/com/baeldung/repository/ArticleRepository.java diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java b/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java index eb65e38f65..a67ec64534 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java @@ -17,7 +17,7 @@ import java.nio.file.Path; import java.nio.file.Paths; @Configuration -@EnableElasticsearchRepositories(basePackages = "com.baeldung.dao") +@EnableElasticsearchRepositories(basePackages = "com.baeldung.repository") @ComponentScan(basePackages = {"com.baeldung.service"}) public class Config { diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java b/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java index 17580ca0db..dee1d0817e 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java @@ -8,7 +8,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType; import java.util.List; -@Document(indexName = "article", type = "article") +@Document(indexName = "blog", type = "article") public class Article { @Id diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/repository/ArticleRepository.java b/spring-data-elasticsearch/src/main/java/com/baeldung/repository/ArticleRepository.java new file mode 100644 index 0000000000..1cb74889c5 --- /dev/null +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/repository/ArticleRepository.java @@ -0,0 +1,15 @@ +package com.baeldung.repository; + +import com.baeldung.model.Article; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.elasticsearch.annotations.Query; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface ArticleRepository extends ElasticsearchRepository { + + Page
findByAuthorsName(String name, Pageable pageable); + + @Query("{\"bool\": {\"must\": [{\"match\": {\"authors.name\": \"?0\"}}]}}") + Page
findByAuthorsNameUsingCustomQuery(String name, Pageable pageable); +} diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java b/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java index 4dc100ec22..59feb2816c 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java @@ -1,6 +1,6 @@ package com.baeldung.service; -import com.baeldung.dao.ArticleRepository; +import com.baeldung.repository.ArticleRepository; import com.baeldung.model.Article; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; From 6ab868cef39ac442eba1421b38826aaf9f4b541e Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 6 Feb 2016 12:50:32 +0200 Subject: [PATCH 007/142] cleanup work --- ...pse.wst.jsdt.core.javascriptValidator.launch | 7 +++++++ spring-security-login-and-registration/.project | 17 ++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 spring-security-login-and-registration/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch diff --git a/spring-security-login-and-registration/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch b/spring-security-login-and-registration/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch new file mode 100644 index 0000000000..627021fb96 --- /dev/null +++ b/spring-security-login-and-registration/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/spring-security-login-and-registration/.project b/spring-security-login-and-registration/.project index 2c3e86ed06..4a27f224a4 100644 --- a/spring-security-login-and-registration/.project +++ b/spring-security-login-and-registration/.project @@ -6,8 +6,13 @@ - org.eclipse.wst.jsdt.core.javascriptValidator + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch + @@ -25,16 +30,6 @@ - - org.jboss.tools.jst.web.kb.kbbuilder - - - - - org.hibernate.eclipse.console.hibernateBuilder - - - org.eclipse.wst.validation.validationbuilder From 8506171908e954c3453a3050fce22963d09e127a Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 6 Feb 2016 21:09:04 +0200 Subject: [PATCH 008/142] removing unused file --- .../src/main/resources/webSecurityConfig.xml | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 spring-jpa/src/main/resources/webSecurityConfig.xml diff --git a/spring-jpa/src/main/resources/webSecurityConfig.xml b/spring-jpa/src/main/resources/webSecurityConfig.xml deleted file mode 100644 index 88af78dabc..0000000000 --- a/spring-jpa/src/main/resources/webSecurityConfig.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 2be93cd3216df16ced5143fb69e3056e628b80e0 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 6 Feb 2016 21:25:59 +0200 Subject: [PATCH 009/142] minimal cleanup in Eclipse --- .../org.hibernate.eclipse.console.hibernateBuilder.launch | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 spring-security-rest-full/.externalToolBuilders/org.hibernate.eclipse.console.hibernateBuilder.launch diff --git a/spring-security-rest-full/.externalToolBuilders/org.hibernate.eclipse.console.hibernateBuilder.launch b/spring-security-rest-full/.externalToolBuilders/org.hibernate.eclipse.console.hibernateBuilder.launch deleted file mode 100644 index 9bc0284d26..0000000000 --- a/spring-security-rest-full/.externalToolBuilders/org.hibernate.eclipse.console.hibernateBuilder.launch +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - From 8b7e761c00f4a1db8710e8f38a4fdf061fa489bb Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Sat, 6 Feb 2016 23:48:50 +0200 Subject: [PATCH 010/142] Update README.md --- spring-jpa/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-jpa/README.md b/spring-jpa/README.md index 11df42ac52..387e3c00eb 100644 --- a/spring-jpa/README.md +++ b/spring-jpa/README.md @@ -7,3 +7,4 @@ - [Spring 3 and JPA with Hibernate](http://www.baeldung.com/2011/12/13/the-persistence-layer-with-spring-3-1-and-jpa/) - [Transactions with Spring 3 and JPA](http://www.baeldung.com/2011/12/26/transaction-configuration-with-jpa-and-spring-3-1/) - [The DAO with JPA and Spring](http://www.baeldung.com/spring-dao-jpa) +- [JPA Pagination](http://www.baeldung.com/jpa-pagination) From f09bce94f9e670e48ad8b00030bb967ea2e5326b Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Sat, 6 Feb 2016 23:51:06 +0200 Subject: [PATCH 011/142] Update README.md --- spring-hibernate4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-hibernate4/README.md b/spring-hibernate4/README.md index 0d1ac1600e..96f8074165 100644 --- a/spring-hibernate4/README.md +++ b/spring-hibernate4/README.md @@ -5,6 +5,7 @@ ### Relevant Articles: - [Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring) - [The DAO with Spring 3 and Hibernate](http://www.baeldung.com/2011/12/02/the-persistence-layer-with-spring-3-1-and-hibernate/) +- [Hibernate Pagination](http://www.baeldung.com/hibernate-pagination) ### Quick Start From ab4b2d8a1a51f0c24e455f17f671c503fd4c1928 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Sat, 6 Feb 2016 23:52:34 +0200 Subject: [PATCH 012/142] Update README.md --- spring-jpa/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-jpa/README.md b/spring-jpa/README.md index 387e3c00eb..da55ca7b75 100644 --- a/spring-jpa/README.md +++ b/spring-jpa/README.md @@ -8,3 +8,4 @@ - [Transactions with Spring 3 and JPA](http://www.baeldung.com/2011/12/26/transaction-configuration-with-jpa-and-spring-3-1/) - [The DAO with JPA and Spring](http://www.baeldung.com/spring-dao-jpa) - [JPA Pagination](http://www.baeldung.com/jpa-pagination) +- [Sorting with JPA](http://www.baeldung.com/jpa-sort) From 1ba1bf2bc5056effb8d718f41885ff30075fd4e0 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sun, 7 Feb 2016 12:49:30 +0200 Subject: [PATCH 013/142] jackson skip conditionally --- .../jackson/dynamicIgnore/Address.java | 41 +++++++ .../jackson/dynamicIgnore/Hidable.java | 9 ++ .../dynamicIgnore/HidableSerializer.java | 29 +++++ .../jackson/dynamicIgnore/Person.java | 41 +++++++ .../test/JacksonDynamicIgnoreTest.java | 100 ++++++++++++++++++ 5 files changed, 220 insertions(+) create mode 100644 jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Address.java create mode 100644 jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Hidable.java create mode 100644 jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/HidableSerializer.java create mode 100644 jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Person.java create mode 100644 jackson/src/test/java/org/baeldung/jackson/test/JacksonDynamicIgnoreTest.java diff --git a/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Address.java b/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Address.java new file mode 100644 index 0000000000..41ea8e7be3 --- /dev/null +++ b/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Address.java @@ -0,0 +1,41 @@ +package org.baeldung.jackson.dynamicIgnore; + + +public class Address implements Hidable { + private String city; + private String country; + private boolean hidden; + + public Address(final String city, final String country, final boolean hidden) { + super(); + this.city = city; + this.country = country; + this.hidden = hidden; + } + + public String getCity() { + return city; + } + + public void setCity(final String city) { + this.city = city; + } + + public String getCountry() { + return country; + } + + public void setCountry(final String country) { + this.country = country; + } + + @Override + public boolean isHidden() { + return hidden; + } + + public void setHidden(final boolean hidden) { + this.hidden = hidden; + } + +} diff --git a/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Hidable.java b/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Hidable.java new file mode 100644 index 0000000000..9eaa0c9619 --- /dev/null +++ b/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Hidable.java @@ -0,0 +1,9 @@ +package org.baeldung.jackson.dynamicIgnore; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + + +@JsonIgnoreProperties("hidden") +public interface Hidable { + boolean isHidden(); +} diff --git a/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/HidableSerializer.java b/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/HidableSerializer.java new file mode 100644 index 0000000000..35bd8fd7f6 --- /dev/null +++ b/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/HidableSerializer.java @@ -0,0 +1,29 @@ +package org.baeldung.jackson.dynamicIgnore; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +public class HidableSerializer extends JsonSerializer { + + private JsonSerializer defaultSerializer; + + public HidableSerializer(final JsonSerializer serializer) { + defaultSerializer = serializer; + } + + @Override + public void serialize(final Hidable value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { + if (value.isHidden()) + return; + defaultSerializer.serialize(value, jgen, provider); + } + + @Override + public boolean isEmpty(final SerializerProvider provider, final Hidable value) { + return (value == null || value.isHidden()); + } +} diff --git a/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Person.java b/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Person.java new file mode 100644 index 0000000000..5fe294a5e1 --- /dev/null +++ b/jackson/src/test/java/org/baeldung/jackson/dynamicIgnore/Person.java @@ -0,0 +1,41 @@ +package org.baeldung.jackson.dynamicIgnore; + + +public class Person implements Hidable { + private String name; + private Address address; + private boolean hidden; + + public Person(final String name, final Address address, final boolean hidden) { + super(); + this.name = name; + this.address = address; + this.hidden = hidden; + } + + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public Address getAddress() { + return address; + } + + public void setAddress(final Address address) { + this.address = address; + } + @Override + public boolean isHidden() { + return hidden; + } + + public void setHidden(final boolean hidden) { + this.hidden = hidden; + } + +} diff --git a/jackson/src/test/java/org/baeldung/jackson/test/JacksonDynamicIgnoreTest.java b/jackson/src/test/java/org/baeldung/jackson/test/JacksonDynamicIgnoreTest.java new file mode 100644 index 0000000000..d98f948dec --- /dev/null +++ b/jackson/src/test/java/org/baeldung/jackson/test/JacksonDynamicIgnoreTest.java @@ -0,0 +1,100 @@ +package org.baeldung.jackson.test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.baeldung.jackson.dynamicIgnore.Address; +import org.baeldung.jackson.dynamicIgnore.Hidable; +import org.baeldung.jackson.dynamicIgnore.HidableSerializer; +import org.baeldung.jackson.dynamicIgnore.Person; +import org.junit.Before; +import org.junit.Test; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.BeanDescription; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationConfig; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.BeanSerializerModifier; + +public class JacksonDynamicIgnoreTest { + + private ObjectMapper mapper = new ObjectMapper(); + + @Before + public void setUp() { + mapper.setSerializationInclusion(Include.NON_EMPTY); + mapper.registerModule(new SimpleModule() { + @Override + public void setupModule(final SetupContext context) { + super.setupModule(context); + context.addBeanSerializerModifier(new BeanSerializerModifier() { + @Override + public JsonSerializer modifySerializer(final SerializationConfig config, final BeanDescription beanDesc, final JsonSerializer serializer) { + if (Hidable.class.isAssignableFrom(beanDesc.getBeanClass())) { + return new HidableSerializer((JsonSerializer) serializer); + } + return serializer; + } + }); + } + }); + } + + @Test + public void whenNotHidden_thenCorrect() throws JsonProcessingException { + final Address ad = new Address("ny", "usa", false); + final Person person = new Person("john", ad, false); + final String result = mapper.writeValueAsString(person); + + assertTrue(result.contains("name")); + assertTrue(result.contains("john")); + assertTrue(result.contains("address")); + assertTrue(result.contains("usa")); + + System.out.println("Not Hidden = " + result); + } + + @Test + public void whenAddressHidden_thenCorrect() throws JsonProcessingException { + final Address ad = new Address("ny", "usa", true); + final Person person = new Person("john", ad, false); + final String result = mapper.writeValueAsString(person); + + assertTrue(result.contains("name")); + assertTrue(result.contains("john")); + assertFalse(result.contains("address")); + assertFalse(result.contains("usa")); + + System.out.println("Address Hidden = " + result); + } + + @Test + public void whenAllHidden_thenCorrect() throws JsonProcessingException { + final Address ad = new Address("ny", "usa", false); + final Person person = new Person("john", ad, true); + final String result = mapper.writeValueAsString(person); + + assertTrue(result.length() == 0); + + System.out.println("All Hidden = " + result); + } + + @Test + public void whenSerializeList_thenCorrect() throws JsonProcessingException { + final Address ad1 = new Address("tokyo", "jp", true); + final Address ad2 = new Address("london", "uk", false); + final Address ad3 = new Address("ny", "usa", false); + final Person p1 = new Person("john", ad1, false); + final Person p2 = new Person("tom", ad2, true); + final Person p3 = new Person("adam", ad3, false); + + final String result = mapper.writeValueAsString(Arrays.asList(p1, p2, p3)); + + System.out.println(result); + } +} From 333e8793bd20d4faabce6733e635844d050f5a2a Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 7 Feb 2016 18:15:42 +0200 Subject: [PATCH 014/142] minor upgrade --- jackson/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jackson/pom.xml b/jackson/pom.xml index 9996330361..ed7a5944a5 100644 --- a/jackson/pom.xml +++ b/jackson/pom.xml @@ -140,7 +140,7 @@ 5.1.35 - 2.5.5 + 2.7.1-1 1.7.13 From 80b3e457f2eb16c2082381cf198c0be7c3b096a3 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:29:30 +0100 Subject: [PATCH 015/142] Minor Bugfix --- .../baeldung/client/ServicesInterface.java | 4 +- .../main/java/com/baeldung/model/Movie.java | 22 +-- .../com/baeldung/server/MovieCrudService.java | 12 +- .../src/main/webapp/WEB-INF/web.xml | 37 +---- .../java/baeldung/client/RestEasyClient.java | 7 + .../baeldung/server/RestEasyClientTest.java | 149 +++++++----------- 6 files changed, 81 insertions(+), 150 deletions(-) create mode 100644 RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 7efed546d8..749cabc757 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -14,7 +14,7 @@ public interface ServicesInterface { @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) - Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + Movie movieByImdbId(@QueryParam("imdbId") String imdbId); @GET @@ -37,7 +37,7 @@ public interface ServicesInterface { @DELETE @Path("/deletemovie") - Response deleteMovie(@QueryParam("imdbID") String imdbID); + Response deleteMovie(@QueryParam("imdbId") String imdbID); diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 052ba081c1..a2b2bd5250 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType; "country", "director", "genre", - "imdbID", + "imdbId", "imdbRating", "imdbVotes", "language", @@ -36,7 +36,7 @@ public class Movie { protected String country; protected String director; protected String genre; - protected String imdbID; + protected String imdbId; protected String imdbRating; protected String imdbVotes; protected String language; @@ -173,27 +173,27 @@ public class Movie { } /** - * Recupera il valore della propriet� imdbID. + * Recupera il valore della propriet� imdbId. * * @return * possible object is * {@link String } * */ - public String getImdbID() { - return imdbID; + public String getImdbId() { + return imdbId; } /** - * Imposta il valore della propriet� imdbID. + * Imposta il valore della propriet� imdbId. * * @param value * allowed object is * {@link String } * */ - public void setImdbID(String value) { - this.imdbID = value; + public void setImdbId(String value) { + this.imdbId = value; } /** @@ -540,7 +540,7 @@ public class Movie { ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + - ", imdbID='" + imdbID + '\'' + + ", imdbId='" + imdbId + '\'' + ", imdbRating='" + imdbRating + '\'' + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + @@ -564,14 +564,14 @@ public class Movie { 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; } @Override public int hashCode() { - int result = imdbID != null ? imdbID.hashCode() : 0; + int result = imdbId != null ? imdbId.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); return result; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 18366e2faa..29226aa0e0 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -22,7 +22,7 @@ public class MovieCrudService { @GET @Path("/getinfo") @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***"); @@ -40,12 +40,12 @@ public class MovieCrudService { System.out.println("*** Calling addMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + 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(); } @@ -58,11 +58,11 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null==inventory.get(movie.getImdbID())){ + 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(); } @@ -70,7 +70,7 @@ public class MovieCrudService { @DELETE @Path("/deletemovie") - public Response deleteMovie(@QueryParam("imdbID") String imdbID){ + public Response deleteMovie(@QueryParam("imdbId") String imdbID){ System.out.println("*** Calling deleteMovie ***"); diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index ab3bc1aa83..f70fdf7975 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -5,47 +5,12 @@ RestEasy Example - - - org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap - - - - RestEasy Example - - - webAppRootKey - RestEasyExample - - - - + resteasy.servlet.mapping.prefix /rest - - resteasy-servlet - - org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher - - - javax.ws.rs.Application - com.baeldung.server.RestEasyServices - - - - - resteasy-servlet - /rest/* - - - - - index.html - - \ No newline at end of file diff --git a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java new file mode 100644 index 0000000000..b474b3d4f8 --- /dev/null +++ b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java @@ -0,0 +1,7 @@ +package baeldung.client; + +/** + * Created by Admin on 29/01/2016. + */ +public class RestEasyClient { +} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index fb4205bcd7..b6a2e2a0c1 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -1,7 +1,7 @@ package com.baeldung.server; -import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import com.baeldung.model.Movie; import org.apache.commons.io.IOUtils; import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; @@ -9,7 +9,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import javax.naming.NamingException; @@ -23,22 +22,13 @@ import java.util.Locale; public class RestEasyClientTest { - Movie transformerMovie=null; Movie batmanMovie=null; ObjectMapper jsonMapper=null; - @BeforeClass - public static void loadMovieInventory(){ - - - - } - @Before public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - 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); @@ -57,133 +47,102 @@ public class RestEasyClientTest { batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException("Test is going to die ...", e); } - } - @Test public void testListAllMovies() { - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } + List movies = simple.listMovies(); + System.out.println(movies); } - @Test - public void testMovieByImdbID() { + public void testMovieByImdbId() { String transformerImdbId="tt0418279"; - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); - final Movie movies = simple.movieByImdbID(transformerImdbId); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } + Movie movies = simple.movieByImdbId(transformerImdbId); + System.out.println(movies); } @Test public void testAddMovie() { - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(transformerMovie); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(transformerMovie); - if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { - //System.out.println(moviesResponse.readEntity(String.class)); - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } @Test - public void testDeleteMovie() { + public void testDeleteMovi1e() { - String transformerImdbId="tt0418279"; + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.deleteMovie(batmanMovie.getImdbId()); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.deleteMovie(transformerImdbId); - moviesResponse.close(); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println(moviesResponse.readEntity(String.class)); + throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } @Test public void testUpdateMovie() { - try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + batmanMovie.setImdbVotes("300,000"); + moviesResponse = simple.updateMovie(batmanMovie); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - batmanMovie.setImdbVotes("300,000"); - moviesResponse = simple.updateMovie(batmanMovie); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - //System.out.println(moviesResponse.readEntity(String.class)); - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } } \ No newline at end of file From a0c22cc22514d0190d14d51e6bcc06ad5eed8836 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sat, 30 Jan 2016 17:48:56 +0100 Subject: [PATCH 016/142] RestEasy Tutorial, CRUD Services example --- RestEasy Example/pom.xml | 91 +++ .../src/main/java/com/baeldung/Movie.java | 535 ++++++++++++++++++ .../baeldung/client/ServicesInterface.java | 44 ++ .../server/service/MovieCrudService.java | 94 +++ .../server/service/RestEasyServices.java | 40 ++ .../src/main/resources/schema1.xsd | 29 + .../main/webapp/WEB-INF/classes/logback.xml | 3 + .../WEB-INF/jboss-deployment-structure.xml | 16 + .../src/main/webapp/WEB-INF/jboss-web.xml | 4 + .../src/main/webapp/WEB-INF/web.xml | 51 ++ .../com/baeldung/server/RestEasyClient.java | 50 ++ .../resources/server/movies/transformer.json | 22 + 12 files changed, 979 insertions(+) create mode 100644 RestEasy Example/pom.xml create mode 100644 RestEasy Example/src/main/java/com/baeldung/Movie.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java create mode 100644 RestEasy Example/src/main/resources/schema1.xsd create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/web.xml create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/resources/server/movies/transformer.json diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml new file mode 100644 index 0000000000..b16c5e8267 --- /dev/null +++ b/RestEasy Example/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + com.baeldung + resteasy-tutorial + 1.0 + war + + + + jboss + http://repository.jboss.org/nexus/content/groups/public/ + + + + + 3.0.14.Final + runtime + + + + RestEasyTutorial + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + org.jboss.resteasy + jaxrs-api + 3.0.12.Final + ${resteasy.scope} + + + + org.jboss.resteasy + resteasy-servlet-initializer + ${resteasy.version} + ${resteasy.scope} + + + jboss-jaxrs-api_2.0_spec + org.jboss.spec.javax.ws.rs + + + + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + ${resteasy.scope} + + + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + + + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + ${resteasy.scope} + + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + ${resteasy.scope} + + + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/Movie.java new file mode 100644 index 0000000000..c0041d2e95 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/Movie.java @@ -0,0 +1,535 @@ + +package com.baeldung; + +import javax.xml.bind.annotation.XmlAccessType; +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" +}) +public class Movie { + + protected String actors; + protected String awards; + protected String country; + protected String director; + protected String genre; + protected String imdbID; + protected String imdbRating; + protected String imdbVotes; + protected String language; + protected String metascore; + protected String plot; + protected String poster; + protected String rated; + protected String released; + protected String response; + protected String runtime; + protected String title; + protected String type; + protected String writer; + protected String year; + + /** + * Recupera il valore della propriet� actors. + * + * @return + * possible object is + * {@link String } + * + */ + public String getActors() { + return actors; + } + + /** + * Imposta il valore della propriet� actors. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setActors(String value) { + this.actors = value; + } + + /** + * Recupera il valore della propriet� awards. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAwards() { + return awards; + } + + /** + * Imposta il valore della propriet� awards. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAwards(String value) { + this.awards = value; + } + + /** + * Recupera il valore della propriet� country. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCountry() { + return country; + } + + /** + * Imposta il valore della propriet� country. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCountry(String value) { + this.country = value; + } + + /** + * Recupera il valore della propriet� director. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDirector() { + return director; + } + + /** + * Imposta il valore della propriet� director. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDirector(String value) { + this.director = value; + } + + /** + * Recupera il valore della propriet� genre. + * + * @return + * possible object is + * {@link String } + * + */ + public String getGenre() { + return genre; + } + + /** + * Imposta il valore della propriet� genre. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setGenre(String value) { + this.genre = value; + } + + /** + * Recupera il valore della propriet� imdbID. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbID() { + return imdbID; + } + + /** + * Imposta il valore della propriet� imdbID. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbID(String value) { + this.imdbID = value; + } + + /** + * Recupera il valore della propriet� imdbRating. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbRating() { + return imdbRating; + } + + /** + * Imposta il valore della propriet� imdbRating. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbRating(String value) { + this.imdbRating = value; + } + + /** + * Recupera il valore della propriet� imdbVotes. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbVotes() { + return imdbVotes; + } + + /** + * Imposta il valore della propriet� imdbVotes. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbVotes(String value) { + this.imdbVotes = value; + } + + /** + * Recupera il valore della propriet� language. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLanguage() { + return language; + } + + /** + * Imposta il valore della propriet� language. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLanguage(String value) { + this.language = value; + } + + /** + * Recupera il valore della propriet� metascore. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMetascore() { + return metascore; + } + + /** + * Imposta il valore della propriet� metascore. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMetascore(String value) { + this.metascore = value; + } + + /** + * Recupera il valore della propriet� plot. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPlot() { + return plot; + } + + /** + * Imposta il valore della propriet� plot. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPlot(String value) { + this.plot = value; + } + + /** + * Recupera il valore della propriet� poster. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPoster() { + return poster; + } + + /** + * Imposta il valore della propriet� poster. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPoster(String value) { + this.poster = value; + } + + /** + * Recupera il valore della propriet� rated. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRated() { + return rated; + } + + /** + * Imposta il valore della propriet� rated. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRated(String value) { + this.rated = value; + } + + /** + * Recupera il valore della propriet� released. + * + * @return + * possible object is + * {@link String } + * + */ + public String getReleased() { + return released; + } + + /** + * Imposta il valore della propriet� released. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setReleased(String value) { + this.released = value; + } + + /** + * Recupera il valore della propriet� response. + * + * @return + * possible object is + * {@link String } + * + */ + public String getResponse() { + return response; + } + + /** + * Imposta il valore della propriet� response. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setResponse(String value) { + this.response = value; + } + + /** + * Recupera il valore della propriet� runtime. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRuntime() { + return runtime; + } + + /** + * Imposta il valore della propriet� runtime. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRuntime(String value) { + this.runtime = value; + } + + /** + * Recupera il valore della propriet� title. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Imposta il valore della propriet� title. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Recupera il valore della propriet� type. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Imposta il valore della propriet� type. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Recupera il valore della propriet� writer. + * + * @return + * possible object is + * {@link String } + * + */ + public String getWriter() { + return writer; + } + + /** + * Imposta il valore della propriet� writer. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setWriter(String value) { + this.writer = value; + } + + /** + * Recupera il valore della propriet� year. + * + * @return + * possible object is + * {@link String } + * + */ + public String getYear() { + return year; + } + + /** + * Imposta il valore della propriet� year. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setYear(String value) { + this.year = value; + } + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java new file mode 100644 index 0000000000..53e88961be --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -0,0 +1,44 @@ +package com.baeldung.client; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + + +public interface ServicesInterface { + + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + + + @POST + @Path("/addmovie") + @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Response addMovie(Movie movie); + + + @PUT + @Path("/updatemovie") + @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Response updateMovie(Movie movie); + + + @DELETE + @Path("/deletemovie") + Response deleteMovie(@QueryParam("imdbID") String imdbID); + + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java new file mode 100644 index 0000000000..d1973e7037 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java @@ -0,0 +1,94 @@ +package com.baeldung.server.service; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@Path("/movies") +public class MovieCrudService { + + + private Map inventory = new HashMap(); + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ + + System.out.println("*** Calling getinfo ***"); + + Movie movie=new Movie(); + movie.setImdbID(imdbID); + return movie; + } + + @POST + @Path("/addmovie") + @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(); + } + 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){ + + 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(); + } + inventory.put(movie.getImdbID(),movie); + return Response.status(Response.Status.OK).build(); + + } + + + @DELETE + @Path("/deletemovie") + 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(); + } + + inventory.remove(imdbID); + return Response.status(Response.Status.OK).build(); + } + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + public List listMovies(){ + + return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); + + } + + + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java new file mode 100644 index 0000000000..16b6200ad1 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java @@ -0,0 +1,40 @@ +package com.baeldung.server.service; + + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Created by Admin on 29/01/2016. + */ + + + +@ApplicationPath("/rest") +public class RestEasyServices extends Application { + + private Set singletons = new HashSet(); + + public RestEasyServices() { + singletons.add(new MovieCrudService()); + } + + @Override + public Set getSingletons() { + return singletons; + } + + @Override + public Set> getClasses() { + return super.getClasses(); + } + + @Override + public Map getProperties() { + return super.getProperties(); + } +} diff --git a/RestEasy Example/src/main/resources/schema1.xsd b/RestEasy Example/src/main/resources/schema1.xsd new file mode 100644 index 0000000000..0d74b7c366 --- /dev/null +++ b/RestEasy Example/src/main/resources/schema1.xsd @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml b/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml new file mode 100644 index 0000000000..d94e9f71ab --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000000..84d75934a7 --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000000..694bb71332 --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..c66d3b56ae --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,51 @@ + + + + RestEasy Example + + + + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap + + + + RestEasy Example + + + webAppRootKey + RestEasyExample + + + + + + resteasy.servlet.mapping.prefix + /rest + + + + + resteasy-servlet + + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher + + + javax.ws.rs.Application + com.baeldung.server.service.RestEasyServices + + + + + resteasy-servlet + /rest/* + + + + + index.html + + + + \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java new file mode 100644 index 0000000000..e711233979 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -0,0 +1,50 @@ +package com.baeldung.server; + +import com.baeldung.Movie; +import com.baeldung.client.ServicesInterface; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; + +import java.util.List; + +public class RestEasyClient { + + public static void main(String[] args) { + + Movie st = new Movie(); + st.setImdbID("12345"); + + /* + * Alternatively you can use this simple String to send + * instead of using a Student instance + * + * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; + */ + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + + ServicesInterface simple = target.proxy(ServicesInterface.class); + final List movies = simple.listMovies(); + + /* + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + + System.out.println("Server response : \n"); + System.out.println(response.readEntity(String.class)); + + response.close(); +*/ + } catch (Exception e) { + + e.printStackTrace(); + + } + } + +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/server/movies/transformer.json new file mode 100644 index 0000000000..2154868265 --- /dev/null +++ b/RestEasy Example/src/test/resources/server/movies/transformer.json @@ -0,0 +1,22 @@ +{ + "title": "Transformers", + "year": "2007", + "rated": "PG-13", + "released": "03 Jul 2007", + "runtime": "144 min", + "genre": "Action, Adventure, Sci-Fi", + "director": "Michael Bay", + "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", + "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", + "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", + "language": "English, Spanish", + "country": "USA", + "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", + "metascore": "61", + "imdbRating": "7.1", + "imdbVotes": "492,225", + "imdbID": "tt0418279", + "Type": "movie", + "response": "True" +} \ No newline at end of file From 72a74b8096cd535da6ff3c96d7cc05d305c5e1a9 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sat, 30 Jan 2016 20:39:28 +0100 Subject: [PATCH 017/142] Added testCase for List All Movies and Add a Movie --- RestEasy Example/pom.xml | 29 +++++ .../baeldung/client/ServicesInterface.java | 6 +- .../java/com/baeldung/{ => model}/Movie.java | 45 +++++++- .../{service => }/MovieCrudService.java | 5 +- .../{service => }/RestEasyServices.java | 2 +- .../com/baeldung/server/RestEasyClient.java | 104 ++++++++++++++---- .../com/baeldung/server/movies/batman.json | 22 ++++ .../baeldung}/server/movies/transformer.json | 2 +- 8 files changed, 184 insertions(+), 31 deletions(-) rename RestEasy Example/src/main/java/com/baeldung/{ => model}/Movie.java (86%) rename RestEasy Example/src/main/java/com/baeldung/server/{service => }/MovieCrudService.java (96%) rename RestEasy Example/src/main/java/com/baeldung/server/{service => }/RestEasyServices.java (95%) create mode 100644 RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json rename RestEasy Example/src/test/resources/{ => com/baeldung}/server/movies/transformer.json (99%) diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index b16c5e8267..8dabfc863b 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -85,6 +85,35 @@ ${resteasy.scope} + + + + junit + junit + 4.4 + + + + commons-io + commons-io + 2.4 + + + + com.fasterxml.jackson.core + jackson-core + 2.7.0 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.7.0 + + + + + diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 53e88961be..2585c32438 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -1,15 +1,13 @@ package com.baeldung.client; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; - +@Path("/movies") public interface ServicesInterface { diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java similarity index 86% rename from RestEasy Example/src/main/java/com/baeldung/Movie.java rename to RestEasy Example/src/main/java/com/baeldung/model/Movie.java index c0041d2e95..052ba081c1 100644 --- a/RestEasy Example/src/main/java/com/baeldung/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -1,5 +1,5 @@ -package com.baeldung; +package com.baeldung.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -532,4 +532,47 @@ public class Movie { this.year = value; } + @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 + '\'' + + '}'; + } + + @Override + public boolean equals(Object o) { + 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; + return title != null ? title.equals(movie.title) : movie.title == null; + + } + + @Override + public int hashCode() { + int result = imdbID != null ? imdbID.hashCode() : 0; + result = 31 * result + (title != null ? title.hashCode() : 0); + return result; + } } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java similarity index 96% rename from RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java rename to RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index d1973e7037..60e0121966 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -1,11 +1,10 @@ -package com.baeldung.server.service; +package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java similarity index 95% rename from RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java rename to RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java index 16b6200ad1..8c57d2c9b4 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java @@ -1,4 +1,4 @@ -package com.baeldung.server.service; +package com.baeldung.server; import javax.ws.rs.ApplicationPath; diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java index e711233979..c77f494862 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -1,49 +1,111 @@ package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import javax.naming.NamingException; +import javax.ws.rs.core.Link; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.List; +import java.util.Locale; public class RestEasyClient { - public static void main(String[] args) { - Movie st = new Movie(); - st.setImdbID("12345"); + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; - /* - * Alternatively you can use this simple String to send - * instead of using a Student instance - * - * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; - */ + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + @Test + public void testListAllMovies() { try { ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ServicesInterface simple = target.proxy(ServicesInterface.class); - final List movies = simple.listMovies(); + final Response moviesResponse = simple.addMovie(batmanMovie); - /* - if (response.getStatus() != 200) { + if (moviesResponse.getStatus() != 201) { + System.out.println(moviesResponse.readEntity(String.class)); throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); + + moviesResponse.getStatus()); } - System.out.println("Server response : \n"); - System.out.println(response.readEntity(String.class)); + moviesResponse.close(); - response.close(); -*/ } catch (Exception e) { - e.printStackTrace(); - } } diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json new file mode 100644 index 0000000000..28061d5bf9 --- /dev/null +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json @@ -0,0 +1,22 @@ +{ + "title": "Batman", + "year": "1989", + "rated": "PG-13", + "released": "23 Jun 1989", + "runtime": "126 min", + "genre": "Action, Adventure", + "director": "Tim Burton", + "writer": "Bob Kane (Batman characters), Sam Hamm (story), Sam Hamm (screenplay), Warren Skaaren (screenplay)", + "actors": "Michael Keaton, Jack Nicholson, Kim Basinger, Robert Wuhl", + "plot": "The Dark Knight of Gotham City begins his war on crime with his first major enemy being the clownishly homicidal Joker.", + "language": "English, French", + "country": "USA, UK", + "awards": "Won 1 Oscar. Another 9 wins & 22 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTYwNjAyODIyMF5BMl5BanBnXkFtZTYwNDMwMDk2._V1_SX300.jpg", + "metascore": "66", + "imdbRating": "7.6", + "imdbVotes": "256,000", + "imdbID": "tt0096895", + "type": "movie", + "response": "True" +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json similarity index 99% rename from RestEasy Example/src/test/resources/server/movies/transformer.json rename to RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json index 2154868265..a3b033a8ba 100644 --- a/RestEasy Example/src/test/resources/server/movies/transformer.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json @@ -17,6 +17,6 @@ "imdbRating": "7.1", "imdbVotes": "492,225", "imdbID": "tt0418279", - "Type": "movie", + "type": "movie", "response": "True" } \ No newline at end of file From 4174ff7dd2a1deb7e023067326e8fa2495385003 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sun, 31 Jan 2016 11:05:11 +0100 Subject: [PATCH 018/142] Added testCase for all Services --- RestEasy Example/pom.xml | 15 -- .../baeldung/client/ServicesInterface.java | 10 +- .../com/baeldung/server/MovieCrudService.java | 15 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- .../com/baeldung/server/RestEasyClient.java | 112 ----------- .../baeldung/server/RestEasyClientTest.java | 189 ++++++++++++++++++ 6 files changed, 206 insertions(+), 137 deletions(-) delete mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 8dabfc863b..6935238d91 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -99,21 +99,6 @@ 2.4 - - com.fasterxml.jackson.core - jackson-core - 2.7.0 - - - - com.fasterxml.jackson.core - jackson-annotations - 2.7.0 - - - - - diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 2585c32438..7efed546d8 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -17,6 +17,12 @@ public interface ServicesInterface { Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -34,9 +40,5 @@ public interface ServicesInterface { Response deleteMovie(@QueryParam("imdbID") String imdbID); - @GET - @Path("/listmovies") - @Produces({"application/json"}) - List listMovies(); } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 60e0121966..18366e2faa 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -18,18 +18,21 @@ public class MovieCrudService { private Map inventory = new HashMap(); + @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ - System.out.println("*** Calling getinfo ***"); + System.out.println("*** Calling getinfo for a given ImdbID***"); + + if(inventory.containsKey(imdbID)){ + return inventory.get(imdbID); + }else return null; - Movie movie=new Movie(); - movie.setImdbID(imdbID); - return movie; } + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -41,6 +44,7 @@ public class MovieCrudService { return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is Already in the database.").build(); } + inventory.put(movie.getImdbID(),movie); return Response.status(Response.Status.CREATED).build(); @@ -54,7 +58,7 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + if (null==inventory.get(movie.getImdbID())){ return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is not in the database.\nUnable to Update").build(); } @@ -79,6 +83,7 @@ public class MovieCrudService { return Response.status(Response.Status.OK).build(); } + @GET @Path("/listmovies") @Produces({"application/json"}) diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index c66d3b56ae..ab3bc1aa83 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -33,7 +33,7 @@ javax.ws.rs.Application - com.baeldung.server.service.RestEasyServices + com.baeldung.server.RestEasyServices diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java deleted file mode 100644 index c77f494862..0000000000 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.baeldung.server; - -import com.baeldung.model.Movie; -import com.baeldung.client.ServicesInterface; -import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.naming.NamingException; -import javax.ws.rs.core.Link; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -public class RestEasyClient { - - - Movie transformerMovie=null; - Movie batmanMovie=null; - ObjectMapper jsonMapper=null; - - @BeforeClass - public static void loadMovieInventory(){ - - - - } - - @Before - public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - - - 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); - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { - String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { - String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); - - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - } - - @Test - public void testListAllMovies() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - - - @Test - public void testAddMovie() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - - ServicesInterface simple = target.proxy(ServicesInterface.class); - final Response moviesResponse = simple.addMovie(batmanMovie); - - if (moviesResponse.getStatus() != 201) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " - + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java new file mode 100644 index 0000000000..fb4205bcd7 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -0,0 +1,189 @@ +package com.baeldung.server; + +import com.baeldung.model.Movie; +import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.naming.NamingException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Locale; + +public class RestEasyClientTest { + + + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; + + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + + @Test + public void testListAllMovies() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testMovieByImdbID() { + + String transformerImdbId="tt0418279"; + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + + final Movie movies = simple.movieByImdbID(transformerImdbId); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(transformerMovie); + + if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { + //System.out.println(moviesResponse.readEntity(String.class)); + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testDeleteMovie() { + + String transformerImdbId="tt0418279"; + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.deleteMovie(transformerImdbId); + moviesResponse.close(); + + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println(moviesResponse.readEntity(String.class)); + throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testUpdateMovie() { + + try { + + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + batmanMovie.setImdbVotes("300,000"); + moviesResponse = simple.updateMovie(batmanMovie); + + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + //System.out.println(moviesResponse.readEntity(String.class)); + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file From 85d299e739fa00317d687fdd2af2ffa43a9dfc1c Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:29:30 +0100 Subject: [PATCH 019/142] Minor Bugfix --- .../baeldung/client/ServicesInterface.java | 4 +- .../main/java/com/baeldung/model/Movie.java | 22 +-- .../com/baeldung/server/MovieCrudService.java | 12 +- .../src/main/webapp/WEB-INF/web.xml | 37 +---- .../java/baeldung/client/RestEasyClient.java | 7 + .../baeldung/server/RestEasyClientTest.java | 149 +++++++----------- 6 files changed, 81 insertions(+), 150 deletions(-) create mode 100644 RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 7efed546d8..749cabc757 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -14,7 +14,7 @@ public interface ServicesInterface { @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) - Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + Movie movieByImdbId(@QueryParam("imdbId") String imdbId); @GET @@ -37,7 +37,7 @@ public interface ServicesInterface { @DELETE @Path("/deletemovie") - Response deleteMovie(@QueryParam("imdbID") String imdbID); + Response deleteMovie(@QueryParam("imdbId") String imdbID); diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 052ba081c1..a2b2bd5250 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType; "country", "director", "genre", - "imdbID", + "imdbId", "imdbRating", "imdbVotes", "language", @@ -36,7 +36,7 @@ public class Movie { protected String country; protected String director; protected String genre; - protected String imdbID; + protected String imdbId; protected String imdbRating; protected String imdbVotes; protected String language; @@ -173,27 +173,27 @@ public class Movie { } /** - * Recupera il valore della propriet� imdbID. + * Recupera il valore della propriet� imdbId. * * @return * possible object is * {@link String } * */ - public String getImdbID() { - return imdbID; + public String getImdbId() { + return imdbId; } /** - * Imposta il valore della propriet� imdbID. + * Imposta il valore della propriet� imdbId. * * @param value * allowed object is * {@link String } * */ - public void setImdbID(String value) { - this.imdbID = value; + public void setImdbId(String value) { + this.imdbId = value; } /** @@ -540,7 +540,7 @@ public class Movie { ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + - ", imdbID='" + imdbID + '\'' + + ", imdbId='" + imdbId + '\'' + ", imdbRating='" + imdbRating + '\'' + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + @@ -564,14 +564,14 @@ public class Movie { 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; } @Override public int hashCode() { - int result = imdbID != null ? imdbID.hashCode() : 0; + int result = imdbId != null ? imdbId.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); return result; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 18366e2faa..29226aa0e0 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -22,7 +22,7 @@ public class MovieCrudService { @GET @Path("/getinfo") @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***"); @@ -40,12 +40,12 @@ public class MovieCrudService { System.out.println("*** Calling addMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + 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(); } @@ -58,11 +58,11 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null==inventory.get(movie.getImdbID())){ + 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(); } @@ -70,7 +70,7 @@ public class MovieCrudService { @DELETE @Path("/deletemovie") - public Response deleteMovie(@QueryParam("imdbID") String imdbID){ + public Response deleteMovie(@QueryParam("imdbId") String imdbID){ System.out.println("*** Calling deleteMovie ***"); diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index ab3bc1aa83..f70fdf7975 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -5,47 +5,12 @@ RestEasy Example - - - org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap - - - - RestEasy Example - - - webAppRootKey - RestEasyExample - - - - + resteasy.servlet.mapping.prefix /rest - - resteasy-servlet - - org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher - - - javax.ws.rs.Application - com.baeldung.server.RestEasyServices - - - - - resteasy-servlet - /rest/* - - - - - index.html - - \ No newline at end of file diff --git a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java new file mode 100644 index 0000000000..b474b3d4f8 --- /dev/null +++ b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java @@ -0,0 +1,7 @@ +package baeldung.client; + +/** + * Created by Admin on 29/01/2016. + */ +public class RestEasyClient { +} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index fb4205bcd7..b6a2e2a0c1 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -1,7 +1,7 @@ package com.baeldung.server; -import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import com.baeldung.model.Movie; import org.apache.commons.io.IOUtils; import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; @@ -9,7 +9,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import javax.naming.NamingException; @@ -23,22 +22,13 @@ import java.util.Locale; public class RestEasyClientTest { - Movie transformerMovie=null; Movie batmanMovie=null; ObjectMapper jsonMapper=null; - @BeforeClass - public static void loadMovieInventory(){ - - - - } - @Before public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - 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); @@ -57,133 +47,102 @@ public class RestEasyClientTest { batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException("Test is going to die ...", e); } - } - @Test public void testListAllMovies() { - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } + List movies = simple.listMovies(); + System.out.println(movies); } - @Test - public void testMovieByImdbID() { + public void testMovieByImdbId() { String transformerImdbId="tt0418279"; - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); - final Movie movies = simple.movieByImdbID(transformerImdbId); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } + Movie movies = simple.movieByImdbId(transformerImdbId); + System.out.println(movies); } @Test public void testAddMovie() { - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(transformerMovie); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(transformerMovie); - if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { - //System.out.println(moviesResponse.readEntity(String.class)); - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } @Test - public void testDeleteMovie() { + public void testDeleteMovi1e() { - String transformerImdbId="tt0418279"; + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.deleteMovie(batmanMovie.getImdbId()); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.deleteMovie(transformerImdbId); - moviesResponse.close(); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println(moviesResponse.readEntity(String.class)); + throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } @Test public void testUpdateMovie() { - try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + batmanMovie.setImdbVotes("300,000"); + moviesResponse = simple.updateMovie(batmanMovie); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - batmanMovie.setImdbVotes("300,000"); - moviesResponse = simple.updateMovie(batmanMovie); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - //System.out.println(moviesResponse.readEntity(String.class)); - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } } \ No newline at end of file From d4a4d20fa03d9356ee122834846551cd71427c44 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:39:35 +0100 Subject: [PATCH 020/142] Minor Bugfix --- .../main/java/com/baeldung/model/Movie.java | 321 +----------------- 1 file changed, 1 insertion(+), 320 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index a2b2bd5250..805ba95209 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -52,482 +52,163 @@ public class Movie { protected String writer; protected String year; - /** - * Recupera il valore della propriet� actors. - * - * @return - * possible object is - * {@link String } - * - */ + public String getActors() { return actors; } - /** - * Imposta il valore della propriet� actors. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setActors(String value) { this.actors = value; } - /** - * Recupera il valore della propriet� awards. - * - * @return - * possible object is - * {@link String } - * - */ public String getAwards() { return awards; } - /** - * Imposta il valore della propriet� awards. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setAwards(String value) { this.awards = value; } - /** - * Recupera il valore della propriet� country. - * - * @return - * possible object is - * {@link String } - * - */ public String getCountry() { return country; } - /** - * Imposta il valore della propriet� country. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setCountry(String value) { this.country = value; } - /** - * Recupera il valore della propriet� director. - * - * @return - * possible object is - * {@link String } - * - */ public String getDirector() { return director; } - /** - * Imposta il valore della propriet� director. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setDirector(String value) { this.director = value; } - /** - * Recupera il valore della propriet� genre. - * - * @return - * possible object is - * {@link String } - * - */ public String getGenre() { return genre; } - /** - * Imposta il valore della propriet� genre. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setGenre(String value) { this.genre = value; } - /** - * Recupera il valore della propriet� imdbId. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbId() { return imdbId; } - /** - * Imposta il valore della propriet� imdbId. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbId(String value) { this.imdbId = value; } - /** - * Recupera il valore della propriet� imdbRating. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbRating() { return imdbRating; } - /** - * Imposta il valore della propriet� imdbRating. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbRating(String value) { this.imdbRating = value; } - /** - * Recupera il valore della propriet� imdbVotes. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbVotes() { return imdbVotes; } - /** - * Imposta il valore della propriet� imdbVotes. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbVotes(String value) { this.imdbVotes = value; } - /** - * Recupera il valore della propriet� language. - * - * @return - * possible object is - * {@link String } - * - */ public String getLanguage() { return language; } - /** - * Imposta il valore della propriet� language. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setLanguage(String value) { this.language = value; } - /** - * Recupera il valore della propriet� metascore. - * - * @return - * possible object is - * {@link String } - * - */ public String getMetascore() { return metascore; } - /** - * Imposta il valore della propriet� metascore. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setMetascore(String value) { this.metascore = value; } - /** - * Recupera il valore della propriet� plot. - * - * @return - * possible object is - * {@link String } - * - */ public String getPlot() { return plot; } - /** - * Imposta il valore della propriet� plot. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setPlot(String value) { this.plot = value; } - /** - * Recupera il valore della propriet� poster. - * - * @return - * possible object is - * {@link String } - * - */ public String getPoster() { return poster; } - /** - * Imposta il valore della propriet� poster. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setPoster(String value) { this.poster = value; } - /** - * Recupera il valore della propriet� rated. - * - * @return - * possible object is - * {@link String } - * - */ public String getRated() { return rated; } - /** - * Imposta il valore della propriet� rated. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setRated(String value) { this.rated = value; } - /** - * Recupera il valore della propriet� released. - * - * @return - * possible object is - * {@link String } - * - */ public String getReleased() { return released; } - /** - * Imposta il valore della propriet� released. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setReleased(String value) { this.released = value; } - /** - * Recupera il valore della propriet� response. - * - * @return - * possible object is - * {@link String } - * - */ public String getResponse() { return response; } - /** - * Imposta il valore della propriet� response. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setResponse(String value) { this.response = value; } - /** - * Recupera il valore della propriet� runtime. - * - * @return - * possible object is - * {@link String } - * - */ public String getRuntime() { return runtime; } - /** - * Imposta il valore della propriet� runtime. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setRuntime(String value) { this.runtime = value; } - /** - * Recupera il valore della propriet� title. - * - * @return - * possible object is - * {@link String } - * - */ public String getTitle() { return title; } - /** - * Imposta il valore della propriet� title. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setTitle(String value) { this.title = value; } - /** - * Recupera il valore della propriet� type. - * - * @return - * possible object is - * {@link String } - * - */ public String getType() { return type; } - /** - * Imposta il valore della propriet� type. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setType(String value) { this.type = value; } - /** - * Recupera il valore della propriet� writer. - * - * @return - * possible object is - * {@link String } - * - */ public String getWriter() { return writer; } - /** - * Imposta il valore della propriet� writer. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setWriter(String value) { this.writer = value; } - /** - * Recupera il valore della propriet� year. - * - * @return - * possible object is - * {@link String } - * - */ public String getYear() { return year; } - /** - * Imposta il valore della propriet� year. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setYear(String value) { this.year = value; } From 183ae3d3b9bae2ce9151c4ab0702b74ecb54d1dd Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:47:42 +0100 Subject: [PATCH 021/142] Minor Bugfix --- .../main/java/com/baeldung/model/Movie.java | 260 ------------------ 1 file changed, 260 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 8eb8283d28..76e84a6378 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -84,390 +84,130 @@ public class Movie { this.director = value; } - public String getGenre() { return genre; } - public void setGenre(String value) { this.genre = value; } - /** - * Recupera il valore della propriet� imdbId. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbId() { return imdbId; } - /** - * Imposta il valore della propriet� imdbId. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbId(String value) { this.imdbId = value; } - /** - * Recupera il valore della propriet� imdbRating. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbRating() { return imdbRating; } - /** - * Imposta il valore della propriet� imdbRating. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbRating(String value) { this.imdbRating = value; } - /** - * Recupera il valore della propriet� imdbVotes. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbVotes() { return imdbVotes; } public void setImdbVotes(String value) { - /** - * Imposta il valore della propriet� imdbVotes. - * - * @param value - * allowed object is - * {@link String } - * - */ this.imdbVotes = value; } public String getLanguage() { - /** - * Recupera il valore della propriet� language. - * - * @return - * possible object is - * {@link String } - * - */ return language; } - /** - * Imposta il valore della propriet� language. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setLanguage(String value) { this.language = value; } - /** - * Recupera il valore della propriet� metascore. - * - * @return - * possible object is - * {@link String } - * - */ public String getMetascore() { return metascore; } - /** - * Imposta il valore della propriet� metascore. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setMetascore(String value) { this.metascore = value; } - /** - * Recupera il valore della propriet� plot. - * - * @return - * possible object is - * {@link String } - * - */ public String getPlot() { return plot; } - /** - * Imposta il valore della propriet� plot. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setPlot(String value) { this.plot = value; } - /** - * Recupera il valore della propriet� poster. - * - * @return - * possible object is - * {@link String } - * - */ public String getPoster() { return poster; } - /** - * Imposta il valore della propriet� poster. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setPoster(String value) { this.poster = value; } - /** - * Recupera il valore della propriet� rated. - * - * @return - * possible object is - * {@link String } - * - */ public String getRated() { return rated; } - /** - * Imposta il valore della propriet� rated. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setRated(String value) { this.rated = value; } - /** - * Recupera il valore della propriet� released. - * - * @return - * possible object is - * {@link String } - * - */ public String getReleased() { return released; } - /** - * Imposta il valore della propriet� released. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setReleased(String value) { this.released = value; } - /** - * Recupera il valore della propriet� response. - * - * @return - * possible object is - * {@link String } - * - */ public String getResponse() { return response; } - /** - * Imposta il valore della propriet� response. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setResponse(String value) { this.response = value; } - /** - * Recupera il valore della propriet� runtime. - * - * @return - * possible object is - * {@link String } - * - */ public String getRuntime() { return runtime; } - /** - * Imposta il valore della propriet� runtime. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setRuntime(String value) { this.runtime = value; } - /** - * Recupera il valore della propriet� title. - * - * @return - * possible object is - * {@link String } - * - */ public String getTitle() { return title; } - /** - * Imposta il valore della propriet� title. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setTitle(String value) { this.title = value; } -<<<<<<< HEAD -======= - /** - * Recupera il valore della propriet� type. - * - * @return - * possible object is - * {@link String } - * - */ ->>>>>>> origin/master public String getType() { return type; } -<<<<<<< HEAD -======= - /** - * Imposta il valore della propriet� type. - * - * @param value - * allowed object is - * {@link String } - * - */ ->>>>>>> origin/master public void setType(String value) { this.type = value; } -<<<<<<< HEAD -======= - /** - * Recupera il valore della propriet� writer. - * - * @return - * possible object is - * {@link String } - * - */ ->>>>>>> origin/master public String getWriter() { return writer; } -<<<<<<< HEAD -======= - /** - * Imposta il valore della propriet� writer. - * - * @param value - * allowed object is - * {@link String } - * - */ ->>>>>>> origin/master public void setWriter(String value) { this.writer = value; } -<<<<<<< HEAD -======= - /** - * Recupera il valore della propriet� year. - * - * @return - * possible object is - * {@link String } - * - */ ->>>>>>> origin/master public String getYear() { return year; } -<<<<<<< HEAD -======= - /** - * Imposta il valore della propriet� year. - * - * @param value - * allowed object is - * {@link String } - * - */ ->>>>>>> origin/master public void setYear(String value) { this.year = value; } From 03b6cbf3e545dcb817abf364f1edea3e2b074a03 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:55:46 +0100 Subject: [PATCH 022/142] CleanUp Code --- RestEasy Example/pom.xml | 3 +- .../baeldung/client/ServicesInterface.java | 1 - .../main/java/com/baeldung/model/Movie.java | 2 -- .../com/baeldung/server/MovieCrudService.java | 17 ++++------- .../com/baeldung/server/RestEasyServices.java | 8 ----- .../src/main/resources/schema1.xsd | 29 ------------------- .../src/main/webapp/WEB-INF/web.xml | 3 -- .../java/baeldung/client/RestEasyClient.java | 7 ----- .../baeldung/server/RestEasyClientTest.java | 1 - 9 files changed, 7 insertions(+), 64 deletions(-) delete mode 100644 RestEasy Example/src/main/resources/schema1.xsd delete mode 100644 RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 6935238d91..9c890da2b7 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -36,7 +36,7 @@ - + org.jboss.resteasy jaxrs-api @@ -101,5 +101,4 @@ - \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 749cabc757..3c8d6abc00 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -1,7 +1,6 @@ package com.baeldung.client; import com.baeldung.model.Movie; - import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 76e84a6378..7590f10487 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -1,11 +1,9 @@ - package com.baeldung.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; - @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "movie", propOrder = { "actors", diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 29226aa0e0..bbb3b1e953 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -1,7 +1,6 @@ package com.baeldung.server; import com.baeldung.model.Movie; - import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -11,23 +10,21 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - @Path("/movies") public class MovieCrudService { - private Map inventory = new HashMap(); @GET @Path("/getinfo") @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***"); - if(inventory.containsKey(imdbID)){ - return inventory.get(imdbID); + if(inventory.containsKey(imdbId)){ + return inventory.get(imdbId); }else return null; } @@ -70,16 +67,16 @@ public class MovieCrudService { @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)){ + 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); + inventory.remove(imdbId); return Response.status(Response.Status.OK).build(); } @@ -93,6 +90,4 @@ public class MovieCrudService { } - - } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java index 8c57d2c9b4..7726e49f38 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java @@ -1,19 +1,11 @@ package com.baeldung.server; - import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; -import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Set; -/** - * Created by Admin on 29/01/2016. - */ - - - @ApplicationPath("/rest") public class RestEasyServices extends Application { diff --git a/RestEasy Example/src/main/resources/schema1.xsd b/RestEasy Example/src/main/resources/schema1.xsd deleted file mode 100644 index 0d74b7c366..0000000000 --- a/RestEasy Example/src/main/resources/schema1.xsd +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index f70fdf7975..1e7f64004d 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -5,12 +5,9 @@ RestEasy Example - resteasy.servlet.mapping.prefix /rest - - \ No newline at end of file diff --git a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java deleted file mode 100644 index b474b3d4f8..0000000000 --- a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java +++ /dev/null @@ -1,7 +0,0 @@ -package baeldung.client; - -/** - * Created by Admin on 29/01/2016. - */ -public class RestEasyClient { -} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index b6a2e2a0c1..faa39e0199 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -10,7 +10,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.junit.Before; import org.junit.Test; - import javax.naming.NamingException; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; From 9c60f320892dcdfe2d15b5b68332c58e103fa64a Mon Sep 17 00:00:00 2001 From: David Morley Date: Sun, 7 Feb 2016 14:54:04 -0600 Subject: [PATCH 023/142] Clean up examples for Spring Data Elasticsearch --- .../baeldung/{ => spring/data/es}/config/Config.java | 4 ++-- .../data/es/dao}/ArticleRepository.java | 4 ++-- .../baeldung/{ => spring/data/es}/model/Article.java | 2 +- .../baeldung/{ => spring/data/es}/model/Author.java | 2 +- .../data/es/repository}/ArticleRepository.java | 5 ++--- .../{ => spring/data/es}/service/ArticleService.java | 4 ++-- .../data/es}/service/ArticleServiceImpl.java | 6 +++--- .../{ => spring/data/es}/ElasticSearchTest.java | 11 +++++------ 8 files changed, 18 insertions(+), 20 deletions(-) rename spring-data-elasticsearch/src/main/java/com/baeldung/{ => spring/data/es}/config/Config.java (94%) rename spring-data-elasticsearch/src/main/java/com/baeldung/{repository => spring/data/es/dao}/ArticleRepository.java (86%) rename spring-data-elasticsearch/src/main/java/com/baeldung/{ => spring/data/es}/model/Article.java (96%) rename spring-data-elasticsearch/src/main/java/com/baeldung/{ => spring/data/es}/model/Author.java (90%) rename spring-data-elasticsearch/src/main/java/com/baeldung/{dao => spring/data/es/repository}/ArticleRepository.java (85%) rename spring-data-elasticsearch/src/main/java/com/baeldung/{ => spring/data/es}/service/ArticleService.java (82%) rename spring-data-elasticsearch/src/main/java/com/baeldung/{ => spring/data/es}/service/ArticleServiceImpl.java (89%) rename spring-data-elasticsearch/src/test/java/com/baeldung/{ => spring/data/es}/ElasticSearchTest.java (94%) diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java similarity index 94% rename from spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java rename to spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java index a67ec64534..78e4083a28 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/config/Config.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java @@ -1,4 +1,4 @@ -package com.baeldung.config; +package com.baeldung.spring.data.es.config; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.node.NodeBuilder; @@ -18,7 +18,7 @@ import java.nio.file.Paths; @Configuration @EnableElasticsearchRepositories(basePackages = "com.baeldung.repository") -@ComponentScan(basePackages = {"com.baeldung.service"}) +@ComponentScan(basePackages = {"com.baeldung.spring.data.es.service"}) public class Config { private static Logger logger = LoggerFactory.getLogger(Config.class); diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/repository/ArticleRepository.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/dao/ArticleRepository.java similarity index 86% rename from spring-data-elasticsearch/src/main/java/com/baeldung/repository/ArticleRepository.java rename to spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/dao/ArticleRepository.java index 1cb74889c5..313eba5b36 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/repository/ArticleRepository.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/dao/ArticleRepository.java @@ -1,6 +1,6 @@ -package com.baeldung.repository; +package com.baeldung.spring.data.es.dao; -import com.baeldung.model.Article; +import com.baeldung.spring.data.es.model.Article; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.elasticsearch.annotations.Query; diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Article.java similarity index 96% rename from spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java rename to spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Article.java index dee1d0817e..dd472982ce 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/model/Article.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Article.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.spring.data.es.model; import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/model/Author.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Author.java similarity index 90% rename from spring-data-elasticsearch/src/main/java/com/baeldung/model/Author.java rename to spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Author.java index 09239efbe5..c335c4534a 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/model/Author.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Author.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.spring.data.es.model; public class Author { diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/dao/ArticleRepository.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/repository/ArticleRepository.java similarity index 85% rename from spring-data-elasticsearch/src/main/java/com/baeldung/dao/ArticleRepository.java rename to spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/repository/ArticleRepository.java index 6ed86eff9b..27628950d7 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/dao/ArticleRepository.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/repository/ArticleRepository.java @@ -1,7 +1,6 @@ -package com.baeldung.dao; +package com.baeldung.spring.data.es.repository; -import com.baeldung.model.Article; -import com.baeldung.model.Article; +import com.baeldung.spring.data.es.model.Article; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.elasticsearch.annotations.Query; diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleService.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java similarity index 82% rename from spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleService.java rename to spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java index 052e22c67d..760bad4b01 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleService.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java @@ -1,6 +1,6 @@ -package com.baeldung.service; +package com.baeldung.spring.data.es.service; -import com.baeldung.model.Article; +import com.baeldung.spring.data.es.model.Article; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java similarity index 89% rename from spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java rename to spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java index 59feb2816c..3bb6e6a0e0 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/service/ArticleServiceImpl.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java @@ -1,7 +1,7 @@ -package com.baeldung.service; +package com.baeldung.spring.data.es.service; -import com.baeldung.repository.ArticleRepository; -import com.baeldung.model.Article; +import com.baeldung.spring.data.es.repository.ArticleRepository; +import com.baeldung.spring.data.es.model.Article; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/ElasticSearchTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchTest.java similarity index 94% rename from spring-data-elasticsearch/src/test/java/com/baeldung/ElasticSearchTest.java rename to spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchTest.java index 07248149c2..34ccfd788e 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/ElasticSearchTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchTest.java @@ -1,10 +1,9 @@ -package com.baeldung; +package com.baeldung.spring.data.es; -import com.baeldung.config.Config; -import com.baeldung.model.Article; -import com.baeldung.model.Author; -import com.baeldung.service.ArticleService; -import org.elasticsearch.index.query.QueryBuilder; +import com.baeldung.spring.data.es.config.Config; +import com.baeldung.spring.data.es.model.Article; +import com.baeldung.spring.data.es.model.Author; +import com.baeldung.spring.data.es.service.ArticleService; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; From 58e82f3c1f630af700aa2890a1f01835969b9667 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 11:46:02 +0200 Subject: [PATCH 024/142] Update README.md --- spring-hibernate4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-hibernate4/README.md b/spring-hibernate4/README.md index 96f8074165..acf20632fe 100644 --- a/spring-hibernate4/README.md +++ b/spring-hibernate4/README.md @@ -6,6 +6,7 @@ - [Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring) - [The DAO with Spring 3 and Hibernate](http://www.baeldung.com/2011/12/02/the-persistence-layer-with-spring-3-1-and-hibernate/) - [Hibernate Pagination](http://www.baeldung.com/hibernate-pagination) +- [Sorting with Hibernate](http://www.baeldung.com/hibernate-sort) ### Quick Start From d68375cd6da76a53a8074daf862d659da21f22bb Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 11:57:26 +0200 Subject: [PATCH 025/142] Update README.md --- httpclient/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/httpclient/README.md b/httpclient/README.md index 529ac754f8..b9dd431500 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -5,12 +5,13 @@ ### Relevant Articles: -- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies) -- [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code) -- [HttpClient 4 – Cancel / Abort Request](http://www.baeldung.com/httpclient-cancel-request) +- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies) +- [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code) +- [HttpClient 4 – Cancel / Abort Request](http://www.baeldung.com/httpclient-cancel-request) - [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4) - [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient) - [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) -- [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post) -- [HttpClient – Set Custom Header](http://www.baeldung.com/httpclient-custom-http-header) +- [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post) +- [HttpClient – Set Custom Header](http://www.baeldung.com/httpclient-custom-http-header) - [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) +- [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload) From e4e5a9e479859468c26a061711beeb3712d421f8 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 11:58:55 +0200 Subject: [PATCH 026/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index 63ca8c7926..b53435a222 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -11,6 +11,7 @@ - [ETags for REST with Spring](http://www.baeldung.com/2013/01/11/etags-for-rest-with-spring/) - [Error Handling for REST with Spring 3](http://www.baeldung.com/2013/01/31/exception-handling-for-rest-with-spring-3-2/) - [Integration Testing with the Maven Cargo plugin](http://www.baeldung.com/2011/10/16/how-to-set-up-integration-testing-with-the-maven-cargo-plugin/) +- [Introduction to Spring Data JPA](http://www.baeldung.com/2011/12/22/the-persistence-layer-with-spring-data-jpa/) ### Build the Project From 72bd9c54b9f53a8c01581cb0a6f3fd6f0a8aebe8 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:01:25 +0200 Subject: [PATCH 027/142] Update README.md --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 772681ad57..665a06a3c8 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -6,4 +6,5 @@ - [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list) - [Java - Reading a Large File Efficiently](http://www.baeldung.com/java-read-lines-large-file) - [Java InputStream to String](http://www.baeldung.com/convert-input-stream-to-string) +- [Converting between an Array and a List in Java](http://www.baeldung.com/convert-array-to-list-and-list-to-array) From ec551bfe3fc43a6aeb2c3c20adcb0c8bef125149 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:02:58 +0200 Subject: [PATCH 028/142] Update README.md --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 665a06a3c8..6aa04df33f 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -7,4 +7,5 @@ - [Java - Reading a Large File Efficiently](http://www.baeldung.com/java-read-lines-large-file) - [Java InputStream to String](http://www.baeldung.com/convert-input-stream-to-string) - [Converting between an Array and a List in Java](http://www.baeldung.com/convert-array-to-list-and-list-to-array) +- [Converting between an Array and a Set in Java](http://www.baeldung.com/convert-array-to-set-and-set-to-array) From 693081d509ac9d9cb1e991ea5e18348f4cfd1c40 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:04:32 +0200 Subject: [PATCH 029/142] Update README.md --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 6aa04df33f..a98e5524ac 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -8,4 +8,5 @@ - [Java InputStream to String](http://www.baeldung.com/convert-input-stream-to-string) - [Converting between an Array and a List in Java](http://www.baeldung.com/convert-array-to-list-and-list-to-array) - [Converting between an Array and a Set in Java](http://www.baeldung.com/convert-array-to-set-and-set-to-array) +- [Converting between a List and a Set in Java](http://www.baeldung.com/convert-list-to-set-and-set-to-list) From c5cad39354069a1888cc547c2cf5cc165b298bf3 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:07:07 +0200 Subject: [PATCH 030/142] Update README.md --- core-java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java/README.md b/core-java/README.md index a98e5524ac..b8f63717ed 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -9,4 +9,4 @@ - [Converting between an Array and a List in Java](http://www.baeldung.com/convert-array-to-list-and-list-to-array) - [Converting between an Array and a Set in Java](http://www.baeldung.com/convert-array-to-set-and-set-to-array) - [Converting between a List and a Set in Java](http://www.baeldung.com/convert-list-to-set-and-set-to-list) - +- [Convert a Map to an Array, List or Set in Java](http://www.baeldung.com/convert-map-values-to-array-list-set) From 9f9aee658f21ac127c2b1158832d7311bd1193ee Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:08:35 +0200 Subject: [PATCH 031/142] Update README.md --- spring-security-mvc-persisted-remember-me/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-mvc-persisted-remember-me/README.md b/spring-security-mvc-persisted-remember-me/README.md index 11f5417028..df83fd3d77 100644 --- a/spring-security-mvc-persisted-remember-me/README.md +++ b/spring-security-mvc-persisted-remember-me/README.md @@ -4,7 +4,7 @@ ### Relevant Articles: -- [Spring Security Persisted Remember Me] +- [Spring Security Persisted Remember Me](http://www.baeldung.com/spring-security-persistent-remember-me) - [Spring Security Remember Me](http://www.baeldung.com/spring-security-remember-me) - [Redirect to different pages after Login with Spring Security](http://www.baeldung.com/spring_redirect_after_login) From 7bc00c24b721a406a3434964b803f835335a4e43 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:13:41 +0200 Subject: [PATCH 032/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index b53435a222..cffbcf40f0 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -12,6 +12,7 @@ - [Error Handling for REST with Spring 3](http://www.baeldung.com/2013/01/31/exception-handling-for-rest-with-spring-3-2/) - [Integration Testing with the Maven Cargo plugin](http://www.baeldung.com/2011/10/16/how-to-set-up-integration-testing-with-the-maven-cargo-plugin/) - [Introduction to Spring Data JPA](http://www.baeldung.com/2011/12/22/the-persistence-layer-with-spring-data-jpa/) +- [Project Configuration with Spring](http://www.baeldung.com/2012/03/12/project-configuration-with-spring/) ### Build the Project From dfc7b2113d40bf7c5a350027473f88ea6a51245a Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:14:54 +0200 Subject: [PATCH 033/142] Update README.md --- spring-mvc-xml/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-xml/README.md b/spring-mvc-xml/README.md index 908e21d4bf..2409ec8174 100644 --- a/spring-mvc-xml/README.md +++ b/spring-mvc-xml/README.md @@ -7,3 +7,4 @@ ### Relevant Articles: - [Spring MVC Tutorial](http://www.baeldung.com/spring-mvc-tutorial) - [Servlet Session Timeout](http://www.baeldung.com/servlet-session-timeout) +- [Basic Forms with Spring MVC](http://www.baeldung.com/spring-mvc-form-tutorial) From 550068f5a8fb8f0f02a5edeb66edd831f875ad47 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:19:34 +0200 Subject: [PATCH 034/142] Update README.md --- gson/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gson/README.md b/gson/README.md index 559e536d81..47d8ecfb39 100644 --- a/gson/README.md +++ b/gson/README.md @@ -2,5 +2,6 @@ ## GSON Cookbooks and Examples -### Relevant Articles: +### Relevant Articles: +-[Gson Deserialization Cookbook](http://www.baeldung.com/gson-deserialization-guide) From adc258155690a4d45e0ffd9c238cbf89081c8f29 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:20:01 +0200 Subject: [PATCH 035/142] Update README.md --- gson/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gson/README.md b/gson/README.md index 47d8ecfb39..67651b732e 100644 --- a/gson/README.md +++ b/gson/README.md @@ -4,4 +4,4 @@ ### Relevant Articles: --[Gson Deserialization Cookbook](http://www.baeldung.com/gson-deserialization-guide) +- [Gson Deserialization Cookbook](http://www.baeldung.com/gson-deserialization-guide) From d33f16a68d762b189c4ea17fc2199ddacb748b81 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:21:29 +0200 Subject: [PATCH 036/142] Update README.md --- spring-security-login-and-registration/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index 1c5b16d6f6..1638e82756 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -5,6 +5,7 @@ ### Relevant Articles: - [Spring Security Registration Tutorial](http://www.baeldung.com/spring-security-registration) +- [The Registration Process With Spring Security](http://www.baeldung.com/registration-with-spring-mvc-and-spring-security) From 28bddf2d8ebde5847c9f7f0cda79b7f9a24db63d Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:22:55 +0200 Subject: [PATCH 037/142] Update README.md --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index b8f63717ed..6db2b370f6 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -10,3 +10,4 @@ - [Converting between an Array and a Set in Java](http://www.baeldung.com/convert-array-to-set-and-set-to-array) - [Converting between a List and a Set in Java](http://www.baeldung.com/convert-list-to-set-and-set-to-list) - [Convert a Map to an Array, List or Set in Java](http://www.baeldung.com/convert-map-values-to-array-list-set) +- [Java – Write to File](http://www.baeldung.com/java-write-to-file) From 1d24669cbb35963cc06791a3156613cb7ada28c4 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:26:06 +0200 Subject: [PATCH 038/142] Update README.md --- guava/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/guava/README.md b/guava/README.md index 8960b4676e..948087ff1e 100644 --- a/guava/README.md +++ b/guava/README.md @@ -7,7 +7,6 @@ - [Guava Collections Cookbook](http://www.baeldung.com/guava-collections) - [Guava Ordering Cookbook](http://www.baeldung.com/guava-order) - [Guava Functional Cookbook](http://www.baeldung.com/guava-functions-predicates) - - [Hamcrest Collections Cookbook](http://www.baeldung.com/hamcrest-collections-arrays) - - [Partition a List in Java](http://www.baeldung.com/java-list-split) +- [Filtering and Transforming Collections in Guava](http://www.baeldung.com/guava-filter-and-transform-a-collection) From 20d79082dd70ddf6118e0e0bf2155ef6821371d4 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:28:15 +0200 Subject: [PATCH 039/142] Update README.md --- guava/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guava/README.md b/guava/README.md index 948087ff1e..86771a740c 100644 --- a/guava/README.md +++ b/guava/README.md @@ -10,3 +10,4 @@ - [Hamcrest Collections Cookbook](http://www.baeldung.com/hamcrest-collections-arrays) - [Partition a List in Java](http://www.baeldung.com/java-list-split) - [Filtering and Transforming Collections in Guava](http://www.baeldung.com/guava-filter-and-transform-a-collection) +- [Guava – Join and Split Collections](http://www.baeldung.com/guava-joiner-and-splitter-tutorial) From d8bb9affec51c483f021dd8564eb6597e4952b33 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:29:23 +0200 Subject: [PATCH 040/142] Update README.md --- guava/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guava/README.md b/guava/README.md index 86771a740c..43acf04bd1 100644 --- a/guava/README.md +++ b/guava/README.md @@ -11,3 +11,4 @@ - [Partition a List in Java](http://www.baeldung.com/java-list-split) - [Filtering and Transforming Collections in Guava](http://www.baeldung.com/guava-filter-and-transform-a-collection) - [Guava – Join and Split Collections](http://www.baeldung.com/guava-joiner-and-splitter-tutorial) +- [Guava – Write to File, Read from File](http://www.baeldung.com/guava-write-to-file-read-from-file) From c2a226141b750871e580b8e77f25561e7456b6eb Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:33:13 +0200 Subject: [PATCH 041/142] Update README.md --- guava/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guava/README.md b/guava/README.md index 43acf04bd1..dfffe8bc07 100644 --- a/guava/README.md +++ b/guava/README.md @@ -12,3 +12,4 @@ - [Filtering and Transforming Collections in Guava](http://www.baeldung.com/guava-filter-and-transform-a-collection) - [Guava – Join and Split Collections](http://www.baeldung.com/guava-joiner-and-splitter-tutorial) - [Guava – Write to File, Read from File](http://www.baeldung.com/guava-write-to-file-read-from-file) +- [Guava – Lists](http://www.baeldung.com/guava-lists) From 30b74f9d04a3614061c4c13748a91fa4fae3c564 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:34:20 +0200 Subject: [PATCH 042/142] Update README.md --- guava/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guava/README.md b/guava/README.md index dfffe8bc07..7fdf28033d 100644 --- a/guava/README.md +++ b/guava/README.md @@ -13,3 +13,4 @@ - [Guava – Join and Split Collections](http://www.baeldung.com/guava-joiner-and-splitter-tutorial) - [Guava – Write to File, Read from File](http://www.baeldung.com/guava-write-to-file-read-from-file) - [Guava – Lists](http://www.baeldung.com/guava-lists) +- [Guava – Sets](http://www.baeldung.com/guava-sets) From 371ebf5db18d1495ba41b0cda5f7cc96b098d496 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:35:14 +0200 Subject: [PATCH 043/142] Update README.md --- guava/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guava/README.md b/guava/README.md index 7fdf28033d..28bcfeb912 100644 --- a/guava/README.md +++ b/guava/README.md @@ -14,3 +14,4 @@ - [Guava – Write to File, Read from File](http://www.baeldung.com/guava-write-to-file-read-from-file) - [Guava – Lists](http://www.baeldung.com/guava-lists) - [Guava – Sets](http://www.baeldung.com/guava-sets) +- [Guava – Maps](http://www.baeldung.com/guava-maps) From 86ca22330b3ee915b44032a0829de436b05ced9c Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:38:54 +0200 Subject: [PATCH 044/142] Update README.md --- mockito/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockito/README.md b/mockito/README.md index 5ecc5722b0..eb80042c4b 100644 --- a/mockito/README.md +++ b/mockito/README.md @@ -6,4 +6,4 @@ ### Relevant Articles: - [Mockito Verify Cookbook](http://www.baeldung.com/mockito-verify) - [Mockito When/Then Cookbook](http://www.baeldung.com/mockito-behavior) - +- [Mockito – Using Spies](http://www.baeldung.com/mockito-spy) From b3dff4d5de740eab323a390895a66d5c8fb2eb32 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:40:40 +0200 Subject: [PATCH 045/142] Update README.md --- spring-all/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-all/README.md b/spring-all/README.md index 4a3bd25077..baab7ec083 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -6,4 +6,5 @@ This project is used to replicate Spring Exceptions only. ### Relevant articles: -- [Properties with Spring](http://www.baeldung.com/2012/02/06/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage \ No newline at end of file +- [Properties with Spring](http://www.baeldung.com/2012/02/06/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage +- [Spring Profiles](http://www.baeldung.com/spring-profiles) From 731c0803c4e5833c619ea40aa1f78e8f1f86f87a Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:42:32 +0200 Subject: [PATCH 046/142] Update README.md --- mockito/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/mockito/README.md b/mockito/README.md index eb80042c4b..5e7cd19f78 100644 --- a/mockito/README.md +++ b/mockito/README.md @@ -7,3 +7,4 @@ - [Mockito Verify Cookbook](http://www.baeldung.com/mockito-verify) - [Mockito When/Then Cookbook](http://www.baeldung.com/mockito-behavior) - [Mockito – Using Spies](http://www.baeldung.com/mockito-spy) +- [Mockito – @Mock, @Spy, @Captor and @InjectMocks](http://www.baeldung.com/mockito-annotations) From cfc4d69a88218b4a44db4a52fb2d1c23963c6641 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:44:18 +0200 Subject: [PATCH 047/142] Update README.md --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 6db2b370f6..9a7c0d3776 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -11,3 +11,4 @@ - [Converting between a List and a Set in Java](http://www.baeldung.com/convert-list-to-set-and-set-to-list) - [Convert a Map to an Array, List or Set in Java](http://www.baeldung.com/convert-map-values-to-array-list-set) - [Java – Write to File](http://www.baeldung.com/java-write-to-file) +- [Java Scanner](http://www.baeldung.com/java-scanner) From 32f6d8ab6c4776853fd3bc29c5a334fd5bd481ca Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:45:35 +0200 Subject: [PATCH 048/142] Update README.md --- httpclient/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/httpclient/README.md b/httpclient/README.md index b9dd431500..1cf788287c 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -15,3 +15,4 @@ - [HttpClient – Set Custom Header](http://www.baeldung.com/httpclient-custom-http-header) - [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) - [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload) +- [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial) From e2de29e24ba0c8b422d0a4ad9c50658898b10b6e Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:47:00 +0200 Subject: [PATCH 049/142] Update README.md --- core-java-8/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-8/README.md b/core-java-8/README.md index 9bb6bb811c..f957b90799 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -3,4 +3,5 @@ ## Core Java 8 Cookbooks and Examples ### Relevant Articles: -// - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) +// - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) +// - [Java – Directory Size](http://www.baeldung.com/java-folder-size) From 68aa809456ac772c98b0da813400d346926b9fd8 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:47:21 +0200 Subject: [PATCH 050/142] Update README.md --- core-java-8/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-8/README.md b/core-java-8/README.md index f957b90799..e3fa3f9848 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -4,4 +4,4 @@ ### Relevant Articles: // - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) -// - [Java – Directory Size](http://www.baeldung.com/java-folder-size) +- [Java – Directory Size](http://www.baeldung.com/java-folder-size) From a8165f78fece34a7c572208f65497dda37c4473b Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:48:14 +0200 Subject: [PATCH 051/142] Update README.md --- core-java-8/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-8/README.md b/core-java-8/README.md index e3fa3f9848..f957b90799 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -4,4 +4,4 @@ ### Relevant Articles: // - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) -- [Java – Directory Size](http://www.baeldung.com/java-folder-size) +// - [Java – Directory Size](http://www.baeldung.com/java-folder-size) From 06f00f1cb166492332794ce4aabd1fd1a7521b33 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:48:29 +0200 Subject: [PATCH 052/142] Update README.md --- core-java-8/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-8/README.md b/core-java-8/README.md index f957b90799..e3fa3f9848 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -4,4 +4,4 @@ ### Relevant Articles: // - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) -// - [Java – Directory Size](http://www.baeldung.com/java-folder-size) +- [Java – Directory Size](http://www.baeldung.com/java-folder-size) From d9f9436f758683edd57b5d54b9b1605c964fc9b8 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:50:49 +0200 Subject: [PATCH 053/142] Update README.md --- spring-security-login-and-registration/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index 1638e82756..a5a9701ff8 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -6,7 +6,7 @@ ### Relevant Articles: - [Spring Security Registration Tutorial](http://www.baeldung.com/spring-security-registration) - [The Registration Process With Spring Security](http://www.baeldung.com/registration-with-spring-mvc-and-spring-security) - +- [Registration – Activate a New Account by Email](http://www.baeldung.com/registration-verify-user-by-email) ### Build the Project From d12e115d0bf5cf9736f8aef516c42adbe51a0f28 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:53:05 +0200 Subject: [PATCH 054/142] Update README.md --- jackson/README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/jackson/README.md b/jackson/README.md index 539cb34761..bb19fc7f77 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -4,9 +4,8 @@ ### Relevant Articles: - [Jackson Ignore Properties on Marshalling](http://www.baeldung.com/jackson-ignore-properties-on-serialization) -- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array) +- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array) - [Jackson Unmarshalling json with Unknown Properties](http://www.baeldung.com/jackson-deserialize-json-unknown-properties) -- [Jackson – Custom Serializer](http://www.baeldung.com/jackson-custom-serialization) -- [Jackson – Custom Deserializer](http://www.baeldung.com/jackson-deserialization) - - +- [Jackson – Custom Serializer](http://www.baeldung.com/jackson-custom-serialization) +- [Jackson – Custom Deserializer](http://www.baeldung.com/jackson-deserialization) +- [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception) From 9877e0008b0f1b7ea2fea271e9c5f661985e86dd Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Mon, 8 Feb 2016 12:54:36 +0200 Subject: [PATCH 055/142] Update README.md --- jackson/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson/README.md b/jackson/README.md index bb19fc7f77..046c6b6cfb 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -9,3 +9,4 @@ - [Jackson – Custom Serializer](http://www.baeldung.com/jackson-custom-serialization) - [Jackson – Custom Deserializer](http://www.baeldung.com/jackson-deserialization) - [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception) +- [Jackson Date](http://www.baeldung.com/jackson-serialize-dates) From c3ef41a10ddf15cc2e919272334fe666579863da Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Mon, 8 Feb 2016 14:00:11 +0100 Subject: [PATCH 056/142] CleanUp and reformatting Code; dependency fix in pom.xml --- RestEasy Example/pom.xml | 147 +++++++----------- .../baeldung/client/ServicesInterface.java | 15 +- .../main/java/com/baeldung/model/Movie.java | 56 ++----- .../com/baeldung/server/MovieCrudService.java | 49 +++--- .../WEB-INF/jboss-deployment-structure.xml | 22 +-- .../src/main/webapp/WEB-INF/web.xml | 14 +- .../baeldung/server/RestEasyClientTest.java | 23 ++- .../com/baeldung/server/movies/batman.json | 2 +- .../baeldung/server/movies/transformer.json | 2 +- 9 files changed, 125 insertions(+), 205 deletions(-) diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 9c890da2b7..ec9e87b0d1 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -1,104 +1,77 @@ - - 4.0.0 + + 4.0.0 - com.baeldung - resteasy-tutorial - 1.0 - war + com.baeldung + resteasy-tutorial + 1.0 + war - - - jboss - http://repository.jboss.org/nexus/content/groups/public/ - - + + 3.0.14.Final + - - 3.0.14.Final - runtime - + + RestEasyTutorial + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + - - RestEasyTutorial - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - + - + - - org.jboss.resteasy - jaxrs-api - 3.0.12.Final - ${resteasy.scope} - - - - org.jboss.resteasy - resteasy-servlet-initializer - ${resteasy.version} - ${resteasy.scope} - - - jboss-jaxrs-api_2.0_spec - org.jboss.spec.javax.ws.rs - - - - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - ${resteasy.scope} - + + org.jboss.resteasy + resteasy-servlet-initializer + ${resteasy.version} + - - javax.ws.rs - javax.ws.rs-api - 2.0.1 - + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + - - org.jboss.resteasy - resteasy-jackson-provider - ${resteasy.version} - ${resteasy.scope} - + - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - ${resteasy.scope} - + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + - + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + - - junit - junit - 4.4 - + - - commons-io - commons-io - 2.4 - + + junit + junit + 4.4 + + + + commons-io + commons-io + 2.4 + + + - \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 3c8d6abc00..3d03c16faf 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -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 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); - - } diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 7590f10487..5aade4591a 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -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; @@ -212,37 +191,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; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index bbb3b1e953..6a0699874a 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -13,78 +13,71 @@ import java.util.stream.Collectors; @Path("/movies") public class MovieCrudService { - private Map inventory = new HashMap(); - + private Map inventory = new HashMap(); @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 listMovies(){ + @Produces({ "application/json" }) + public List listMovies() { return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 84d75934a7..7879603d19 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -1,16 +1,16 @@ - - - - + + + + - - - - - + + + + + - - + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index 1e7f64004d..d5f00293f4 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -1,13 +1,13 @@ + 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"> - RestEasy Example + RestEasy Example - - resteasy.servlet.mapping.prefix - /rest - + + resteasy.servlet.mapping.prefix + /rest + \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index faa39e0199..3760ae2415 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -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()); } } \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json index 28061d5bf9..173901c948 100644 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json @@ -16,7 +16,7 @@ "metascore": "66", "imdbRating": "7.6", "imdbVotes": "256,000", - "imdbID": "tt0096895", + "imdbId": "tt0096895", "type": "movie", "response": "True" } \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json index a3b033a8ba..a4fd061a82 100644 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json @@ -16,7 +16,7 @@ "metascore": "61", "imdbRating": "7.1", "imdbVotes": "492,225", - "imdbID": "tt0418279", + "imdbId": "tt0418279", "type": "movie", "response": "True" } \ No newline at end of file From d362112a31f1c283556f94f2a470eed1053dbdd6 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Mon, 8 Feb 2016 16:08:15 +0100 Subject: [PATCH 057/142] CleanUp and reformatting Code. --- .../src/main/java/com/baeldung/server/MovieCrudService.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 6a0699874a..b7f3215f3f 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -26,7 +26,6 @@ public class MovieCrudService { return inventory.get(imdbId); } else return null; - } @POST @@ -41,7 +40,6 @@ public class MovieCrudService { } inventory.put(movie.getImdbId(), movie); - return Response.status(Response.Status.CREATED).build(); } @@ -55,9 +53,9 @@ public class MovieCrudService { 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); return Response.status(Response.Status.OK).build(); - } @DELETE @@ -80,7 +78,6 @@ public class MovieCrudService { public List listMovies() { return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); - } } From ae772727ce8e66289c6e883c22335d17fbdbdc43 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sat, 30 Jan 2016 17:48:56 +0100 Subject: [PATCH 058/142] RestEasy Tutorial, CRUD Services example --- RestEasy Example/pom.xml | 91 +++ .../src/main/java/com/baeldung/Movie.java | 535 ++++++++++++++++++ .../baeldung/client/ServicesInterface.java | 44 ++ .../server/service/MovieCrudService.java | 94 +++ .../server/service/RestEasyServices.java | 40 ++ .../src/main/resources/schema1.xsd | 29 + .../main/webapp/WEB-INF/classes/logback.xml | 3 + .../WEB-INF/jboss-deployment-structure.xml | 16 + .../src/main/webapp/WEB-INF/jboss-web.xml | 4 + .../src/main/webapp/WEB-INF/web.xml | 51 ++ .../com/baeldung/server/RestEasyClient.java | 50 ++ .../resources/server/movies/transformer.json | 22 + 12 files changed, 979 insertions(+) create mode 100644 RestEasy Example/pom.xml create mode 100644 RestEasy Example/src/main/java/com/baeldung/Movie.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java create mode 100644 RestEasy Example/src/main/resources/schema1.xsd create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/web.xml create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/resources/server/movies/transformer.json diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml new file mode 100644 index 0000000000..b16c5e8267 --- /dev/null +++ b/RestEasy Example/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + com.baeldung + resteasy-tutorial + 1.0 + war + + + + jboss + http://repository.jboss.org/nexus/content/groups/public/ + + + + + 3.0.14.Final + runtime + + + + RestEasyTutorial + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + org.jboss.resteasy + jaxrs-api + 3.0.12.Final + ${resteasy.scope} + + + + org.jboss.resteasy + resteasy-servlet-initializer + ${resteasy.version} + ${resteasy.scope} + + + jboss-jaxrs-api_2.0_spec + org.jboss.spec.javax.ws.rs + + + + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + ${resteasy.scope} + + + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + + + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + ${resteasy.scope} + + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + ${resteasy.scope} + + + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/Movie.java new file mode 100644 index 0000000000..c0041d2e95 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/Movie.java @@ -0,0 +1,535 @@ + +package com.baeldung; + +import javax.xml.bind.annotation.XmlAccessType; +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" +}) +public class Movie { + + protected String actors; + protected String awards; + protected String country; + protected String director; + protected String genre; + protected String imdbID; + protected String imdbRating; + protected String imdbVotes; + protected String language; + protected String metascore; + protected String plot; + protected String poster; + protected String rated; + protected String released; + protected String response; + protected String runtime; + protected String title; + protected String type; + protected String writer; + protected String year; + + /** + * Recupera il valore della propriet� actors. + * + * @return + * possible object is + * {@link String } + * + */ + public String getActors() { + return actors; + } + + /** + * Imposta il valore della propriet� actors. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setActors(String value) { + this.actors = value; + } + + /** + * Recupera il valore della propriet� awards. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAwards() { + return awards; + } + + /** + * Imposta il valore della propriet� awards. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAwards(String value) { + this.awards = value; + } + + /** + * Recupera il valore della propriet� country. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCountry() { + return country; + } + + /** + * Imposta il valore della propriet� country. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCountry(String value) { + this.country = value; + } + + /** + * Recupera il valore della propriet� director. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDirector() { + return director; + } + + /** + * Imposta il valore della propriet� director. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDirector(String value) { + this.director = value; + } + + /** + * Recupera il valore della propriet� genre. + * + * @return + * possible object is + * {@link String } + * + */ + public String getGenre() { + return genre; + } + + /** + * Imposta il valore della propriet� genre. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setGenre(String value) { + this.genre = value; + } + + /** + * Recupera il valore della propriet� imdbID. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbID() { + return imdbID; + } + + /** + * Imposta il valore della propriet� imdbID. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbID(String value) { + this.imdbID = value; + } + + /** + * Recupera il valore della propriet� imdbRating. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbRating() { + return imdbRating; + } + + /** + * Imposta il valore della propriet� imdbRating. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbRating(String value) { + this.imdbRating = value; + } + + /** + * Recupera il valore della propriet� imdbVotes. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbVotes() { + return imdbVotes; + } + + /** + * Imposta il valore della propriet� imdbVotes. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbVotes(String value) { + this.imdbVotes = value; + } + + /** + * Recupera il valore della propriet� language. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLanguage() { + return language; + } + + /** + * Imposta il valore della propriet� language. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLanguage(String value) { + this.language = value; + } + + /** + * Recupera il valore della propriet� metascore. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMetascore() { + return metascore; + } + + /** + * Imposta il valore della propriet� metascore. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMetascore(String value) { + this.metascore = value; + } + + /** + * Recupera il valore della propriet� plot. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPlot() { + return plot; + } + + /** + * Imposta il valore della propriet� plot. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPlot(String value) { + this.plot = value; + } + + /** + * Recupera il valore della propriet� poster. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPoster() { + return poster; + } + + /** + * Imposta il valore della propriet� poster. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPoster(String value) { + this.poster = value; + } + + /** + * Recupera il valore della propriet� rated. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRated() { + return rated; + } + + /** + * Imposta il valore della propriet� rated. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRated(String value) { + this.rated = value; + } + + /** + * Recupera il valore della propriet� released. + * + * @return + * possible object is + * {@link String } + * + */ + public String getReleased() { + return released; + } + + /** + * Imposta il valore della propriet� released. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setReleased(String value) { + this.released = value; + } + + /** + * Recupera il valore della propriet� response. + * + * @return + * possible object is + * {@link String } + * + */ + public String getResponse() { + return response; + } + + /** + * Imposta il valore della propriet� response. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setResponse(String value) { + this.response = value; + } + + /** + * Recupera il valore della propriet� runtime. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRuntime() { + return runtime; + } + + /** + * Imposta il valore della propriet� runtime. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRuntime(String value) { + this.runtime = value; + } + + /** + * Recupera il valore della propriet� title. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Imposta il valore della propriet� title. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Recupera il valore della propriet� type. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Imposta il valore della propriet� type. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Recupera il valore della propriet� writer. + * + * @return + * possible object is + * {@link String } + * + */ + public String getWriter() { + return writer; + } + + /** + * Imposta il valore della propriet� writer. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setWriter(String value) { + this.writer = value; + } + + /** + * Recupera il valore della propriet� year. + * + * @return + * possible object is + * {@link String } + * + */ + public String getYear() { + return year; + } + + /** + * Imposta il valore della propriet� year. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setYear(String value) { + this.year = value; + } + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java new file mode 100644 index 0000000000..53e88961be --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -0,0 +1,44 @@ +package com.baeldung.client; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + + +public interface ServicesInterface { + + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + + + @POST + @Path("/addmovie") + @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Response addMovie(Movie movie); + + + @PUT + @Path("/updatemovie") + @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Response updateMovie(Movie movie); + + + @DELETE + @Path("/deletemovie") + Response deleteMovie(@QueryParam("imdbID") String imdbID); + + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java new file mode 100644 index 0000000000..d1973e7037 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java @@ -0,0 +1,94 @@ +package com.baeldung.server.service; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@Path("/movies") +public class MovieCrudService { + + + private Map inventory = new HashMap(); + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ + + System.out.println("*** Calling getinfo ***"); + + Movie movie=new Movie(); + movie.setImdbID(imdbID); + return movie; + } + + @POST + @Path("/addmovie") + @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(); + } + 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){ + + 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(); + } + inventory.put(movie.getImdbID(),movie); + return Response.status(Response.Status.OK).build(); + + } + + + @DELETE + @Path("/deletemovie") + 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(); + } + + inventory.remove(imdbID); + return Response.status(Response.Status.OK).build(); + } + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + public List listMovies(){ + + return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); + + } + + + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java new file mode 100644 index 0000000000..16b6200ad1 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java @@ -0,0 +1,40 @@ +package com.baeldung.server.service; + + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Created by Admin on 29/01/2016. + */ + + + +@ApplicationPath("/rest") +public class RestEasyServices extends Application { + + private Set singletons = new HashSet(); + + public RestEasyServices() { + singletons.add(new MovieCrudService()); + } + + @Override + public Set getSingletons() { + return singletons; + } + + @Override + public Set> getClasses() { + return super.getClasses(); + } + + @Override + public Map getProperties() { + return super.getProperties(); + } +} diff --git a/RestEasy Example/src/main/resources/schema1.xsd b/RestEasy Example/src/main/resources/schema1.xsd new file mode 100644 index 0000000000..0d74b7c366 --- /dev/null +++ b/RestEasy Example/src/main/resources/schema1.xsd @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml b/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml new file mode 100644 index 0000000000..d94e9f71ab --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000000..84d75934a7 --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000000..694bb71332 --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..c66d3b56ae --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,51 @@ + + + + RestEasy Example + + + + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap + + + + RestEasy Example + + + webAppRootKey + RestEasyExample + + + + + + resteasy.servlet.mapping.prefix + /rest + + + + + resteasy-servlet + + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher + + + javax.ws.rs.Application + com.baeldung.server.service.RestEasyServices + + + + + resteasy-servlet + /rest/* + + + + + index.html + + + + \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java new file mode 100644 index 0000000000..e711233979 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -0,0 +1,50 @@ +package com.baeldung.server; + +import com.baeldung.Movie; +import com.baeldung.client.ServicesInterface; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; + +import java.util.List; + +public class RestEasyClient { + + public static void main(String[] args) { + + Movie st = new Movie(); + st.setImdbID("12345"); + + /* + * Alternatively you can use this simple String to send + * instead of using a Student instance + * + * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; + */ + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + + ServicesInterface simple = target.proxy(ServicesInterface.class); + final List movies = simple.listMovies(); + + /* + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + + System.out.println("Server response : \n"); + System.out.println(response.readEntity(String.class)); + + response.close(); +*/ + } catch (Exception e) { + + e.printStackTrace(); + + } + } + +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/server/movies/transformer.json new file mode 100644 index 0000000000..2154868265 --- /dev/null +++ b/RestEasy Example/src/test/resources/server/movies/transformer.json @@ -0,0 +1,22 @@ +{ + "title": "Transformers", + "year": "2007", + "rated": "PG-13", + "released": "03 Jul 2007", + "runtime": "144 min", + "genre": "Action, Adventure, Sci-Fi", + "director": "Michael Bay", + "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", + "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", + "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", + "language": "English, Spanish", + "country": "USA", + "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", + "metascore": "61", + "imdbRating": "7.1", + "imdbVotes": "492,225", + "imdbID": "tt0418279", + "Type": "movie", + "response": "True" +} \ No newline at end of file From 09c853477edb3a0cb0f4154b6a8c9077f877ae02 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sat, 30 Jan 2016 20:39:28 +0100 Subject: [PATCH 059/142] Added testCase for List All Movies and Add a Movie --- RestEasy Example/pom.xml | 29 +++++ .../baeldung/client/ServicesInterface.java | 6 +- .../java/com/baeldung/{ => model}/Movie.java | 45 +++++++- .../{service => }/MovieCrudService.java | 5 +- .../{service => }/RestEasyServices.java | 2 +- .../com/baeldung/server/RestEasyClient.java | 104 ++++++++++++++---- .../com/baeldung/server/movies/batman.json | 22 ++++ .../baeldung}/server/movies/transformer.json | 2 +- 8 files changed, 184 insertions(+), 31 deletions(-) rename RestEasy Example/src/main/java/com/baeldung/{ => model}/Movie.java (86%) rename RestEasy Example/src/main/java/com/baeldung/server/{service => }/MovieCrudService.java (96%) rename RestEasy Example/src/main/java/com/baeldung/server/{service => }/RestEasyServices.java (95%) create mode 100644 RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json rename RestEasy Example/src/test/resources/{ => com/baeldung}/server/movies/transformer.json (99%) diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index b16c5e8267..8dabfc863b 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -85,6 +85,35 @@ ${resteasy.scope} + + + + junit + junit + 4.4 + + + + commons-io + commons-io + 2.4 + + + + com.fasterxml.jackson.core + jackson-core + 2.7.0 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.7.0 + + + + + diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 53e88961be..2585c32438 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -1,15 +1,13 @@ package com.baeldung.client; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; - +@Path("/movies") public interface ServicesInterface { diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java similarity index 86% rename from RestEasy Example/src/main/java/com/baeldung/Movie.java rename to RestEasy Example/src/main/java/com/baeldung/model/Movie.java index c0041d2e95..052ba081c1 100644 --- a/RestEasy Example/src/main/java/com/baeldung/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -1,5 +1,5 @@ -package com.baeldung; +package com.baeldung.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -532,4 +532,47 @@ public class Movie { this.year = value; } + @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 + '\'' + + '}'; + } + + @Override + public boolean equals(Object o) { + 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; + return title != null ? title.equals(movie.title) : movie.title == null; + + } + + @Override + public int hashCode() { + int result = imdbID != null ? imdbID.hashCode() : 0; + result = 31 * result + (title != null ? title.hashCode() : 0); + return result; + } } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java similarity index 96% rename from RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java rename to RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index d1973e7037..60e0121966 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -1,11 +1,10 @@ -package com.baeldung.server.service; +package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java similarity index 95% rename from RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java rename to RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java index 16b6200ad1..8c57d2c9b4 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java @@ -1,4 +1,4 @@ -package com.baeldung.server.service; +package com.baeldung.server; import javax.ws.rs.ApplicationPath; diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java index e711233979..c77f494862 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -1,49 +1,111 @@ package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import javax.naming.NamingException; +import javax.ws.rs.core.Link; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.List; +import java.util.Locale; public class RestEasyClient { - public static void main(String[] args) { - Movie st = new Movie(); - st.setImdbID("12345"); + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; - /* - * Alternatively you can use this simple String to send - * instead of using a Student instance - * - * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; - */ + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + @Test + public void testListAllMovies() { try { ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ServicesInterface simple = target.proxy(ServicesInterface.class); - final List movies = simple.listMovies(); + final Response moviesResponse = simple.addMovie(batmanMovie); - /* - if (response.getStatus() != 200) { + if (moviesResponse.getStatus() != 201) { + System.out.println(moviesResponse.readEntity(String.class)); throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); + + moviesResponse.getStatus()); } - System.out.println("Server response : \n"); - System.out.println(response.readEntity(String.class)); + moviesResponse.close(); - response.close(); -*/ } catch (Exception e) { - e.printStackTrace(); - } } diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json new file mode 100644 index 0000000000..28061d5bf9 --- /dev/null +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json @@ -0,0 +1,22 @@ +{ + "title": "Batman", + "year": "1989", + "rated": "PG-13", + "released": "23 Jun 1989", + "runtime": "126 min", + "genre": "Action, Adventure", + "director": "Tim Burton", + "writer": "Bob Kane (Batman characters), Sam Hamm (story), Sam Hamm (screenplay), Warren Skaaren (screenplay)", + "actors": "Michael Keaton, Jack Nicholson, Kim Basinger, Robert Wuhl", + "plot": "The Dark Knight of Gotham City begins his war on crime with his first major enemy being the clownishly homicidal Joker.", + "language": "English, French", + "country": "USA, UK", + "awards": "Won 1 Oscar. Another 9 wins & 22 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTYwNjAyODIyMF5BMl5BanBnXkFtZTYwNDMwMDk2._V1_SX300.jpg", + "metascore": "66", + "imdbRating": "7.6", + "imdbVotes": "256,000", + "imdbID": "tt0096895", + "type": "movie", + "response": "True" +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json similarity index 99% rename from RestEasy Example/src/test/resources/server/movies/transformer.json rename to RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json index 2154868265..a3b033a8ba 100644 --- a/RestEasy Example/src/test/resources/server/movies/transformer.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json @@ -17,6 +17,6 @@ "imdbRating": "7.1", "imdbVotes": "492,225", "imdbID": "tt0418279", - "Type": "movie", + "type": "movie", "response": "True" } \ No newline at end of file From 6263054087798e2bf302a2f72f231616b1c5488e Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sun, 31 Jan 2016 11:05:11 +0100 Subject: [PATCH 060/142] Added testCase for all Services --- RestEasy Example/pom.xml | 15 -- .../baeldung/client/ServicesInterface.java | 10 +- .../com/baeldung/server/MovieCrudService.java | 15 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- .../com/baeldung/server/RestEasyClient.java | 112 ----------- .../baeldung/server/RestEasyClientTest.java | 189 ++++++++++++++++++ 6 files changed, 206 insertions(+), 137 deletions(-) delete mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 8dabfc863b..6935238d91 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -99,21 +99,6 @@ 2.4 - - com.fasterxml.jackson.core - jackson-core - 2.7.0 - - - - com.fasterxml.jackson.core - jackson-annotations - 2.7.0 - - - - - diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 2585c32438..7efed546d8 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -17,6 +17,12 @@ public interface ServicesInterface { Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -34,9 +40,5 @@ public interface ServicesInterface { Response deleteMovie(@QueryParam("imdbID") String imdbID); - @GET - @Path("/listmovies") - @Produces({"application/json"}) - List listMovies(); } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 60e0121966..18366e2faa 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -18,18 +18,21 @@ public class MovieCrudService { private Map inventory = new HashMap(); + @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ - System.out.println("*** Calling getinfo ***"); + System.out.println("*** Calling getinfo for a given ImdbID***"); + + if(inventory.containsKey(imdbID)){ + return inventory.get(imdbID); + }else return null; - Movie movie=new Movie(); - movie.setImdbID(imdbID); - return movie; } + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -41,6 +44,7 @@ public class MovieCrudService { return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is Already in the database.").build(); } + inventory.put(movie.getImdbID(),movie); return Response.status(Response.Status.CREATED).build(); @@ -54,7 +58,7 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + if (null==inventory.get(movie.getImdbID())){ return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is not in the database.\nUnable to Update").build(); } @@ -79,6 +83,7 @@ public class MovieCrudService { return Response.status(Response.Status.OK).build(); } + @GET @Path("/listmovies") @Produces({"application/json"}) diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index c66d3b56ae..ab3bc1aa83 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -33,7 +33,7 @@ javax.ws.rs.Application - com.baeldung.server.service.RestEasyServices + com.baeldung.server.RestEasyServices diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java deleted file mode 100644 index c77f494862..0000000000 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.baeldung.server; - -import com.baeldung.model.Movie; -import com.baeldung.client.ServicesInterface; -import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.naming.NamingException; -import javax.ws.rs.core.Link; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -public class RestEasyClient { - - - Movie transformerMovie=null; - Movie batmanMovie=null; - ObjectMapper jsonMapper=null; - - @BeforeClass - public static void loadMovieInventory(){ - - - - } - - @Before - public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - - - 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); - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { - String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { - String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); - - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - } - - @Test - public void testListAllMovies() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - - - @Test - public void testAddMovie() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - - ServicesInterface simple = target.proxy(ServicesInterface.class); - final Response moviesResponse = simple.addMovie(batmanMovie); - - if (moviesResponse.getStatus() != 201) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " - + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java new file mode 100644 index 0000000000..fb4205bcd7 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -0,0 +1,189 @@ +package com.baeldung.server; + +import com.baeldung.model.Movie; +import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.naming.NamingException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Locale; + +public class RestEasyClientTest { + + + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; + + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + + @Test + public void testListAllMovies() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testMovieByImdbID() { + + String transformerImdbId="tt0418279"; + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + + final Movie movies = simple.movieByImdbID(transformerImdbId); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(transformerMovie); + + if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { + //System.out.println(moviesResponse.readEntity(String.class)); + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testDeleteMovie() { + + String transformerImdbId="tt0418279"; + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.deleteMovie(transformerImdbId); + moviesResponse.close(); + + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println(moviesResponse.readEntity(String.class)); + throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testUpdateMovie() { + + try { + + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + batmanMovie.setImdbVotes("300,000"); + moviesResponse = simple.updateMovie(batmanMovie); + + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + //System.out.println(moviesResponse.readEntity(String.class)); + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file From c57578dba5d51ed62541518498550b6431b71cf6 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:29:30 +0100 Subject: [PATCH 061/142] Minor Bugfix --- .../baeldung/client/ServicesInterface.java | 4 +- .../main/java/com/baeldung/model/Movie.java | 22 +-- .../com/baeldung/server/MovieCrudService.java | 12 +- .../src/main/webapp/WEB-INF/web.xml | 37 +---- .../java/baeldung/client/RestEasyClient.java | 7 + .../baeldung/server/RestEasyClientTest.java | 149 +++++++----------- 6 files changed, 81 insertions(+), 150 deletions(-) create mode 100644 RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 7efed546d8..749cabc757 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -14,7 +14,7 @@ public interface ServicesInterface { @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) - Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + Movie movieByImdbId(@QueryParam("imdbId") String imdbId); @GET @@ -37,7 +37,7 @@ public interface ServicesInterface { @DELETE @Path("/deletemovie") - Response deleteMovie(@QueryParam("imdbID") String imdbID); + Response deleteMovie(@QueryParam("imdbId") String imdbID); diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 052ba081c1..a2b2bd5250 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType; "country", "director", "genre", - "imdbID", + "imdbId", "imdbRating", "imdbVotes", "language", @@ -36,7 +36,7 @@ public class Movie { protected String country; protected String director; protected String genre; - protected String imdbID; + protected String imdbId; protected String imdbRating; protected String imdbVotes; protected String language; @@ -173,27 +173,27 @@ public class Movie { } /** - * Recupera il valore della propriet� imdbID. + * Recupera il valore della propriet� imdbId. * * @return * possible object is * {@link String } * */ - public String getImdbID() { - return imdbID; + public String getImdbId() { + return imdbId; } /** - * Imposta il valore della propriet� imdbID. + * Imposta il valore della propriet� imdbId. * * @param value * allowed object is * {@link String } * */ - public void setImdbID(String value) { - this.imdbID = value; + public void setImdbId(String value) { + this.imdbId = value; } /** @@ -540,7 +540,7 @@ public class Movie { ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + - ", imdbID='" + imdbID + '\'' + + ", imdbId='" + imdbId + '\'' + ", imdbRating='" + imdbRating + '\'' + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + @@ -564,14 +564,14 @@ public class Movie { 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; } @Override public int hashCode() { - int result = imdbID != null ? imdbID.hashCode() : 0; + int result = imdbId != null ? imdbId.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); return result; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 18366e2faa..29226aa0e0 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -22,7 +22,7 @@ public class MovieCrudService { @GET @Path("/getinfo") @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***"); @@ -40,12 +40,12 @@ public class MovieCrudService { System.out.println("*** Calling addMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + 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(); } @@ -58,11 +58,11 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null==inventory.get(movie.getImdbID())){ + 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(); } @@ -70,7 +70,7 @@ public class MovieCrudService { @DELETE @Path("/deletemovie") - public Response deleteMovie(@QueryParam("imdbID") String imdbID){ + public Response deleteMovie(@QueryParam("imdbId") String imdbID){ System.out.println("*** Calling deleteMovie ***"); diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index ab3bc1aa83..f70fdf7975 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -5,47 +5,12 @@ RestEasy Example - - - org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap - - - - RestEasy Example - - - webAppRootKey - RestEasyExample - - - - + resteasy.servlet.mapping.prefix /rest - - resteasy-servlet - - org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher - - - javax.ws.rs.Application - com.baeldung.server.RestEasyServices - - - - - resteasy-servlet - /rest/* - - - - - index.html - - \ No newline at end of file diff --git a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java new file mode 100644 index 0000000000..b474b3d4f8 --- /dev/null +++ b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java @@ -0,0 +1,7 @@ +package baeldung.client; + +/** + * Created by Admin on 29/01/2016. + */ +public class RestEasyClient { +} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index fb4205bcd7..b6a2e2a0c1 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -1,7 +1,7 @@ package com.baeldung.server; -import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import com.baeldung.model.Movie; import org.apache.commons.io.IOUtils; import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; @@ -9,7 +9,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import javax.naming.NamingException; @@ -23,22 +22,13 @@ import java.util.Locale; public class RestEasyClientTest { - Movie transformerMovie=null; Movie batmanMovie=null; ObjectMapper jsonMapper=null; - @BeforeClass - public static void loadMovieInventory(){ - - - - } - @Before public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - 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); @@ -57,133 +47,102 @@ public class RestEasyClientTest { batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException("Test is going to die ...", e); } - } - @Test public void testListAllMovies() { - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } + List movies = simple.listMovies(); + System.out.println(movies); } - @Test - public void testMovieByImdbID() { + public void testMovieByImdbId() { String transformerImdbId="tt0418279"; - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); - final Movie movies = simple.movieByImdbID(transformerImdbId); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } + Movie movies = simple.movieByImdbId(transformerImdbId); + System.out.println(movies); } @Test public void testAddMovie() { - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(transformerMovie); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(transformerMovie); - if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { - //System.out.println(moviesResponse.readEntity(String.class)); - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } @Test - public void testDeleteMovie() { + public void testDeleteMovi1e() { - String transformerImdbId="tt0418279"; + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.deleteMovie(batmanMovie.getImdbId()); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.deleteMovie(transformerImdbId); - moviesResponse.close(); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println(moviesResponse.readEntity(String.class)); + throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } @Test public void testUpdateMovie() { - try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + batmanMovie.setImdbVotes("300,000"); + moviesResponse = simple.updateMovie(batmanMovie); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - batmanMovie.setImdbVotes("300,000"); - moviesResponse = simple.updateMovie(batmanMovie); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - //System.out.println(moviesResponse.readEntity(String.class)); - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } } \ No newline at end of file From 9d3f34d6367e623aac467de603eba275f878e580 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sat, 30 Jan 2016 17:48:56 +0100 Subject: [PATCH 062/142] RestEasy Tutorial, CRUD Services example --- .../src/main/java/com/baeldung/Movie.java | 535 ++++++++++++++++++ .../server/service/MovieCrudService.java | 94 +++ .../server/service/RestEasyServices.java | 40 ++ .../com/baeldung/server/RestEasyClient.java | 50 ++ .../resources/server/movies/transformer.json | 22 + 5 files changed, 741 insertions(+) create mode 100644 RestEasy Example/src/main/java/com/baeldung/Movie.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/resources/server/movies/transformer.json diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/Movie.java new file mode 100644 index 0000000000..c0041d2e95 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/Movie.java @@ -0,0 +1,535 @@ + +package com.baeldung; + +import javax.xml.bind.annotation.XmlAccessType; +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" +}) +public class Movie { + + protected String actors; + protected String awards; + protected String country; + protected String director; + protected String genre; + protected String imdbID; + protected String imdbRating; + protected String imdbVotes; + protected String language; + protected String metascore; + protected String plot; + protected String poster; + protected String rated; + protected String released; + protected String response; + protected String runtime; + protected String title; + protected String type; + protected String writer; + protected String year; + + /** + * Recupera il valore della propriet� actors. + * + * @return + * possible object is + * {@link String } + * + */ + public String getActors() { + return actors; + } + + /** + * Imposta il valore della propriet� actors. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setActors(String value) { + this.actors = value; + } + + /** + * Recupera il valore della propriet� awards. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAwards() { + return awards; + } + + /** + * Imposta il valore della propriet� awards. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAwards(String value) { + this.awards = value; + } + + /** + * Recupera il valore della propriet� country. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCountry() { + return country; + } + + /** + * Imposta il valore della propriet� country. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCountry(String value) { + this.country = value; + } + + /** + * Recupera il valore della propriet� director. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDirector() { + return director; + } + + /** + * Imposta il valore della propriet� director. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDirector(String value) { + this.director = value; + } + + /** + * Recupera il valore della propriet� genre. + * + * @return + * possible object is + * {@link String } + * + */ + public String getGenre() { + return genre; + } + + /** + * Imposta il valore della propriet� genre. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setGenre(String value) { + this.genre = value; + } + + /** + * Recupera il valore della propriet� imdbID. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbID() { + return imdbID; + } + + /** + * Imposta il valore della propriet� imdbID. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbID(String value) { + this.imdbID = value; + } + + /** + * Recupera il valore della propriet� imdbRating. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbRating() { + return imdbRating; + } + + /** + * Imposta il valore della propriet� imdbRating. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbRating(String value) { + this.imdbRating = value; + } + + /** + * Recupera il valore della propriet� imdbVotes. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbVotes() { + return imdbVotes; + } + + /** + * Imposta il valore della propriet� imdbVotes. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbVotes(String value) { + this.imdbVotes = value; + } + + /** + * Recupera il valore della propriet� language. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLanguage() { + return language; + } + + /** + * Imposta il valore della propriet� language. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLanguage(String value) { + this.language = value; + } + + /** + * Recupera il valore della propriet� metascore. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMetascore() { + return metascore; + } + + /** + * Imposta il valore della propriet� metascore. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMetascore(String value) { + this.metascore = value; + } + + /** + * Recupera il valore della propriet� plot. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPlot() { + return plot; + } + + /** + * Imposta il valore della propriet� plot. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPlot(String value) { + this.plot = value; + } + + /** + * Recupera il valore della propriet� poster. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPoster() { + return poster; + } + + /** + * Imposta il valore della propriet� poster. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPoster(String value) { + this.poster = value; + } + + /** + * Recupera il valore della propriet� rated. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRated() { + return rated; + } + + /** + * Imposta il valore della propriet� rated. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRated(String value) { + this.rated = value; + } + + /** + * Recupera il valore della propriet� released. + * + * @return + * possible object is + * {@link String } + * + */ + public String getReleased() { + return released; + } + + /** + * Imposta il valore della propriet� released. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setReleased(String value) { + this.released = value; + } + + /** + * Recupera il valore della propriet� response. + * + * @return + * possible object is + * {@link String } + * + */ + public String getResponse() { + return response; + } + + /** + * Imposta il valore della propriet� response. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setResponse(String value) { + this.response = value; + } + + /** + * Recupera il valore della propriet� runtime. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRuntime() { + return runtime; + } + + /** + * Imposta il valore della propriet� runtime. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRuntime(String value) { + this.runtime = value; + } + + /** + * Recupera il valore della propriet� title. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Imposta il valore della propriet� title. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Recupera il valore della propriet� type. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Imposta il valore della propriet� type. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Recupera il valore della propriet� writer. + * + * @return + * possible object is + * {@link String } + * + */ + public String getWriter() { + return writer; + } + + /** + * Imposta il valore della propriet� writer. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setWriter(String value) { + this.writer = value; + } + + /** + * Recupera il valore della propriet� year. + * + * @return + * possible object is + * {@link String } + * + */ + public String getYear() { + return year; + } + + /** + * Imposta il valore della propriet� year. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setYear(String value) { + this.year = value; + } + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java new file mode 100644 index 0000000000..d1973e7037 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java @@ -0,0 +1,94 @@ +package com.baeldung.server.service; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@Path("/movies") +public class MovieCrudService { + + + private Map inventory = new HashMap(); + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ + + System.out.println("*** Calling getinfo ***"); + + Movie movie=new Movie(); + movie.setImdbID(imdbID); + return movie; + } + + @POST + @Path("/addmovie") + @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(); + } + 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){ + + 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(); + } + inventory.put(movie.getImdbID(),movie); + return Response.status(Response.Status.OK).build(); + + } + + + @DELETE + @Path("/deletemovie") + 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(); + } + + inventory.remove(imdbID); + return Response.status(Response.Status.OK).build(); + } + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + public List listMovies(){ + + return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); + + } + + + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java new file mode 100644 index 0000000000..16b6200ad1 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java @@ -0,0 +1,40 @@ +package com.baeldung.server.service; + + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Created by Admin on 29/01/2016. + */ + + + +@ApplicationPath("/rest") +public class RestEasyServices extends Application { + + private Set singletons = new HashSet(); + + public RestEasyServices() { + singletons.add(new MovieCrudService()); + } + + @Override + public Set getSingletons() { + return singletons; + } + + @Override + public Set> getClasses() { + return super.getClasses(); + } + + @Override + public Map getProperties() { + return super.getProperties(); + } +} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java new file mode 100644 index 0000000000..e711233979 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -0,0 +1,50 @@ +package com.baeldung.server; + +import com.baeldung.Movie; +import com.baeldung.client.ServicesInterface; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; + +import java.util.List; + +public class RestEasyClient { + + public static void main(String[] args) { + + Movie st = new Movie(); + st.setImdbID("12345"); + + /* + * Alternatively you can use this simple String to send + * instead of using a Student instance + * + * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; + */ + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + + ServicesInterface simple = target.proxy(ServicesInterface.class); + final List movies = simple.listMovies(); + + /* + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + + System.out.println("Server response : \n"); + System.out.println(response.readEntity(String.class)); + + response.close(); +*/ + } catch (Exception e) { + + e.printStackTrace(); + + } + } + +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/server/movies/transformer.json new file mode 100644 index 0000000000..2154868265 --- /dev/null +++ b/RestEasy Example/src/test/resources/server/movies/transformer.json @@ -0,0 +1,22 @@ +{ + "title": "Transformers", + "year": "2007", + "rated": "PG-13", + "released": "03 Jul 2007", + "runtime": "144 min", + "genre": "Action, Adventure, Sci-Fi", + "director": "Michael Bay", + "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", + "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", + "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", + "language": "English, Spanish", + "country": "USA", + "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", + "metascore": "61", + "imdbRating": "7.1", + "imdbVotes": "492,225", + "imdbID": "tt0418279", + "Type": "movie", + "response": "True" +} \ No newline at end of file From fa973988fb4b4d6357eac6bcadf1f3ac4143605a Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sat, 30 Jan 2016 20:39:28 +0100 Subject: [PATCH 063/142] Added testCase for List All Movies and Add a Movie --- .../src/main/java/com/baeldung/Movie.java | 535 ------------------ .../main/java/com/baeldung/model/Movie.java | 22 +- .../com/baeldung/server/MovieCrudService.java | 25 +- .../server/service/MovieCrudService.java | 94 --- .../server/service/RestEasyServices.java | 40 -- .../com/baeldung/server/RestEasyClient.java | 104 +++- .../resources/server/movies/transformer.json | 22 - 7 files changed, 104 insertions(+), 738 deletions(-) delete mode 100644 RestEasy Example/src/main/java/com/baeldung/Movie.java delete mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java delete mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java delete mode 100644 RestEasy Example/src/test/resources/server/movies/transformer.json diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/Movie.java deleted file mode 100644 index c0041d2e95..0000000000 --- a/RestEasy Example/src/main/java/com/baeldung/Movie.java +++ /dev/null @@ -1,535 +0,0 @@ - -package com.baeldung; - -import javax.xml.bind.annotation.XmlAccessType; -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" -}) -public class Movie { - - protected String actors; - protected String awards; - protected String country; - protected String director; - protected String genre; - protected String imdbID; - protected String imdbRating; - protected String imdbVotes; - protected String language; - protected String metascore; - protected String plot; - protected String poster; - protected String rated; - protected String released; - protected String response; - protected String runtime; - protected String title; - protected String type; - protected String writer; - protected String year; - - /** - * Recupera il valore della propriet� actors. - * - * @return - * possible object is - * {@link String } - * - */ - public String getActors() { - return actors; - } - - /** - * Imposta il valore della propriet� actors. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setActors(String value) { - this.actors = value; - } - - /** - * Recupera il valore della propriet� awards. - * - * @return - * possible object is - * {@link String } - * - */ - public String getAwards() { - return awards; - } - - /** - * Imposta il valore della propriet� awards. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setAwards(String value) { - this.awards = value; - } - - /** - * Recupera il valore della propriet� country. - * - * @return - * possible object is - * {@link String } - * - */ - public String getCountry() { - return country; - } - - /** - * Imposta il valore della propriet� country. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setCountry(String value) { - this.country = value; - } - - /** - * Recupera il valore della propriet� director. - * - * @return - * possible object is - * {@link String } - * - */ - public String getDirector() { - return director; - } - - /** - * Imposta il valore della propriet� director. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setDirector(String value) { - this.director = value; - } - - /** - * Recupera il valore della propriet� genre. - * - * @return - * possible object is - * {@link String } - * - */ - public String getGenre() { - return genre; - } - - /** - * Imposta il valore della propriet� genre. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setGenre(String value) { - this.genre = value; - } - - /** - * Recupera il valore della propriet� imdbID. - * - * @return - * possible object is - * {@link String } - * - */ - public String getImdbID() { - return imdbID; - } - - /** - * Imposta il valore della propriet� imdbID. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setImdbID(String value) { - this.imdbID = value; - } - - /** - * Recupera il valore della propriet� imdbRating. - * - * @return - * possible object is - * {@link String } - * - */ - public String getImdbRating() { - return imdbRating; - } - - /** - * Imposta il valore della propriet� imdbRating. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setImdbRating(String value) { - this.imdbRating = value; - } - - /** - * Recupera il valore della propriet� imdbVotes. - * - * @return - * possible object is - * {@link String } - * - */ - public String getImdbVotes() { - return imdbVotes; - } - - /** - * Imposta il valore della propriet� imdbVotes. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setImdbVotes(String value) { - this.imdbVotes = value; - } - - /** - * Recupera il valore della propriet� language. - * - * @return - * possible object is - * {@link String } - * - */ - public String getLanguage() { - return language; - } - - /** - * Imposta il valore della propriet� language. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setLanguage(String value) { - this.language = value; - } - - /** - * Recupera il valore della propriet� metascore. - * - * @return - * possible object is - * {@link String } - * - */ - public String getMetascore() { - return metascore; - } - - /** - * Imposta il valore della propriet� metascore. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setMetascore(String value) { - this.metascore = value; - } - - /** - * Recupera il valore della propriet� plot. - * - * @return - * possible object is - * {@link String } - * - */ - public String getPlot() { - return plot; - } - - /** - * Imposta il valore della propriet� plot. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setPlot(String value) { - this.plot = value; - } - - /** - * Recupera il valore della propriet� poster. - * - * @return - * possible object is - * {@link String } - * - */ - public String getPoster() { - return poster; - } - - /** - * Imposta il valore della propriet� poster. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setPoster(String value) { - this.poster = value; - } - - /** - * Recupera il valore della propriet� rated. - * - * @return - * possible object is - * {@link String } - * - */ - public String getRated() { - return rated; - } - - /** - * Imposta il valore della propriet� rated. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setRated(String value) { - this.rated = value; - } - - /** - * Recupera il valore della propriet� released. - * - * @return - * possible object is - * {@link String } - * - */ - public String getReleased() { - return released; - } - - /** - * Imposta il valore della propriet� released. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setReleased(String value) { - this.released = value; - } - - /** - * Recupera il valore della propriet� response. - * - * @return - * possible object is - * {@link String } - * - */ - public String getResponse() { - return response; - } - - /** - * Imposta il valore della propriet� response. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setResponse(String value) { - this.response = value; - } - - /** - * Recupera il valore della propriet� runtime. - * - * @return - * possible object is - * {@link String } - * - */ - public String getRuntime() { - return runtime; - } - - /** - * Imposta il valore della propriet� runtime. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setRuntime(String value) { - this.runtime = value; - } - - /** - * Recupera il valore della propriet� title. - * - * @return - * possible object is - * {@link String } - * - */ - public String getTitle() { - return title; - } - - /** - * Imposta il valore della propriet� title. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setTitle(String value) { - this.title = value; - } - - /** - * Recupera il valore della propriet� type. - * - * @return - * possible object is - * {@link String } - * - */ - public String getType() { - return type; - } - - /** - * Imposta il valore della propriet� type. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setType(String value) { - this.type = value; - } - - /** - * Recupera il valore della propriet� writer. - * - * @return - * possible object is - * {@link String } - * - */ - public String getWriter() { - return writer; - } - - /** - * Imposta il valore della propriet� writer. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setWriter(String value) { - this.writer = value; - } - - /** - * Recupera il valore della propriet� year. - * - * @return - * possible object is - * {@link String } - * - */ - public String getYear() { - return year; - } - - /** - * Imposta il valore della propriet� year. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setYear(String value) { - this.year = value; - } - -} diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index a2b2bd5250..052ba081c1 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType; "country", "director", "genre", - "imdbId", + "imdbID", "imdbRating", "imdbVotes", "language", @@ -36,7 +36,7 @@ public class Movie { protected String country; protected String director; protected String genre; - protected String imdbId; + protected String imdbID; protected String imdbRating; protected String imdbVotes; protected String language; @@ -173,27 +173,27 @@ public class Movie { } /** - * Recupera il valore della propriet� imdbId. + * Recupera il valore della propriet� imdbID. * * @return * possible object is * {@link String } * */ - public String getImdbId() { - return imdbId; + public String getImdbID() { + return imdbID; } /** - * Imposta il valore della propriet� imdbId. + * Imposta il valore della propriet� imdbID. * * @param value * allowed object is * {@link String } * */ - public void setImdbId(String value) { - this.imdbId = value; + public void setImdbID(String value) { + this.imdbID = value; } /** @@ -540,7 +540,7 @@ public class Movie { ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + - ", imdbId='" + imdbId + '\'' + + ", imdbID='" + imdbID + '\'' + ", imdbRating='" + imdbRating + '\'' + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + @@ -564,14 +564,14 @@ public class Movie { 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; } @Override public int hashCode() { - int result = imdbId != null ? imdbId.hashCode() : 0; + int result = imdbID != null ? imdbID.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); return result; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 29226aa0e0..60e0121966 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -18,21 +18,18 @@ public class MovieCrudService { private Map inventory = new HashMap(); - @GET @Path("/getinfo") @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***"); - - if(inventory.containsKey(imdbID)){ - return inventory.get(imdbID); - }else return null; + System.out.println("*** Calling getinfo ***"); + Movie movie=new Movie(); + movie.setImdbID(imdbID); + return movie; } - @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -40,12 +37,11 @@ public class MovieCrudService { System.out.println("*** Calling addMovie ***"); - if (null!=inventory.get(movie.getImdbId())){ + 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(); } @@ -58,11 +54,11 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null==inventory.get(movie.getImdbId())){ + 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(); } @@ -70,7 +66,7 @@ public class MovieCrudService { @DELETE @Path("/deletemovie") - public Response deleteMovie(@QueryParam("imdbId") String imdbID){ + public Response deleteMovie(@QueryParam("imdbID") String imdbID){ System.out.println("*** Calling deleteMovie ***"); @@ -83,7 +79,6 @@ public class MovieCrudService { return Response.status(Response.Status.OK).build(); } - @GET @Path("/listmovies") @Produces({"application/json"}) diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java deleted file mode 100644 index d1973e7037..0000000000 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.baeldung.server.service; - -import com.baeldung.Movie; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - - -@Path("/movies") -public class MovieCrudService { - - - private Map inventory = new HashMap(); - - @GET - @Path("/getinfo") - @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) - public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ - - System.out.println("*** Calling getinfo ***"); - - Movie movie=new Movie(); - movie.setImdbID(imdbID); - return movie; - } - - @POST - @Path("/addmovie") - @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(); - } - 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){ - - 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(); - } - inventory.put(movie.getImdbID(),movie); - return Response.status(Response.Status.OK).build(); - - } - - - @DELETE - @Path("/deletemovie") - 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(); - } - - inventory.remove(imdbID); - return Response.status(Response.Status.OK).build(); - } - - @GET - @Path("/listmovies") - @Produces({"application/json"}) - public List listMovies(){ - - return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); - - } - - - -} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java deleted file mode 100644 index 16b6200ad1..0000000000 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.server.service; - - -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Created by Admin on 29/01/2016. - */ - - - -@ApplicationPath("/rest") -public class RestEasyServices extends Application { - - private Set singletons = new HashSet(); - - public RestEasyServices() { - singletons.add(new MovieCrudService()); - } - - @Override - public Set getSingletons() { - return singletons; - } - - @Override - public Set> getClasses() { - return super.getClasses(); - } - - @Override - public Map getProperties() { - return super.getProperties(); - } -} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java index e711233979..c77f494862 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -1,49 +1,111 @@ package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import javax.naming.NamingException; +import javax.ws.rs.core.Link; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.List; +import java.util.Locale; public class RestEasyClient { - public static void main(String[] args) { - Movie st = new Movie(); - st.setImdbID("12345"); + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; - /* - * Alternatively you can use this simple String to send - * instead of using a Student instance - * - * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; - */ + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + @Test + public void testListAllMovies() { try { ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ServicesInterface simple = target.proxy(ServicesInterface.class); - final List movies = simple.listMovies(); + final Response moviesResponse = simple.addMovie(batmanMovie); - /* - if (response.getStatus() != 200) { + if (moviesResponse.getStatus() != 201) { + System.out.println(moviesResponse.readEntity(String.class)); throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); + + moviesResponse.getStatus()); } - System.out.println("Server response : \n"); - System.out.println(response.readEntity(String.class)); + moviesResponse.close(); - response.close(); -*/ } catch (Exception e) { - e.printStackTrace(); - } } diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/server/movies/transformer.json deleted file mode 100644 index 2154868265..0000000000 --- a/RestEasy Example/src/test/resources/server/movies/transformer.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "title": "Transformers", - "year": "2007", - "rated": "PG-13", - "released": "03 Jul 2007", - "runtime": "144 min", - "genre": "Action, Adventure, Sci-Fi", - "director": "Michael Bay", - "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", - "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", - "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", - "language": "English, Spanish", - "country": "USA", - "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", - "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", - "metascore": "61", - "imdbRating": "7.1", - "imdbVotes": "492,225", - "imdbID": "tt0418279", - "Type": "movie", - "response": "True" -} \ No newline at end of file From 913f2908e0468550647ac32d61db4da23d7093a3 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sun, 31 Jan 2016 11:05:11 +0100 Subject: [PATCH 064/142] Added testCase for all Services --- .../baeldung/client/ServicesInterface.java | 6 + .../com/baeldung/server/MovieCrudService.java | 15 ++- .../com/baeldung/server/RestEasyClient.java | 112 ------------------ 3 files changed, 16 insertions(+), 117 deletions(-) delete mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 749cabc757..8898b83483 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -23,6 +23,12 @@ public interface ServicesInterface { List listMovies(); + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 60e0121966..18366e2faa 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -18,18 +18,21 @@ public class MovieCrudService { private Map inventory = new HashMap(); + @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ - System.out.println("*** Calling getinfo ***"); + System.out.println("*** Calling getinfo for a given ImdbID***"); + + if(inventory.containsKey(imdbID)){ + return inventory.get(imdbID); + }else return null; - Movie movie=new Movie(); - movie.setImdbID(imdbID); - return movie; } + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -41,6 +44,7 @@ public class MovieCrudService { return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is Already in the database.").build(); } + inventory.put(movie.getImdbID(),movie); return Response.status(Response.Status.CREATED).build(); @@ -54,7 +58,7 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + if (null==inventory.get(movie.getImdbID())){ return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is not in the database.\nUnable to Update").build(); } @@ -79,6 +83,7 @@ public class MovieCrudService { return Response.status(Response.Status.OK).build(); } + @GET @Path("/listmovies") @Produces({"application/json"}) diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java deleted file mode 100644 index c77f494862..0000000000 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.baeldung.server; - -import com.baeldung.model.Movie; -import com.baeldung.client.ServicesInterface; -import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.naming.NamingException; -import javax.ws.rs.core.Link; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -public class RestEasyClient { - - - Movie transformerMovie=null; - Movie batmanMovie=null; - ObjectMapper jsonMapper=null; - - @BeforeClass - public static void loadMovieInventory(){ - - - - } - - @Before - public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - - - 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); - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { - String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { - String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); - - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - } - - @Test - public void testListAllMovies() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - - - @Test - public void testAddMovie() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - - ServicesInterface simple = target.proxy(ServicesInterface.class); - final Response moviesResponse = simple.addMovie(batmanMovie); - - if (moviesResponse.getStatus() != 201) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " - + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file From 929a7d7483b6361f28ec19e8513ed7468f2686e8 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:29:30 +0100 Subject: [PATCH 065/142] Minor Bugfix --- .../baeldung/client/ServicesInterface.java | 6 ----- .../main/java/com/baeldung/model/Movie.java | 22 +++++++++---------- .../com/baeldung/server/MovieCrudService.java | 12 +++++----- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 8898b83483..749cabc757 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -23,12 +23,6 @@ public interface ServicesInterface { List listMovies(); - @GET - @Path("/listmovies") - @Produces({"application/json"}) - List listMovies(); - - @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 052ba081c1..a2b2bd5250 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType; "country", "director", "genre", - "imdbID", + "imdbId", "imdbRating", "imdbVotes", "language", @@ -36,7 +36,7 @@ public class Movie { protected String country; protected String director; protected String genre; - protected String imdbID; + protected String imdbId; protected String imdbRating; protected String imdbVotes; protected String language; @@ -173,27 +173,27 @@ public class Movie { } /** - * Recupera il valore della propriet� imdbID. + * Recupera il valore della propriet� imdbId. * * @return * possible object is * {@link String } * */ - public String getImdbID() { - return imdbID; + public String getImdbId() { + return imdbId; } /** - * Imposta il valore della propriet� imdbID. + * Imposta il valore della propriet� imdbId. * * @param value * allowed object is * {@link String } * */ - public void setImdbID(String value) { - this.imdbID = value; + public void setImdbId(String value) { + this.imdbId = value; } /** @@ -540,7 +540,7 @@ public class Movie { ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + - ", imdbID='" + imdbID + '\'' + + ", imdbId='" + imdbId + '\'' + ", imdbRating='" + imdbRating + '\'' + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + @@ -564,14 +564,14 @@ public class Movie { 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; } @Override public int hashCode() { - int result = imdbID != null ? imdbID.hashCode() : 0; + int result = imdbId != null ? imdbId.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); return result; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 18366e2faa..29226aa0e0 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -22,7 +22,7 @@ public class MovieCrudService { @GET @Path("/getinfo") @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***"); @@ -40,12 +40,12 @@ public class MovieCrudService { System.out.println("*** Calling addMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + 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(); } @@ -58,11 +58,11 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null==inventory.get(movie.getImdbID())){ + 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(); } @@ -70,7 +70,7 @@ public class MovieCrudService { @DELETE @Path("/deletemovie") - public Response deleteMovie(@QueryParam("imdbID") String imdbID){ + public Response deleteMovie(@QueryParam("imdbId") String imdbID){ System.out.println("*** Calling deleteMovie ***"); From bcad6811a346b82cb38c1a6cbe5d8fc7408450b8 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:39:35 +0100 Subject: [PATCH 066/142] Minor Bugfix --- .../main/java/com/baeldung/model/Movie.java | 321 +----------------- 1 file changed, 1 insertion(+), 320 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index a2b2bd5250..805ba95209 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -52,482 +52,163 @@ public class Movie { protected String writer; protected String year; - /** - * Recupera il valore della propriet� actors. - * - * @return - * possible object is - * {@link String } - * - */ + public String getActors() { return actors; } - /** - * Imposta il valore della propriet� actors. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setActors(String value) { this.actors = value; } - /** - * Recupera il valore della propriet� awards. - * - * @return - * possible object is - * {@link String } - * - */ public String getAwards() { return awards; } - /** - * Imposta il valore della propriet� awards. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setAwards(String value) { this.awards = value; } - /** - * Recupera il valore della propriet� country. - * - * @return - * possible object is - * {@link String } - * - */ public String getCountry() { return country; } - /** - * Imposta il valore della propriet� country. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setCountry(String value) { this.country = value; } - /** - * Recupera il valore della propriet� director. - * - * @return - * possible object is - * {@link String } - * - */ public String getDirector() { return director; } - /** - * Imposta il valore della propriet� director. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setDirector(String value) { this.director = value; } - /** - * Recupera il valore della propriet� genre. - * - * @return - * possible object is - * {@link String } - * - */ public String getGenre() { return genre; } - /** - * Imposta il valore della propriet� genre. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setGenre(String value) { this.genre = value; } - /** - * Recupera il valore della propriet� imdbId. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbId() { return imdbId; } - /** - * Imposta il valore della propriet� imdbId. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbId(String value) { this.imdbId = value; } - /** - * Recupera il valore della propriet� imdbRating. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbRating() { return imdbRating; } - /** - * Imposta il valore della propriet� imdbRating. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbRating(String value) { this.imdbRating = value; } - /** - * Recupera il valore della propriet� imdbVotes. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbVotes() { return imdbVotes; } - /** - * Imposta il valore della propriet� imdbVotes. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbVotes(String value) { this.imdbVotes = value; } - /** - * Recupera il valore della propriet� language. - * - * @return - * possible object is - * {@link String } - * - */ public String getLanguage() { return language; } - /** - * Imposta il valore della propriet� language. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setLanguage(String value) { this.language = value; } - /** - * Recupera il valore della propriet� metascore. - * - * @return - * possible object is - * {@link String } - * - */ public String getMetascore() { return metascore; } - /** - * Imposta il valore della propriet� metascore. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setMetascore(String value) { this.metascore = value; } - /** - * Recupera il valore della propriet� plot. - * - * @return - * possible object is - * {@link String } - * - */ public String getPlot() { return plot; } - /** - * Imposta il valore della propriet� plot. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setPlot(String value) { this.plot = value; } - /** - * Recupera il valore della propriet� poster. - * - * @return - * possible object is - * {@link String } - * - */ public String getPoster() { return poster; } - /** - * Imposta il valore della propriet� poster. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setPoster(String value) { this.poster = value; } - /** - * Recupera il valore della propriet� rated. - * - * @return - * possible object is - * {@link String } - * - */ public String getRated() { return rated; } - /** - * Imposta il valore della propriet� rated. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setRated(String value) { this.rated = value; } - /** - * Recupera il valore della propriet� released. - * - * @return - * possible object is - * {@link String } - * - */ public String getReleased() { return released; } - /** - * Imposta il valore della propriet� released. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setReleased(String value) { this.released = value; } - /** - * Recupera il valore della propriet� response. - * - * @return - * possible object is - * {@link String } - * - */ public String getResponse() { return response; } - /** - * Imposta il valore della propriet� response. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setResponse(String value) { this.response = value; } - /** - * Recupera il valore della propriet� runtime. - * - * @return - * possible object is - * {@link String } - * - */ public String getRuntime() { return runtime; } - /** - * Imposta il valore della propriet� runtime. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setRuntime(String value) { this.runtime = value; } - /** - * Recupera il valore della propriet� title. - * - * @return - * possible object is - * {@link String } - * - */ public String getTitle() { return title; } - /** - * Imposta il valore della propriet� title. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setTitle(String value) { this.title = value; } - /** - * Recupera il valore della propriet� type. - * - * @return - * possible object is - * {@link String } - * - */ public String getType() { return type; } - /** - * Imposta il valore della propriet� type. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setType(String value) { this.type = value; } - /** - * Recupera il valore della propriet� writer. - * - * @return - * possible object is - * {@link String } - * - */ public String getWriter() { return writer; } - /** - * Imposta il valore della propriet� writer. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setWriter(String value) { this.writer = value; } - /** - * Recupera il valore della propriet� year. - * - * @return - * possible object is - * {@link String } - * - */ public String getYear() { return year; } - /** - * Imposta il valore della propriet� year. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setYear(String value) { this.year = value; } From 31fbff34eb181c3898691c778920db10e8ffa18b Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:55:46 +0100 Subject: [PATCH 067/142] CleanUp Code --- RestEasy Example/pom.xml | 3 +- .../baeldung/client/ServicesInterface.java | 1 - .../main/java/com/baeldung/model/Movie.java | 2 -- .../com/baeldung/server/MovieCrudService.java | 17 ++++------- .../com/baeldung/server/RestEasyServices.java | 8 ----- .../src/main/resources/schema1.xsd | 29 ------------------- .../src/main/webapp/WEB-INF/web.xml | 3 -- .../java/baeldung/client/RestEasyClient.java | 7 ----- .../baeldung/server/RestEasyClientTest.java | 1 - 9 files changed, 7 insertions(+), 64 deletions(-) delete mode 100644 RestEasy Example/src/main/resources/schema1.xsd delete mode 100644 RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 6935238d91..9c890da2b7 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -36,7 +36,7 @@ - + org.jboss.resteasy jaxrs-api @@ -101,5 +101,4 @@ - \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 749cabc757..3c8d6abc00 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -1,7 +1,6 @@ package com.baeldung.client; import com.baeldung.model.Movie; - import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 805ba95209..56ba766ff4 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -1,11 +1,9 @@ - package com.baeldung.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; - @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "movie", propOrder = { "actors", diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 29226aa0e0..bbb3b1e953 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -1,7 +1,6 @@ package com.baeldung.server; import com.baeldung.model.Movie; - import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -11,23 +10,21 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - @Path("/movies") public class MovieCrudService { - private Map inventory = new HashMap(); @GET @Path("/getinfo") @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***"); - if(inventory.containsKey(imdbID)){ - return inventory.get(imdbID); + if(inventory.containsKey(imdbId)){ + return inventory.get(imdbId); }else return null; } @@ -70,16 +67,16 @@ public class MovieCrudService { @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)){ + 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); + inventory.remove(imdbId); return Response.status(Response.Status.OK).build(); } @@ -93,6 +90,4 @@ public class MovieCrudService { } - - } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java index 8c57d2c9b4..7726e49f38 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java @@ -1,19 +1,11 @@ package com.baeldung.server; - import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; -import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Set; -/** - * Created by Admin on 29/01/2016. - */ - - - @ApplicationPath("/rest") public class RestEasyServices extends Application { diff --git a/RestEasy Example/src/main/resources/schema1.xsd b/RestEasy Example/src/main/resources/schema1.xsd deleted file mode 100644 index 0d74b7c366..0000000000 --- a/RestEasy Example/src/main/resources/schema1.xsd +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index f70fdf7975..1e7f64004d 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -5,12 +5,9 @@ RestEasy Example - resteasy.servlet.mapping.prefix /rest - - \ No newline at end of file diff --git a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java deleted file mode 100644 index b474b3d4f8..0000000000 --- a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java +++ /dev/null @@ -1,7 +0,0 @@ -package baeldung.client; - -/** - * Created by Admin on 29/01/2016. - */ -public class RestEasyClient { -} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index b6a2e2a0c1..faa39e0199 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -10,7 +10,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.junit.Before; import org.junit.Test; - import javax.naming.NamingException; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; From 37acdef2a7bbe867416c1e1208cd93a068cd5bbc Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Mon, 8 Feb 2016 14:00:11 +0100 Subject: [PATCH 068/142] CleanUp and reformatting Code; dependency fix in pom.xml --- RestEasy Example/pom.xml | 147 +++++++----------- .../baeldung/client/ServicesInterface.java | 15 +- .../main/java/com/baeldung/model/Movie.java | 56 ++----- .../com/baeldung/server/MovieCrudService.java | 49 +++--- .../WEB-INF/jboss-deployment-structure.xml | 22 +-- .../src/main/webapp/WEB-INF/web.xml | 14 +- .../baeldung/server/RestEasyClientTest.java | 23 ++- .../com/baeldung/server/movies/batman.json | 2 +- .../baeldung/server/movies/transformer.json | 2 +- 9 files changed, 125 insertions(+), 205 deletions(-) diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 9c890da2b7..ec9e87b0d1 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -1,104 +1,77 @@ - - 4.0.0 + + 4.0.0 - com.baeldung - resteasy-tutorial - 1.0 - war + com.baeldung + resteasy-tutorial + 1.0 + war - - - jboss - http://repository.jboss.org/nexus/content/groups/public/ - - + + 3.0.14.Final + - - 3.0.14.Final - runtime - + + RestEasyTutorial + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + - - RestEasyTutorial - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - + - + - - org.jboss.resteasy - jaxrs-api - 3.0.12.Final - ${resteasy.scope} - - - - org.jboss.resteasy - resteasy-servlet-initializer - ${resteasy.version} - ${resteasy.scope} - - - jboss-jaxrs-api_2.0_spec - org.jboss.spec.javax.ws.rs - - - - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - ${resteasy.scope} - + + org.jboss.resteasy + resteasy-servlet-initializer + ${resteasy.version} + - - javax.ws.rs - javax.ws.rs-api - 2.0.1 - + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + - - org.jboss.resteasy - resteasy-jackson-provider - ${resteasy.version} - ${resteasy.scope} - + - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - ${resteasy.scope} - + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + - + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + - - junit - junit - 4.4 - + - - commons-io - commons-io - 2.4 - + + junit + junit + 4.4 + + + + commons-io + commons-io + 2.4 + + + - \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 3c8d6abc00..3d03c16faf 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -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 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); - - } diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 56ba766ff4..a959682a75 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -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; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index bbb3b1e953..6a0699874a 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -13,78 +13,71 @@ import java.util.stream.Collectors; @Path("/movies") public class MovieCrudService { - private Map inventory = new HashMap(); - + private Map inventory = new HashMap(); @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 listMovies(){ + @Produces({ "application/json" }) + public List listMovies() { return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 84d75934a7..7879603d19 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -1,16 +1,16 @@ - - - - + + + + - - - - - + + + + + - - + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index 1e7f64004d..d5f00293f4 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -1,13 +1,13 @@ + 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"> - RestEasy Example + RestEasy Example - - resteasy.servlet.mapping.prefix - /rest - + + resteasy.servlet.mapping.prefix + /rest + \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index faa39e0199..3760ae2415 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -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()); } } \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json index 28061d5bf9..173901c948 100644 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json @@ -16,7 +16,7 @@ "metascore": "66", "imdbRating": "7.6", "imdbVotes": "256,000", - "imdbID": "tt0096895", + "imdbId": "tt0096895", "type": "movie", "response": "True" } \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json index a3b033a8ba..a4fd061a82 100644 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json @@ -16,7 +16,7 @@ "metascore": "61", "imdbRating": "7.1", "imdbVotes": "492,225", - "imdbID": "tt0418279", + "imdbId": "tt0418279", "type": "movie", "response": "True" } \ No newline at end of file From 06bbf19265938d444d07841989397369cf01d3fd Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Mon, 8 Feb 2016 16:08:15 +0100 Subject: [PATCH 069/142] CleanUp and reformatting Code. --- .../src/main/java/com/baeldung/server/MovieCrudService.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 6a0699874a..b7f3215f3f 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -26,7 +26,6 @@ public class MovieCrudService { return inventory.get(imdbId); } else return null; - } @POST @@ -41,7 +40,6 @@ public class MovieCrudService { } inventory.put(movie.getImdbId(), movie); - return Response.status(Response.Status.CREATED).build(); } @@ -55,9 +53,9 @@ public class MovieCrudService { 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); return Response.status(Response.Status.OK).build(); - } @DELETE @@ -80,7 +78,6 @@ public class MovieCrudService { public List listMovies() { return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); - } } From 4d3ce9afe9cf7c73a2955c0852c3b335828f3c3a Mon Sep 17 00:00:00 2001 From: Oleksandr Borkovskyi Date: Tue, 9 Feb 2016 13:59:35 +0200 Subject: [PATCH 070/142] Updated test --- .../src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java b/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java index 4569019e60..903381bd29 100644 --- a/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java +++ b/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java @@ -27,7 +27,7 @@ public class GuavaMiscUtilsTest { List stackTraceElements = Throwables.lazyStackTrace(e); - assertEquals(27, stackTraceElements.size()); + assertTrue(stackTraceElements.size() > 0); } @Test From 420cbb202b3d101b10ea1b4eb9f8784ede50f112 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Tue, 9 Feb 2016 14:27:46 +0200 Subject: [PATCH 071/142] Update README.md --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 9a7c0d3776..23fe12465f 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -12,3 +12,4 @@ - [Convert a Map to an Array, List or Set in Java](http://www.baeldung.com/convert-map-values-to-array-list-set) - [Java – Write to File](http://www.baeldung.com/java-write-to-file) - [Java Scanner](http://www.baeldung.com/java-scanner) +- [Java Timer](http://www.baeldung.com/java-timer-and-timertask) From 0757706c4718548c8031ef97be8c702196689977 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Tue, 9 Feb 2016 14:30:27 +0200 Subject: [PATCH 072/142] Update README.md --- jackson/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson/README.md b/jackson/README.md index 046c6b6cfb..d49ad9088a 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -10,3 +10,4 @@ - [Jackson – Custom Deserializer](http://www.baeldung.com/jackson-deserialization) - [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception) - [Jackson Date](http://www.baeldung.com/jackson-serialize-dates) +- [Jackson – Bidirectional Relationships](http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion) From 86157e6beeb25cd85221038fbeb7291b48127aef Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Tue, 9 Feb 2016 14:31:59 +0200 Subject: [PATCH 073/142] Update README.md --- spring-security-login-and-registration/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index a5a9701ff8..57e7fd28f0 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -7,7 +7,7 @@ - [Spring Security Registration Tutorial](http://www.baeldung.com/spring-security-registration) - [The Registration Process With Spring Security](http://www.baeldung.com/registration-with-spring-mvc-and-spring-security) - [Registration – Activate a New Account by Email](http://www.baeldung.com/registration-verify-user-by-email) - +- [Registration with Spring Security – Password Encoding](http://www.baeldung.com/spring-security-registration-password-encoding-bcrypt) ### Build the Project ``` From 58d169cd241c998618969c2ead01eac5b2262ee9 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Tue, 9 Feb 2016 14:33:43 +0200 Subject: [PATCH 074/142] Update README.md --- spring-security-login-and-registration/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index 57e7fd28f0..299d096c37 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -8,6 +8,7 @@ - [The Registration Process With Spring Security](http://www.baeldung.com/registration-with-spring-mvc-and-spring-security) - [Registration – Activate a New Account by Email](http://www.baeldung.com/registration-verify-user-by-email) - [Registration with Spring Security – Password Encoding](http://www.baeldung.com/spring-security-registration-password-encoding-bcrypt) +- [Spring Security – Roles and Privileges](http://www.baeldung.com/role-and-privilege-for-spring-security-registration) ### Build the Project ``` From d806fa3925b681e4e81a74de4a27dc093d267806 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Tue, 9 Feb 2016 14:35:18 +0200 Subject: [PATCH 075/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index cffbcf40f0..64478589a3 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -13,6 +13,7 @@ - [Integration Testing with the Maven Cargo plugin](http://www.baeldung.com/2011/10/16/how-to-set-up-integration-testing-with-the-maven-cargo-plugin/) - [Introduction to Spring Data JPA](http://www.baeldung.com/2011/12/22/the-persistence-layer-with-spring-data-jpa/) - [Project Configuration with Spring](http://www.baeldung.com/2012/03/12/project-configuration-with-spring/) +- [REST Query Language with Spring and JPA Criteria](http://www.baeldung.com/rest-search-language-spring-jpa-criteria) ### Build the Project From ad0dd95004b88106744065cf68c28770433466bf Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Tue, 9 Feb 2016 14:38:17 +0200 Subject: [PATCH 076/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index 64478589a3..c5f52f44ad 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -14,6 +14,7 @@ - [Introduction to Spring Data JPA](http://www.baeldung.com/2011/12/22/the-persistence-layer-with-spring-data-jpa/) - [Project Configuration with Spring](http://www.baeldung.com/2012/03/12/project-configuration-with-spring/) - [REST Query Language with Spring and JPA Criteria](http://www.baeldung.com/rest-search-language-spring-jpa-criteria) +- [REST Query Language with Spring Data JPA Specifications](http://www.baeldung.com/rest-api-search-language-spring-data-specifications) ### Build the Project From 00ecb8c947a542eba055e214e3cda4d17a43c903 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Tue, 9 Feb 2016 14:43:43 +0200 Subject: [PATCH 077/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index c5f52f44ad..e2db0e0307 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -15,6 +15,7 @@ - [Project Configuration with Spring](http://www.baeldung.com/2012/03/12/project-configuration-with-spring/) - [REST Query Language with Spring and JPA Criteria](http://www.baeldung.com/rest-search-language-spring-jpa-criteria) - [REST Query Language with Spring Data JPA Specifications](http://www.baeldung.com/rest-api-search-language-spring-data-specifications) +- [REST Query Language with Spring Data JPA and QueryDSL](http://www.baeldung.com/rest-api-search-language-spring-data-querydsl) ### Build the Project From 2bad287a2eee1acd22deaf9b6ef5c00d08a6d149 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Tue, 9 Feb 2016 14:44:49 +0200 Subject: [PATCH 078/142] Update README.md --- spring-jpa/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-jpa/README.md b/spring-jpa/README.md index da55ca7b75..f974c6e22c 100644 --- a/spring-jpa/README.md +++ b/spring-jpa/README.md @@ -9,3 +9,4 @@ - [The DAO with JPA and Spring](http://www.baeldung.com/spring-dao-jpa) - [JPA Pagination](http://www.baeldung.com/jpa-pagination) - [Sorting with JPA](http://www.baeldung.com/jpa-sort) +- [Spring JPA – Multiple Databases](http://www.baeldung.com/spring-data-jpa-multiple-databases) From 5d896c28d386e6f86783dac649f0ba10fd1d54ff Mon Sep 17 00:00:00 2001 From: David Morley Date: Wed, 10 Feb 2016 05:14:57 -0600 Subject: [PATCH 079/142] Clean up Guava 19 examples --- .../test/java/com/baeldung/guava/GuavaMiscUtilsTest.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java b/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java index 903381bd29..c7b8441b78 100644 --- a/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java +++ b/guava19/src/test/java/com/baeldung/guava/GuavaMiscUtilsTest.java @@ -1,16 +1,9 @@ package com.baeldung.guava; -import com.baeldung.guava.entity.User; -import com.google.common.base.CharMatcher; import com.google.common.base.Throwables; import com.google.common.collect.*; -import com.google.common.hash.HashCode; -import com.google.common.hash.HashFunction; -import com.google.common.hash.Hashing; -import com.google.common.reflect.TypeToken; import org.junit.Test; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; From ed0c9aca109f02ea1e68db24df642578c67dc501 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:33:35 +0200 Subject: [PATCH 080/142] Update README.md --- spring-security-login-and-registration/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index 299d096c37..7235ef3bf6 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -9,6 +9,7 @@ - [Registration – Activate a New Account by Email](http://www.baeldung.com/registration-verify-user-by-email) - [Registration with Spring Security – Password Encoding](http://www.baeldung.com/spring-security-registration-password-encoding-bcrypt) - [Spring Security – Roles and Privileges](http://www.baeldung.com/role-and-privilege-for-spring-security-registration) +- [Prevent Brute Force Authentication Attempts with Spring Security](http://www.baeldung.com/spring-security-block-brute-force-authentication-attempts) ### Build the Project ``` From 855c8b153ca209f171750f069bf007ecb520b803 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:34:34 +0200 Subject: [PATCH 081/142] Update README.md --- spring-security-login-and-registration/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index 7235ef3bf6..8f47992c1d 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -10,6 +10,7 @@ - [Registration with Spring Security – Password Encoding](http://www.baeldung.com/spring-security-registration-password-encoding-bcrypt) - [Spring Security – Roles and Privileges](http://www.baeldung.com/role-and-privilege-for-spring-security-registration) - [Prevent Brute Force Authentication Attempts with Spring Security](http://www.baeldung.com/spring-security-block-brute-force-authentication-attempts) +- [Spring Security – Reset Your Password](http://www.baeldung.com/spring-security-registration-i-forgot-my-password) ### Build the Project ``` From 32373392a952a6c5bdb72fbc5754202889e4962c Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:35:55 +0200 Subject: [PATCH 082/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index e2db0e0307..3df3947d5e 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -16,6 +16,7 @@ - [REST Query Language with Spring and JPA Criteria](http://www.baeldung.com/rest-search-language-spring-jpa-criteria) - [REST Query Language with Spring Data JPA Specifications](http://www.baeldung.com/rest-api-search-language-spring-data-specifications) - [REST Query Language with Spring Data JPA and QueryDSL](http://www.baeldung.com/rest-api-search-language-spring-data-querydsl) +- [REST Query Language – Advanced Search Operations](http://www.baeldung.com/rest-api-query-search-language-more-operations) ### Build the Project From bf6519b860da52ed8491c7bddeb7cc2d7d684dab Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:37:24 +0200 Subject: [PATCH 083/142] Update README.md --- spring-security-login-and-registration/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index 8f47992c1d..5b1980dcbf 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -11,6 +11,7 @@ - [Spring Security – Roles and Privileges](http://www.baeldung.com/role-and-privilege-for-spring-security-registration) - [Prevent Brute Force Authentication Attempts with Spring Security](http://www.baeldung.com/spring-security-block-brute-force-authentication-attempts) - [Spring Security – Reset Your Password](http://www.baeldung.com/spring-security-registration-i-forgot-my-password) +- [Spring Security Registration – Resend Verification Email](http://www.baeldung.com/spring-security-registration-verification-email) ### Build the Project ``` From e051f36401d19a16a0b36af987807a9f48140a22 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:41:29 +0200 Subject: [PATCH 084/142] Update README.md --- spring-security-login-and-registration/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index 5b1980dcbf..ee565dca65 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -12,6 +12,7 @@ - [Prevent Brute Force Authentication Attempts with Spring Security](http://www.baeldung.com/spring-security-block-brute-force-authentication-attempts) - [Spring Security – Reset Your Password](http://www.baeldung.com/spring-security-registration-i-forgot-my-password) - [Spring Security Registration – Resend Verification Email](http://www.baeldung.com/spring-security-registration-verification-email) +- [The Registration API becomes RESTful](http://www.baeldung.com/registration-restful-api) ### Build the Project ``` From 24a8e3803ce097e584b2b1c46f7ff4b497ce4912 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:42:54 +0200 Subject: [PATCH 085/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index 3df3947d5e..6b56f4b918 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -17,6 +17,7 @@ - [REST Query Language with Spring Data JPA Specifications](http://www.baeldung.com/rest-api-search-language-spring-data-specifications) - [REST Query Language with Spring Data JPA and QueryDSL](http://www.baeldung.com/rest-api-search-language-spring-data-querydsl) - [REST Query Language – Advanced Search Operations](http://www.baeldung.com/rest-api-query-search-language-more-operations) +- [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) ### Build the Project From 6b0d2165ce7c67a1d367c825dde605e2e121b78a Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:44:08 +0200 Subject: [PATCH 086/142] Update README.md --- spring-security-login-and-registration/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index ee565dca65..e1b3e61acc 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -13,6 +13,7 @@ - [Spring Security – Reset Your Password](http://www.baeldung.com/spring-security-registration-i-forgot-my-password) - [Spring Security Registration – Resend Verification Email](http://www.baeldung.com/spring-security-registration-verification-email) - [The Registration API becomes RESTful](http://www.baeldung.com/registration-restful-api) +- [Registration – Password Strength and Rules](http://www.baeldung.com/registration-password-strength-and-rules) ### Build the Project ``` From 11065cd00481cc472e9144a4274e7400a3ad53ab Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:45:30 +0200 Subject: [PATCH 087/142] Update README.md --- spring-security-login-and-registration/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-login-and-registration/README.md b/spring-security-login-and-registration/README.md index e1b3e61acc..07fb21bfff 100644 --- a/spring-security-login-and-registration/README.md +++ b/spring-security-login-and-registration/README.md @@ -14,6 +14,7 @@ - [Spring Security Registration – Resend Verification Email](http://www.baeldung.com/spring-security-registration-verification-email) - [The Registration API becomes RESTful](http://www.baeldung.com/registration-restful-api) - [Registration – Password Strength and Rules](http://www.baeldung.com/registration-password-strength-and-rules) +- [Updating your Password](http://www.baeldung.com/updating-your-password/) ### Build the Project ``` From 95f51e577bc80b8cafe200d2d9ff5b9732eb9566 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:46:41 +0200 Subject: [PATCH 088/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index 6b56f4b918..b592f7558c 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -18,6 +18,7 @@ - [REST Query Language with Spring Data JPA and QueryDSL](http://www.baeldung.com/rest-api-search-language-spring-data-querydsl) - [REST Query Language – Advanced Search Operations](http://www.baeldung.com/rest-api-query-search-language-more-operations) - [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) +- [REST Query Language with RSQL](http://www.baeldung.com/rest-api-search-language-rsql-fiql) ### Build the Project From 9f3be320b49901d8900cab69d010f50346e579c4 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:47:44 +0200 Subject: [PATCH 089/142] Update README.md --- httpclient/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/httpclient/README.md b/httpclient/README.md index 1cf788287c..e06c57da71 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -16,3 +16,4 @@ - [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) - [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload) - [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial) +- [HttpClient 4 Tutorial](http://www.baeldung.com/httpclient-guide) From ac96fae1a7bd262e77ae1e51b650ad2115bf35a3 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:50:01 +0200 Subject: [PATCH 090/142] Update README.md --- jackson/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson/README.md b/jackson/README.md index d49ad9088a..c17d89912f 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -11,3 +11,4 @@ - [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception) - [Jackson Date](http://www.baeldung.com/jackson-serialize-dates) - [Jackson – Bidirectional Relationships](http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion) +- [Jackson JSON Tutorial](http://www.baeldung.com/jackson) From dbaf47927008cf4fb467d93a66b55982df354083 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:50:52 +0200 Subject: [PATCH 091/142] Update README.md --- jackson/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson/README.md b/jackson/README.md index c17d89912f..cd08926386 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -12,3 +12,4 @@ - [Jackson Date](http://www.baeldung.com/jackson-serialize-dates) - [Jackson – Bidirectional Relationships](http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion) - [Jackson JSON Tutorial](http://www.baeldung.com/jackson) +- [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key) From c273b4eda0ce1a5011dca9c04550d0763309a069 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:52:25 +0200 Subject: [PATCH 092/142] Update README.md --- jackson/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson/README.md b/jackson/README.md index cd08926386..1a445b701b 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -13,3 +13,4 @@ - [Jackson – Bidirectional Relationships](http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion) - [Jackson JSON Tutorial](http://www.baeldung.com/jackson) - [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key) +- [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not) From 9bba394195c6d274d4a120cc0be6c0ba869a774d Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 13:53:22 +0200 Subject: [PATCH 093/142] Update README.md --- jackson/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson/README.md b/jackson/README.md index 1a445b701b..e226721d61 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -14,3 +14,4 @@ - [Jackson JSON Tutorial](http://www.baeldung.com/jackson) - [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key) - [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not) +- [A Guide to Jackson Annotations](http://www.baeldung.com/jackson-annotations) From 6a56dcaa15798e1f6724f3c74683f4e8512778f7 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:03:31 +0200 Subject: [PATCH 094/142] Create README.md --- spring-data-mongodb/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spring-data-mongodb/README.md diff --git a/spring-data-mongodb/README.md b/spring-data-mongodb/README.md new file mode 100644 index 0000000000..7d194b72c8 --- /dev/null +++ b/spring-data-mongodb/README.md @@ -0,0 +1,7 @@ +========= + +## Spring Data MongoDB + + +### Relevant Articles: +-[A Guide to Queries in Spring Data MongoDB](http://www.baeldung.com/queries-in-spring-data-mongodb) From 034c57571330f02a7616ca4406478728c10c42d6 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:03:50 +0200 Subject: [PATCH 095/142] Update README.md --- spring-data-mongodb/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-mongodb/README.md b/spring-data-mongodb/README.md index 7d194b72c8..d92edc8940 100644 --- a/spring-data-mongodb/README.md +++ b/spring-data-mongodb/README.md @@ -4,4 +4,4 @@ ### Relevant Articles: --[A Guide to Queries in Spring Data MongoDB](http://www.baeldung.com/queries-in-spring-data-mongodb) +- [A Guide to Queries in Spring Data MongoDB](http://www.baeldung.com/queries-in-spring-data-mongodb) From 344c29cc11c84e3de0d042fa448076d5bd63aa24 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:11:27 +0200 Subject: [PATCH 096/142] Update README.md --- spring-data-mongodb/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-mongodb/README.md b/spring-data-mongodb/README.md index d92edc8940..4a140c1be6 100644 --- a/spring-data-mongodb/README.md +++ b/spring-data-mongodb/README.md @@ -5,3 +5,4 @@ ### Relevant Articles: - [A Guide to Queries in Spring Data MongoDB](http://www.baeldung.com/queries-in-spring-data-mongodb) +- [Spring Data MongoDB – Indexes, Annotations and Converters](http://www.baeldung.com/spring-data-mongodb-index-annotations-converter) From 04947776da282b21b1b640bef6d76e9167fe7aa5 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:12:20 +0200 Subject: [PATCH 097/142] Update README.md --- spring-data-mongodb/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-mongodb/README.md b/spring-data-mongodb/README.md index 4a140c1be6..e784176879 100644 --- a/spring-data-mongodb/README.md +++ b/spring-data-mongodb/README.md @@ -6,3 +6,4 @@ ### Relevant Articles: - [A Guide to Queries in Spring Data MongoDB](http://www.baeldung.com/queries-in-spring-data-mongodb) - [Spring Data MongoDB – Indexes, Annotations and Converters](http://www.baeldung.com/spring-data-mongodb-index-annotations-converter) +- [Custom Cascading in Spring Data MongoDB](http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb) From 11b30eea02668bf6c54f5e78a48821e843b07672 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:13:27 +0200 Subject: [PATCH 098/142] Update README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index b592f7558c..c6d6ed5848 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -19,6 +19,7 @@ - [REST Query Language – Advanced Search Operations](http://www.baeldung.com/rest-api-query-search-language-more-operations) - [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) - [REST Query Language with RSQL](http://www.baeldung.com/rest-api-search-language-rsql-fiql) +- [Spring RestTemplate Tutorial](http://www.baeldung.com/rest-template) ### Build the Project From 09e896a3577ff8a42c8516f972bdaf8c5abdeeda Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:20:12 +0200 Subject: [PATCH 099/142] Create README.md --- spring-katharsis/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 spring-katharsis/README.md diff --git a/spring-katharsis/README.md b/spring-katharsis/README.md new file mode 100644 index 0000000000..ec0141f41a --- /dev/null +++ b/spring-katharsis/README.md @@ -0,0 +1,6 @@ +========= + +## Java Web Application + +### Relevant Articles: +- [JSON API in a Java Web Application](http://www.baeldung.com/json-api-java-spring-web-app) From 15b5ac439e675d47bd1151caad401654e129ab92 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:24:04 +0200 Subject: [PATCH 100/142] Update README.md --- spring-all/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-all/README.md b/spring-all/README.md index baab7ec083..977b8b7357 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -8,3 +8,4 @@ This project is used to replicate Spring Exceptions only. ### Relevant articles: - [Properties with Spring](http://www.baeldung.com/2012/02/06/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage - [Spring Profiles](http://www.baeldung.com/spring-profiles) +- [A Spring Custom Annotation for a Better DAO](http://www.baeldung.com/spring-annotation-bean-pre-processor) From 0b55104f32e22152e9dd2657a3359c0f2fe57e85 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:25:03 +0200 Subject: [PATCH 101/142] Update README.md --- spring-data-mongodb/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-mongodb/README.md b/spring-data-mongodb/README.md index e784176879..c5d2d2df41 100644 --- a/spring-data-mongodb/README.md +++ b/spring-data-mongodb/README.md @@ -7,3 +7,4 @@ - [A Guide to Queries in Spring Data MongoDB](http://www.baeldung.com/queries-in-spring-data-mongodb) - [Spring Data MongoDB – Indexes, Annotations and Converters](http://www.baeldung.com/spring-data-mongodb-index-annotations-converter) - [Custom Cascading in Spring Data MongoDB](http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb) +- [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) From f602cea186c7fe224b2c537116d4e7db9fe73e97 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:25:49 +0200 Subject: [PATCH 102/142] Update README.md --- spring-mvc-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index bf76c7e1d4..113f690920 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -4,3 +4,4 @@ ### Relevant Articles: +- [http://www.baeldung.com/spring-bean-annotations](http://www.baeldung.com/spring-bean-annotations) From d91f7672ff4f8f4b7938be4fd686f3685cce4ac8 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:26:17 +0200 Subject: [PATCH 103/142] Update README.md --- spring-mvc-java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index 113f690920..ccbd1288f0 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -4,4 +4,4 @@ ### Relevant Articles: -- [http://www.baeldung.com/spring-bean-annotations](http://www.baeldung.com/spring-bean-annotations) +- [Spring Bean Annotations](http://www.baeldung.com/spring-bean-annotations) From eb3b30e9b1fa190c26629ef7152607e1c7e02bea Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:27:10 +0200 Subject: [PATCH 104/142] Update README.md --- spring-security-rest/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest/README.md b/spring-security-rest/README.md index a3fce32a9c..d17cb24f7e 100644 --- a/spring-security-rest/README.md +++ b/spring-security-rest/README.md @@ -5,3 +5,4 @@ ### Relevant Articles: - [Spring REST Service Security](http://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/) +- [Setting Up Swagger 2 with a Spring REST API](http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) From 238f5d340f286e64f91da86a0eb49864e29ea4b6 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:28:15 +0200 Subject: [PATCH 105/142] Update README.md --- spring-mvc-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index ccbd1288f0..f6bb37b600 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -5,3 +5,4 @@ ### Relevant Articles: - [Spring Bean Annotations](http://www.baeldung.com/spring-bean-annotations) +- [Introduction to Pointcut Expressions in Spring](http://www.baeldung.com/spring-aop-pointcut-tutorial) From fda7b00e6be4707912c038b7d28e74b52964839b Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:29:26 +0200 Subject: [PATCH 106/142] Update README.md --- spring-mvc-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index f6bb37b600..2de2373149 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -6,3 +6,4 @@ ### Relevant Articles: - [Spring Bean Annotations](http://www.baeldung.com/spring-bean-annotations) - [Introduction to Pointcut Expressions in Spring](http://www.baeldung.com/spring-aop-pointcut-tutorial) +- [Introduction to Advice Types in Spring](http://www.baeldung.com/spring-aop-advice-tutorial) From 03ddc9056e271240838413ddd857d520d2995db2 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:30:23 +0200 Subject: [PATCH 107/142] Update README.md --- spring-data-cassandra/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-cassandra/README.md b/spring-data-cassandra/README.md index a245ff62a1..85ea3b8649 100644 --- a/spring-data-cassandra/README.md +++ b/spring-data-cassandra/README.md @@ -2,7 +2,7 @@ ### Relevant Articles: - [Introduction to Spring Data Cassandra](http://www.baeldung.com/spring-data-cassandra-tutorial) - +- [http://www.baeldung.com/spring-data-cassandratemplate-cqltemplate](http://www.baeldung.com/spring-data-cassandratemplate-cqltemplate) ### Build the Project with Tests Running ``` mvn clean install From cde526808ad9c504871c6aa8b7aecb28f2b9542b Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:31:11 +0200 Subject: [PATCH 108/142] Update README.md --- spring-data-cassandra/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-data-cassandra/README.md b/spring-data-cassandra/README.md index 85ea3b8649..456eefcf18 100644 --- a/spring-data-cassandra/README.md +++ b/spring-data-cassandra/README.md @@ -2,7 +2,8 @@ ### Relevant Articles: - [Introduction to Spring Data Cassandra](http://www.baeldung.com/spring-data-cassandra-tutorial) -- [http://www.baeldung.com/spring-data-cassandratemplate-cqltemplate](http://www.baeldung.com/spring-data-cassandratemplate-cqltemplate) +- [Using the CassandraTemplate from Spring Data](http://www.baeldung.com/spring-data-cassandratemplate-cqltemplate) + ### Build the Project with Tests Running ``` mvn clean install From cd8c2517dbf51fdd0a590afb8ab3b9f000ab62b3 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:32:10 +0200 Subject: [PATCH 109/142] Update README.md --- guava18/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/guava18/README.md b/guava18/README.md index 8960b4676e..9924d7c16f 100644 --- a/guava18/README.md +++ b/guava18/README.md @@ -7,7 +7,6 @@ - [Guava Collections Cookbook](http://www.baeldung.com/guava-collections) - [Guava Ordering Cookbook](http://www.baeldung.com/guava-order) - [Guava Functional Cookbook](http://www.baeldung.com/guava-functions-predicates) - - [Hamcrest Collections Cookbook](http://www.baeldung.com/hamcrest-collections-arrays) - - [Partition a List in Java](http://www.baeldung.com/java-list-split) +- [Guava 18: What’s New?](http://www.baeldung.com/whats-new-in-guava-18) From f7bd8093d037108b03591e7c32b584b5c495fdba Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:33:03 +0200 Subject: [PATCH 110/142] Update README.md --- core-java-8/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-8/README.md b/core-java-8/README.md index e3fa3f9848..62040ba5cf 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -5,3 +5,4 @@ ### Relevant Articles: // - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) - [Java – Directory Size](http://www.baeldung.com/java-folder-size) +- [Java – Try with Resources](http://www.baeldung.com/java-try-with-resources) From 2b4b9fa79c3fdb70590e7ee8f356da6e2cdac740 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:33:55 +0200 Subject: [PATCH 111/142] Update README.md --- spring-security-mvc-ldap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-mvc-ldap/README.md b/spring-security-mvc-ldap/README.md index 260b4b38d8..686f611f99 100644 --- a/spring-security-mvc-ldap/README.md +++ b/spring-security-mvc-ldap/README.md @@ -5,7 +5,7 @@ ### Relevant Article: - [Spring Security - security none, filters none, access permitAll](http://www.baeldung.com/security-none-filters-none-access-permitAll) - [Spring Security Basic Authentication](http://www.baeldung.com/spring-security-basic-authentication) - +- [Intro to Spring Security LDAP](http://www.baeldung.com/spring-security-ldap) ### Notes - the project uses Spring Boot - simply run 'SampleLDAPApplication.java' to start up Spring Boot with a Tomcat container and embedded LDAP server. From 573f4bed69eafd21bbbb3908f538bb746de175dc Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Wed, 10 Feb 2016 14:35:56 +0200 Subject: [PATCH 112/142] Update README.md --- spring-batch/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-batch/README.md b/spring-batch/README.md index 8b13789179..953e652cea 100644 --- a/spring-batch/README.md +++ b/spring-batch/README.md @@ -1 +1,7 @@ +========= +## Spring Batch + + +### Relevant Articles: +- [Introduction to Spring Batch](http://www.baeldung.com/introduction-to-spring-batch) From ebce69d28d14f77da8c390b92db58d15cd66ce04 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:25:41 +0200 Subject: [PATCH 113/142] Update README.md --- spring-data-mongodb/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-mongodb/README.md b/spring-data-mongodb/README.md index c5d2d2df41..d656bc897c 100644 --- a/spring-data-mongodb/README.md +++ b/spring-data-mongodb/README.md @@ -8,3 +8,4 @@ - [Spring Data MongoDB – Indexes, Annotations and Converters](http://www.baeldung.com/spring-data-mongodb-index-annotations-converter) - [Custom Cascading in Spring Data MongoDB](http://www.baeldung.com/cascading-with-dbref-and-lifecycle-events-in-spring-data-mongodb) - [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) +- [Introduction to Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-tutorial) From c3e5eb7ccfd942761e01d9b15ed21cf57f8511fe Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:40:35 +0200 Subject: [PATCH 114/142] Update README.md --- core-java-8/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-8/README.md b/core-java-8/README.md index 62040ba5cf..ab89bbdaf2 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -6,3 +6,4 @@ // - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) - [Java – Directory Size](http://www.baeldung.com/java-folder-size) - [Java – Try with Resources](http://www.baeldung.com/java-try-with-resources) +- [Lambda Expressions and Functional Interfaces: Tips and Best Practices](http://www.baeldung.com/java-8-lambda-expressions-tips) From a7cd46c02230f5f589fa58bb60e3873f092de5ec Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:45:49 +0200 Subject: [PATCH 115/142] Create README.md --- mockito-mocks-spring-beans/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 mockito-mocks-spring-beans/README.md diff --git a/mockito-mocks-spring-beans/README.md b/mockito-mocks-spring-beans/README.md new file mode 100644 index 0000000000..3ced7161fa --- /dev/null +++ b/mockito-mocks-spring-beans/README.md @@ -0,0 +1,7 @@ +========= + +## Mockito Mocks into Spring Beans + + +### Relevant Articles: +- [Injecting Mockito Mocks into Spring Beans](http://www.baeldung.com/injecting-mocks-in-spring) From fffeb216f5c22fa3399e61d4a0211c0595be9bfc Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:47:43 +0200 Subject: [PATCH 116/142] Update README.md --- spring-security-rest/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest/README.md b/spring-security-rest/README.md index d17cb24f7e..6261fbe83d 100644 --- a/spring-security-rest/README.md +++ b/spring-security-rest/README.md @@ -6,3 +6,4 @@ ### Relevant Articles: - [Spring REST Service Security](http://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/) - [Setting Up Swagger 2 with a Spring REST API](http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) +- [Custom Error Message Handling for REST API](http://www.baeldung.com/global-error-handler-in-a-spring-rest-api) From ae8d5ca8db2087d120e236c8d1a01d693fb3068b Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:48:47 +0200 Subject: [PATCH 117/142] Update README.md --- spring-hibernate4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-hibernate4/README.md b/spring-hibernate4/README.md index acf20632fe..4c0c6706d6 100644 --- a/spring-hibernate4/README.md +++ b/spring-hibernate4/README.md @@ -7,6 +7,7 @@ - [The DAO with Spring 3 and Hibernate](http://www.baeldung.com/2011/12/02/the-persistence-layer-with-spring-3-1-and-hibernate/) - [Hibernate Pagination](http://www.baeldung.com/hibernate-pagination) - [Sorting with Hibernate](http://www.baeldung.com/hibernate-sort) +- [Auditing with JPA, Hibernate, and Spring Data JPA](http://www.baeldung.com/database-auditing-jpa) ### Quick Start From 80da6e8668dbe02bcd3777529ec801dafb10e8d9 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:51:08 +0200 Subject: [PATCH 118/142] Create README.md --- spring-freemarker/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spring-freemarker/README.md diff --git a/spring-freemarker/README.md b/spring-freemarker/README.md new file mode 100644 index 0000000000..bd939d11e9 --- /dev/null +++ b/spring-freemarker/README.md @@ -0,0 +1,7 @@ +========= + +## Using FreeMarker in Spring MVC + + +### Relevant Articles: +- [Introduction to Using FreeMarker in Spring MVC](http://www.baeldung.com/freemarker-in-spring-mvc-tutorial) From 02ebbd4044ef107f69bc89823827f37064afe50b Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:52:17 +0200 Subject: [PATCH 119/142] Update README.md --- spring-security-rest-full/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index c6d6ed5848..f648c49244 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -20,7 +20,7 @@ - [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) - [REST Query Language with RSQL](http://www.baeldung.com/rest-api-search-language-rsql-fiql) - [Spring RestTemplate Tutorial](http://www.baeldung.com/rest-template) - +- [A Guide to CSRF Protection in Spring Security](http://www.baeldung.com/spring-security-csrf) ### Build the Project ``` From 7011fa40fec956a2bfce298d896129ccccc96354 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:53:18 +0200 Subject: [PATCH 120/142] Update README.md --- jackson/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jackson/README.md b/jackson/README.md index e226721d61..53b9c7c31d 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -15,3 +15,4 @@ - [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key) - [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not) - [A Guide to Jackson Annotations](http://www.baeldung.com/jackson-annotations) +- [Working with Tree Model Nodes in Jackson](http://www.baeldung.com/jackson-json-node-tree-model) From edcb2e2e69edcc25c8f9233a899fab5020a2f7f4 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:54:21 +0200 Subject: [PATCH 121/142] Update README.md --- core-java-8/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-8/README.md b/core-java-8/README.md index ab89bbdaf2..8bef3a1be0 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -7,3 +7,4 @@ - [Java – Directory Size](http://www.baeldung.com/java-folder-size) - [Java – Try with Resources](http://www.baeldung.com/java-try-with-resources) - [Lambda Expressions and Functional Interfaces: Tips and Best Practices](http://www.baeldung.com/java-8-lambda-expressions-tips) +- [The Double Colon Operator in Java 8](http://www.baeldung.com/java-8-double-colon-operator) From 71ef292b3a18992345b58007cb0b9c26d63ff56c Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 02:56:17 +0200 Subject: [PATCH 122/142] Create README.md --- spring-zuul/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spring-zuul/README.md diff --git a/spring-zuul/README.md b/spring-zuul/README.md new file mode 100644 index 0000000000..41a77f70c8 --- /dev/null +++ b/spring-zuul/README.md @@ -0,0 +1,7 @@ +========= + +## Spring REST with a Zuul + + +### Relevant Articles: +- [Spring REST with a Zuul Proxy](http://www.baeldung.com/spring-rest-with-zuul-proxy) From e77e6ebfcf045138cf9e8b2cf9650516d09718e0 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 03:03:08 +0200 Subject: [PATCH 123/142] Update README.md --- spring-rest/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-rest/README.md b/spring-rest/README.md index 3b93b06d66..9d373962c4 100644 --- a/spring-rest/README.md +++ b/spring-rest/README.md @@ -7,3 +7,4 @@ - [Spring @RequestMapping](http://www.baeldung.com/spring-requestmapping) - [Http Message Converters with the Spring Framework](http://www.baeldung.com/spring-httpmessageconverter-rest) - [Redirect in Spring](http://www.baeldung.com/spring-redirect-and-forward) +- [Returning Custom Status Codes from Spring Controllers](http://www.baeldung.com/spring-mvc-controller-custom-http-status-code) From b0d8d832804b8366d025e02f01e5d6ea2821af81 Mon Sep 17 00:00:00 2001 From: MichelLeBon Date: Thu, 11 Feb 2016 03:04:45 +0200 Subject: [PATCH 124/142] Update README.md --- spring-mvc-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index 2de2373149..e5264b0370 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -7,3 +7,4 @@ - [Spring Bean Annotations](http://www.baeldung.com/spring-bean-annotations) - [Introduction to Pointcut Expressions in Spring](http://www.baeldung.com/spring-aop-pointcut-tutorial) - [Introduction to Advice Types in Spring](http://www.baeldung.com/spring-aop-advice-tutorial) +- [A Guide to the ViewResolver in Spring MVC](http://www.baeldung.com/spring-mvc-view-resolver-tutorial) From 45358317b6b4f33ead9c4d923c3d7d3bf3e7c281 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 13 Feb 2016 22:25:31 +0200 Subject: [PATCH 125/142] OpenID Connect example --- spring-openid/.classpath | 32 ++++++++ spring-openid/.project | 48 +++++++++++ spring-openid/pom.xml | 68 ++++++++++++++++ .../config/GoogleOpenIdConnectConfig.java | 51 ++++++++++++ .../org/baeldung/config/HomeController.java | 22 +++++ .../org/baeldung/config/SecurityConfig.java | 49 +++++++++++ .../config/SpringOpenidApplication.java | 13 +++ .../security/OpenIdConnectFilter.java | 71 ++++++++++++++++ .../security/OpenIdConnectUserDetails.java | 81 +++++++++++++++++++ .../src/main/resources/application.properties | 6 ++ 10 files changed, 441 insertions(+) create mode 100644 spring-openid/.classpath create mode 100644 spring-openid/.project create mode 100644 spring-openid/pom.xml create mode 100644 spring-openid/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java create mode 100644 spring-openid/src/main/java/org/baeldung/config/HomeController.java create mode 100644 spring-openid/src/main/java/org/baeldung/config/SecurityConfig.java create mode 100644 spring-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java create mode 100644 spring-openid/src/main/java/org/baeldung/security/OpenIdConnectFilter.java create mode 100644 spring-openid/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java create mode 100644 spring-openid/src/main/resources/application.properties diff --git a/spring-openid/.classpath b/spring-openid/.classpath new file mode 100644 index 0000000000..0cad5db2d0 --- /dev/null +++ b/spring-openid/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-openid/.project b/spring-openid/.project new file mode 100644 index 0000000000..81874eb896 --- /dev/null +++ b/spring-openid/.project @@ -0,0 +1,48 @@ + + + spring-openid + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/spring-openid/pom.xml b/spring-openid/pom.xml new file mode 100644 index 0000000000..641fe93a09 --- /dev/null +++ b/spring-openid/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + org.baeldung + spring-openid + 0.0.1-SNAPSHOT + war + + spring-openid + Spring OpenID sample project + + + org.springframework.boot + spring-boot-starter-parent + 1.3.2.RELEASE + + + + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + org.springframework.security.oauth + spring-security-oauth2 + + + + org.springframework.security + spring-security-jwt + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + UTF-8 + 1.8 + + diff --git a/spring-openid/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java b/spring-openid/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java new file mode 100644 index 0000000000..8e9c6e974e --- /dev/null +++ b/spring-openid/src/main/java/org/baeldung/config/GoogleOpenIdConnectConfig.java @@ -0,0 +1,51 @@ +package org.baeldung.config; + +import java.util.Arrays; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.oauth2.client.OAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; +import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; + +@Configuration +@EnableOAuth2Client +public class GoogleOpenIdConnectConfig { + @Value("${google.clientId}") + private String clientId; + + @Value("${google.clientSecret}") + private String clientSecret; + + @Value("${google.accessTokenUri}") + private String accessTokenUri; + + @Value("${google.userAuthorizationUri}") + private String userAuthorizationUri; + + @Value("${google.redirectUri}") + private String redirectUri; + + @Bean + public OAuth2ProtectedResourceDetails googleOpenId() { + final AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails(); + details.setClientId(clientId); + details.setClientSecret(clientSecret); + details.setAccessTokenUri(accessTokenUri); + details.setUserAuthorizationUri(userAuthorizationUri); + details.setScope(Arrays.asList("openid", "email")); + details.setPreEstablishedRedirectUri(redirectUri); + details.setUseCurrentUri(false); + return details; + } + + @Bean + public OAuth2RestTemplate googleOpenIdTemplate(final OAuth2ClientContext clientContext) { + final OAuth2RestTemplate template = new OAuth2RestTemplate(googleOpenId(), clientContext); + return template; + } + +} diff --git a/spring-openid/src/main/java/org/baeldung/config/HomeController.java b/spring-openid/src/main/java/org/baeldung/config/HomeController.java new file mode 100644 index 0000000000..f0a5378019 --- /dev/null +++ b/spring-openid/src/main/java/org/baeldung/config/HomeController.java @@ -0,0 +1,22 @@ +package org.baeldung.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class HomeController { + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @RequestMapping("/") + @ResponseBody + public final String home() { + final String username = SecurityContextHolder.getContext().getAuthentication().getName(); + logger.info(username); + return "Welcome, " + username; + } + +} diff --git a/spring-openid/src/main/java/org/baeldung/config/SecurityConfig.java b/spring-openid/src/main/java/org/baeldung/config/SecurityConfig.java new file mode 100644 index 0000000000..d929bfd631 --- /dev/null +++ b/spring-openid/src/main/java/org/baeldung/config/SecurityConfig.java @@ -0,0 +1,49 @@ +package org.baeldung.config; + +import org.baeldung.security.OpenIdConnectFilter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter; +import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint; +import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter; + +@Configuration +@EnableWebSecurity +public class SecurityConfig extends WebSecurityConfigurerAdapter { + @Autowired + private OAuth2RestTemplate restTemplate; + + @Override + public void configure(WebSecurity web) throws Exception { + web.ignoring().antMatchers("/resources/**"); + } + + @Bean + public OpenIdConnectFilter myFilter() { + final OpenIdConnectFilter filter = new OpenIdConnectFilter("/google-login"); + filter.setRestTemplate(restTemplate); + return filter; + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + // @formatter:off + http + .addFilterAfter(new OAuth2ClientContextFilter(), AbstractPreAuthenticatedProcessingFilter.class) + .addFilterAfter(myFilter(), OAuth2ClientContextFilter.class) + .httpBasic().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/google-login")) + .and() + .authorizeRequests() + // .antMatchers("/","/index*").permitAll() + .anyRequest().authenticated() + ; + + // @formatter:on + } +} \ No newline at end of file diff --git a/spring-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java b/spring-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java new file mode 100644 index 0000000000..608e8a6819 --- /dev/null +++ b/spring-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java @@ -0,0 +1,13 @@ +package org.baeldung.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringOpenidApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringOpenidApplication.class, args); + } + +} diff --git a/spring-openid/src/main/java/org/baeldung/security/OpenIdConnectFilter.java b/spring-openid/src/main/java/org/baeldung/security/OpenIdConnectFilter.java new file mode 100644 index 0000000000..c0970ab3cf --- /dev/null +++ b/spring-openid/src/main/java/org/baeldung/security/OpenIdConnectFilter.java @@ -0,0 +1,71 @@ +package org.baeldung.security; + +import java.io.IOException; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.jwt.Jwt; +import org.springframework.security.jwt.JwtHelper; +import org.springframework.security.oauth2.client.OAuth2RestOperations; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.security.oauth2.common.exceptions.InvalidTokenException; +import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; +import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class OpenIdConnectFilter extends AbstractAuthenticationProcessingFilter { + public OAuth2RestOperations restTemplate; + + public OpenIdConnectFilter(String defaultFilterProcessesUrl) { + super(defaultFilterProcessesUrl); + setAuthenticationManager(new NoopAuthenticationManager()); + } + + @Override + public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { + + OAuth2AccessToken accessToken; + try { + accessToken = restTemplate.getAccessToken(); + } catch (final OAuth2Exception e) { + throw new BadCredentialsException("Could not obtain access token", e); + } + try { + final String idToken = accessToken.getAdditionalInformation().get("id_token").toString(); + final Jwt tokenDecoded = JwtHelper.decode(idToken); + System.out.println("===== : " + tokenDecoded.getClaims()); + + final Map authInfo = new ObjectMapper().readValue(tokenDecoded.getClaims(), Map.class); + + final OpenIdConnectUserDetails user = new OpenIdConnectUserDetails(authInfo, accessToken); + return new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities()); + } catch (final InvalidTokenException e) { + throw new BadCredentialsException("Could not obtain user details from token", e); + } + + } + + public void setRestTemplate(OAuth2RestTemplate restTemplate2) { + restTemplate = restTemplate2; + + } + + private static class NoopAuthenticationManager implements AuthenticationManager { + + @Override + public Authentication authenticate(Authentication authentication) throws AuthenticationException { + throw new UnsupportedOperationException("No authentication should be done with this AuthenticationManager"); + } + + } +} diff --git a/spring-openid/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java b/spring-openid/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java new file mode 100644 index 0000000000..f0d91fdc27 --- /dev/null +++ b/spring-openid/src/main/java/org/baeldung/security/OpenIdConnectUserDetails.java @@ -0,0 +1,81 @@ +package org.baeldung.security; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.oauth2.common.OAuth2AccessToken; + +public class OpenIdConnectUserDetails implements UserDetails { + + private static final long serialVersionUID = 1L; + + private String userId; + private String username; + private OAuth2AccessToken token; + + public OpenIdConnectUserDetails(Map userInfo, OAuth2AccessToken token) { + this.userId = userInfo.get("sub"); + this.username = userInfo.get("email"); + this.token = token; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public Collection getAuthorities() { + return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")); + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public OAuth2AccessToken getToken() { + return token; + } + + public void setToken(OAuth2AccessToken token) { + this.token = token; + } + + public void setUsername(String username) { + this.username = username; + } + + @Override + public String getPassword() { + return null; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } + +} diff --git a/spring-openid/src/main/resources/application.properties b/spring-openid/src/main/resources/application.properties new file mode 100644 index 0000000000..fa567a164c --- /dev/null +++ b/spring-openid/src/main/resources/application.properties @@ -0,0 +1,6 @@ +server.port=8081 +google.clientId=497324626536-d6fphsh1qpl2o6j2j66nukajrfqc0rtq.apps.googleusercontent.com +google.clientSecret=vtueZycMsrRjjCjnY6JzbEZT +google.accessTokenUri=https://www.googleapis.com/oauth2/v3/token +google.userAuthorizationUri=https://accounts.google.com/o/oauth2/auth +google.redirectUri=http://localhost:8081/google-login \ No newline at end of file From 4b5ad0629a854078437e8248bbbf341165f7e4f8 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sat, 30 Jan 2016 17:48:56 +0100 Subject: [PATCH 126/142] RestEasy Tutorial, CRUD Services example --- RestEasy Example/pom.xml | 91 +++ .../src/main/java/com/baeldung/Movie.java | 535 ++++++++++++++++++ .../baeldung/client/ServicesInterface.java | 44 ++ .../server/service/MovieCrudService.java | 94 +++ .../server/service/RestEasyServices.java | 40 ++ .../src/main/resources/schema1.xsd | 29 + .../main/webapp/WEB-INF/classes/logback.xml | 3 + .../WEB-INF/jboss-deployment-structure.xml | 16 + .../src/main/webapp/WEB-INF/jboss-web.xml | 4 + .../src/main/webapp/WEB-INF/web.xml | 51 ++ .../com/baeldung/server/RestEasyClient.java | 50 ++ .../resources/server/movies/transformer.json | 22 + 12 files changed, 979 insertions(+) create mode 100644 RestEasy Example/pom.xml create mode 100644 RestEasy Example/src/main/java/com/baeldung/Movie.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java create mode 100644 RestEasy Example/src/main/resources/schema1.xsd create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml create mode 100644 RestEasy Example/src/main/webapp/WEB-INF/web.xml create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/resources/server/movies/transformer.json diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml new file mode 100644 index 0000000000..b16c5e8267 --- /dev/null +++ b/RestEasy Example/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + com.baeldung + resteasy-tutorial + 1.0 + war + + + + jboss + http://repository.jboss.org/nexus/content/groups/public/ + + + + + 3.0.14.Final + runtime + + + + RestEasyTutorial + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + org.jboss.resteasy + jaxrs-api + 3.0.12.Final + ${resteasy.scope} + + + + org.jboss.resteasy + resteasy-servlet-initializer + ${resteasy.version} + ${resteasy.scope} + + + jboss-jaxrs-api_2.0_spec + org.jboss.spec.javax.ws.rs + + + + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + ${resteasy.scope} + + + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + + + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + ${resteasy.scope} + + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + ${resteasy.scope} + + + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/Movie.java new file mode 100644 index 0000000000..c0041d2e95 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/Movie.java @@ -0,0 +1,535 @@ + +package com.baeldung; + +import javax.xml.bind.annotation.XmlAccessType; +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" +}) +public class Movie { + + protected String actors; + protected String awards; + protected String country; + protected String director; + protected String genre; + protected String imdbID; + protected String imdbRating; + protected String imdbVotes; + protected String language; + protected String metascore; + protected String plot; + protected String poster; + protected String rated; + protected String released; + protected String response; + protected String runtime; + protected String title; + protected String type; + protected String writer; + protected String year; + + /** + * Recupera il valore della propriet� actors. + * + * @return + * possible object is + * {@link String } + * + */ + public String getActors() { + return actors; + } + + /** + * Imposta il valore della propriet� actors. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setActors(String value) { + this.actors = value; + } + + /** + * Recupera il valore della propriet� awards. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAwards() { + return awards; + } + + /** + * Imposta il valore della propriet� awards. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAwards(String value) { + this.awards = value; + } + + /** + * Recupera il valore della propriet� country. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCountry() { + return country; + } + + /** + * Imposta il valore della propriet� country. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCountry(String value) { + this.country = value; + } + + /** + * Recupera il valore della propriet� director. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDirector() { + return director; + } + + /** + * Imposta il valore della propriet� director. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDirector(String value) { + this.director = value; + } + + /** + * Recupera il valore della propriet� genre. + * + * @return + * possible object is + * {@link String } + * + */ + public String getGenre() { + return genre; + } + + /** + * Imposta il valore della propriet� genre. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setGenre(String value) { + this.genre = value; + } + + /** + * Recupera il valore della propriet� imdbID. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbID() { + return imdbID; + } + + /** + * Imposta il valore della propriet� imdbID. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbID(String value) { + this.imdbID = value; + } + + /** + * Recupera il valore della propriet� imdbRating. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbRating() { + return imdbRating; + } + + /** + * Imposta il valore della propriet� imdbRating. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbRating(String value) { + this.imdbRating = value; + } + + /** + * Recupera il valore della propriet� imdbVotes. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbVotes() { + return imdbVotes; + } + + /** + * Imposta il valore della propriet� imdbVotes. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbVotes(String value) { + this.imdbVotes = value; + } + + /** + * Recupera il valore della propriet� language. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLanguage() { + return language; + } + + /** + * Imposta il valore della propriet� language. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLanguage(String value) { + this.language = value; + } + + /** + * Recupera il valore della propriet� metascore. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMetascore() { + return metascore; + } + + /** + * Imposta il valore della propriet� metascore. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMetascore(String value) { + this.metascore = value; + } + + /** + * Recupera il valore della propriet� plot. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPlot() { + return plot; + } + + /** + * Imposta il valore della propriet� plot. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPlot(String value) { + this.plot = value; + } + + /** + * Recupera il valore della propriet� poster. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPoster() { + return poster; + } + + /** + * Imposta il valore della propriet� poster. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPoster(String value) { + this.poster = value; + } + + /** + * Recupera il valore della propriet� rated. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRated() { + return rated; + } + + /** + * Imposta il valore della propriet� rated. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRated(String value) { + this.rated = value; + } + + /** + * Recupera il valore della propriet� released. + * + * @return + * possible object is + * {@link String } + * + */ + public String getReleased() { + return released; + } + + /** + * Imposta il valore della propriet� released. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setReleased(String value) { + this.released = value; + } + + /** + * Recupera il valore della propriet� response. + * + * @return + * possible object is + * {@link String } + * + */ + public String getResponse() { + return response; + } + + /** + * Imposta il valore della propriet� response. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setResponse(String value) { + this.response = value; + } + + /** + * Recupera il valore della propriet� runtime. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRuntime() { + return runtime; + } + + /** + * Imposta il valore della propriet� runtime. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRuntime(String value) { + this.runtime = value; + } + + /** + * Recupera il valore della propriet� title. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Imposta il valore della propriet� title. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Recupera il valore della propriet� type. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Imposta il valore della propriet� type. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Recupera il valore della propriet� writer. + * + * @return + * possible object is + * {@link String } + * + */ + public String getWriter() { + return writer; + } + + /** + * Imposta il valore della propriet� writer. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setWriter(String value) { + this.writer = value; + } + + /** + * Recupera il valore della propriet� year. + * + * @return + * possible object is + * {@link String } + * + */ + public String getYear() { + return year; + } + + /** + * Imposta il valore della propriet� year. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setYear(String value) { + this.year = value; + } + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java new file mode 100644 index 0000000000..53e88961be --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -0,0 +1,44 @@ +package com.baeldung.client; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + + +public interface ServicesInterface { + + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + + + @POST + @Path("/addmovie") + @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Response addMovie(Movie movie); + + + @PUT + @Path("/updatemovie") + @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + Response updateMovie(Movie movie); + + + @DELETE + @Path("/deletemovie") + Response deleteMovie(@QueryParam("imdbID") String imdbID); + + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java new file mode 100644 index 0000000000..d1973e7037 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java @@ -0,0 +1,94 @@ +package com.baeldung.server.service; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@Path("/movies") +public class MovieCrudService { + + + private Map inventory = new HashMap(); + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ + + System.out.println("*** Calling getinfo ***"); + + Movie movie=new Movie(); + movie.setImdbID(imdbID); + return movie; + } + + @POST + @Path("/addmovie") + @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(); + } + 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){ + + 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(); + } + inventory.put(movie.getImdbID(),movie); + return Response.status(Response.Status.OK).build(); + + } + + + @DELETE + @Path("/deletemovie") + 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(); + } + + inventory.remove(imdbID); + return Response.status(Response.Status.OK).build(); + } + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + public List listMovies(){ + + return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); + + } + + + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java new file mode 100644 index 0000000000..16b6200ad1 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java @@ -0,0 +1,40 @@ +package com.baeldung.server.service; + + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Created by Admin on 29/01/2016. + */ + + + +@ApplicationPath("/rest") +public class RestEasyServices extends Application { + + private Set singletons = new HashSet(); + + public RestEasyServices() { + singletons.add(new MovieCrudService()); + } + + @Override + public Set getSingletons() { + return singletons; + } + + @Override + public Set> getClasses() { + return super.getClasses(); + } + + @Override + public Map getProperties() { + return super.getProperties(); + } +} diff --git a/RestEasy Example/src/main/resources/schema1.xsd b/RestEasy Example/src/main/resources/schema1.xsd new file mode 100644 index 0000000000..0d74b7c366 --- /dev/null +++ b/RestEasy Example/src/main/resources/schema1.xsd @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml b/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml new file mode 100644 index 0000000000..d94e9f71ab --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/classes/logback.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml new file mode 100644 index 0000000000..84d75934a7 --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000000..694bb71332 --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..c66d3b56ae --- /dev/null +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,51 @@ + + + + RestEasy Example + + + + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap + + + + RestEasy Example + + + webAppRootKey + RestEasyExample + + + + + + resteasy.servlet.mapping.prefix + /rest + + + + + resteasy-servlet + + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher + + + javax.ws.rs.Application + com.baeldung.server.service.RestEasyServices + + + + + resteasy-servlet + /rest/* + + + + + index.html + + + + \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java new file mode 100644 index 0000000000..e711233979 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -0,0 +1,50 @@ +package com.baeldung.server; + +import com.baeldung.Movie; +import com.baeldung.client.ServicesInterface; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; + +import java.util.List; + +public class RestEasyClient { + + public static void main(String[] args) { + + Movie st = new Movie(); + st.setImdbID("12345"); + + /* + * Alternatively you can use this simple String to send + * instead of using a Student instance + * + * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; + */ + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + + ServicesInterface simple = target.proxy(ServicesInterface.class); + final List movies = simple.listMovies(); + + /* + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + + System.out.println("Server response : \n"); + System.out.println(response.readEntity(String.class)); + + response.close(); +*/ + } catch (Exception e) { + + e.printStackTrace(); + + } + } + +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/server/movies/transformer.json new file mode 100644 index 0000000000..2154868265 --- /dev/null +++ b/RestEasy Example/src/test/resources/server/movies/transformer.json @@ -0,0 +1,22 @@ +{ + "title": "Transformers", + "year": "2007", + "rated": "PG-13", + "released": "03 Jul 2007", + "runtime": "144 min", + "genre": "Action, Adventure, Sci-Fi", + "director": "Michael Bay", + "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", + "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", + "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", + "language": "English, Spanish", + "country": "USA", + "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", + "metascore": "61", + "imdbRating": "7.1", + "imdbVotes": "492,225", + "imdbID": "tt0418279", + "Type": "movie", + "response": "True" +} \ No newline at end of file From 663def8e2c00957b8913afcb118bde494c85f987 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sat, 30 Jan 2016 20:39:28 +0100 Subject: [PATCH 127/142] Added testCase for List All Movies and Add a Movie --- RestEasy Example/pom.xml | 29 +++++ .../baeldung/client/ServicesInterface.java | 6 +- .../java/com/baeldung/{ => model}/Movie.java | 45 +++++++- .../{service => }/MovieCrudService.java | 5 +- .../{service => }/RestEasyServices.java | 2 +- .../com/baeldung/server/RestEasyClient.java | 104 ++++++++++++++---- .../com/baeldung/server/movies/batman.json | 22 ++++ .../baeldung}/server/movies/transformer.json | 2 +- 8 files changed, 184 insertions(+), 31 deletions(-) rename RestEasy Example/src/main/java/com/baeldung/{ => model}/Movie.java (86%) rename RestEasy Example/src/main/java/com/baeldung/server/{service => }/MovieCrudService.java (96%) rename RestEasy Example/src/main/java/com/baeldung/server/{service => }/RestEasyServices.java (95%) create mode 100644 RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json rename RestEasy Example/src/test/resources/{ => com/baeldung}/server/movies/transformer.json (99%) diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index b16c5e8267..8dabfc863b 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -85,6 +85,35 @@ ${resteasy.scope} + + + + junit + junit + 4.4 + + + + commons-io + commons-io + 2.4 + + + + com.fasterxml.jackson.core + jackson-core + 2.7.0 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.7.0 + + + + + diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 53e88961be..2585c32438 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -1,15 +1,13 @@ package com.baeldung.client; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; - +@Path("/movies") public interface ServicesInterface { diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java similarity index 86% rename from RestEasy Example/src/main/java/com/baeldung/Movie.java rename to RestEasy Example/src/main/java/com/baeldung/model/Movie.java index c0041d2e95..052ba081c1 100644 --- a/RestEasy Example/src/main/java/com/baeldung/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -1,5 +1,5 @@ -package com.baeldung; +package com.baeldung.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -532,4 +532,47 @@ public class Movie { this.year = value; } + @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 + '\'' + + '}'; + } + + @Override + public boolean equals(Object o) { + 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; + return title != null ? title.equals(movie.title) : movie.title == null; + + } + + @Override + public int hashCode() { + int result = imdbID != null ? imdbID.hashCode() : 0; + result = 31 * result + (title != null ? title.hashCode() : 0); + return result; + } } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java similarity index 96% rename from RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java rename to RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index d1973e7037..60e0121966 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -1,11 +1,10 @@ -package com.baeldung.server.service; +package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java similarity index 95% rename from RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java rename to RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java index 16b6200ad1..8c57d2c9b4 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java @@ -1,4 +1,4 @@ -package com.baeldung.server.service; +package com.baeldung.server; import javax.ws.rs.ApplicationPath; diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java index e711233979..c77f494862 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -1,49 +1,111 @@ package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import javax.naming.NamingException; +import javax.ws.rs.core.Link; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.List; +import java.util.Locale; public class RestEasyClient { - public static void main(String[] args) { - Movie st = new Movie(); - st.setImdbID("12345"); + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; - /* - * Alternatively you can use this simple String to send - * instead of using a Student instance - * - * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; - */ + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + @Test + public void testListAllMovies() { try { ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ServicesInterface simple = target.proxy(ServicesInterface.class); - final List movies = simple.listMovies(); + final Response moviesResponse = simple.addMovie(batmanMovie); - /* - if (response.getStatus() != 200) { + if (moviesResponse.getStatus() != 201) { + System.out.println(moviesResponse.readEntity(String.class)); throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); + + moviesResponse.getStatus()); } - System.out.println("Server response : \n"); - System.out.println(response.readEntity(String.class)); + moviesResponse.close(); - response.close(); -*/ } catch (Exception e) { - e.printStackTrace(); - } } diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json new file mode 100644 index 0000000000..28061d5bf9 --- /dev/null +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json @@ -0,0 +1,22 @@ +{ + "title": "Batman", + "year": "1989", + "rated": "PG-13", + "released": "23 Jun 1989", + "runtime": "126 min", + "genre": "Action, Adventure", + "director": "Tim Burton", + "writer": "Bob Kane (Batman characters), Sam Hamm (story), Sam Hamm (screenplay), Warren Skaaren (screenplay)", + "actors": "Michael Keaton, Jack Nicholson, Kim Basinger, Robert Wuhl", + "plot": "The Dark Knight of Gotham City begins his war on crime with his first major enemy being the clownishly homicidal Joker.", + "language": "English, French", + "country": "USA, UK", + "awards": "Won 1 Oscar. Another 9 wins & 22 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTYwNjAyODIyMF5BMl5BanBnXkFtZTYwNDMwMDk2._V1_SX300.jpg", + "metascore": "66", + "imdbRating": "7.6", + "imdbVotes": "256,000", + "imdbID": "tt0096895", + "type": "movie", + "response": "True" +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json similarity index 99% rename from RestEasy Example/src/test/resources/server/movies/transformer.json rename to RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json index 2154868265..a3b033a8ba 100644 --- a/RestEasy Example/src/test/resources/server/movies/transformer.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json @@ -17,6 +17,6 @@ "imdbRating": "7.1", "imdbVotes": "492,225", "imdbID": "tt0418279", - "Type": "movie", + "type": "movie", "response": "True" } \ No newline at end of file From b39ec7d76ee55ffe0165aa82ff23f2da3bd8475c Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sun, 31 Jan 2016 11:05:11 +0100 Subject: [PATCH 128/142] Added testCase for all Services --- RestEasy Example/pom.xml | 15 -- .../baeldung/client/ServicesInterface.java | 10 +- .../com/baeldung/server/MovieCrudService.java | 15 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- .../com/baeldung/server/RestEasyClient.java | 112 ----------- .../baeldung/server/RestEasyClientTest.java | 189 ++++++++++++++++++ 6 files changed, 206 insertions(+), 137 deletions(-) delete mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 8dabfc863b..6935238d91 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -99,21 +99,6 @@ 2.4 - - com.fasterxml.jackson.core - jackson-core - 2.7.0 - - - - com.fasterxml.jackson.core - jackson-annotations - 2.7.0 - - - - - diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 2585c32438..7efed546d8 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -17,6 +17,12 @@ public interface ServicesInterface { Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -34,9 +40,5 @@ public interface ServicesInterface { Response deleteMovie(@QueryParam("imdbID") String imdbID); - @GET - @Path("/listmovies") - @Produces({"application/json"}) - List listMovies(); } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 60e0121966..18366e2faa 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -18,18 +18,21 @@ public class MovieCrudService { private Map inventory = new HashMap(); + @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ - System.out.println("*** Calling getinfo ***"); + System.out.println("*** Calling getinfo for a given ImdbID***"); + + if(inventory.containsKey(imdbID)){ + return inventory.get(imdbID); + }else return null; - Movie movie=new Movie(); - movie.setImdbID(imdbID); - return movie; } + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -41,6 +44,7 @@ public class MovieCrudService { return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is Already in the database.").build(); } + inventory.put(movie.getImdbID(),movie); return Response.status(Response.Status.CREATED).build(); @@ -54,7 +58,7 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + if (null==inventory.get(movie.getImdbID())){ return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is not in the database.\nUnable to Update").build(); } @@ -79,6 +83,7 @@ public class MovieCrudService { return Response.status(Response.Status.OK).build(); } + @GET @Path("/listmovies") @Produces({"application/json"}) diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index c66d3b56ae..ab3bc1aa83 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -33,7 +33,7 @@ javax.ws.rs.Application - com.baeldung.server.service.RestEasyServices + com.baeldung.server.RestEasyServices diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java deleted file mode 100644 index c77f494862..0000000000 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.baeldung.server; - -import com.baeldung.model.Movie; -import com.baeldung.client.ServicesInterface; -import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.naming.NamingException; -import javax.ws.rs.core.Link; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -public class RestEasyClient { - - - Movie transformerMovie=null; - Movie batmanMovie=null; - ObjectMapper jsonMapper=null; - - @BeforeClass - public static void loadMovieInventory(){ - - - - } - - @Before - public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - - - 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); - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { - String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { - String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); - - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - } - - @Test - public void testListAllMovies() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - - - @Test - public void testAddMovie() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - - ServicesInterface simple = target.proxy(ServicesInterface.class); - final Response moviesResponse = simple.addMovie(batmanMovie); - - if (moviesResponse.getStatus() != 201) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " - + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java new file mode 100644 index 0000000000..fb4205bcd7 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -0,0 +1,189 @@ +package com.baeldung.server; + +import com.baeldung.model.Movie; +import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.naming.NamingException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Locale; + +public class RestEasyClientTest { + + + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; + + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + + @Test + public void testListAllMovies() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testMovieByImdbID() { + + String transformerImdbId="tt0418279"; + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + + final Movie movies = simple.movieByImdbID(transformerImdbId); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(transformerMovie); + + if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { + //System.out.println(moviesResponse.readEntity(String.class)); + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testDeleteMovie() { + + String transformerImdbId="tt0418279"; + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.deleteMovie(transformerImdbId); + moviesResponse.close(); + + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println(moviesResponse.readEntity(String.class)); + throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testUpdateMovie() { + + try { + + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + batmanMovie.setImdbVotes("300,000"); + moviesResponse = simple.updateMovie(batmanMovie); + + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + //System.out.println(moviesResponse.readEntity(String.class)); + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); + } + + moviesResponse.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file From 5cdf7185a4eed764473b76b365f14c2737f7c0bb Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:29:30 +0100 Subject: [PATCH 129/142] Minor Bugfix --- .../baeldung/client/ServicesInterface.java | 4 +- .../main/java/com/baeldung/model/Movie.java | 22 +-- .../com/baeldung/server/MovieCrudService.java | 12 +- .../src/main/webapp/WEB-INF/web.xml | 37 +---- .../java/baeldung/client/RestEasyClient.java | 7 + .../baeldung/server/RestEasyClientTest.java | 149 +++++++----------- 6 files changed, 81 insertions(+), 150 deletions(-) create mode 100644 RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 7efed546d8..749cabc757 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -14,7 +14,7 @@ public interface ServicesInterface { @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) - Movie movieByImdbID(@QueryParam("imdbID") String imdbID); + Movie movieByImdbId(@QueryParam("imdbId") String imdbId); @GET @@ -37,7 +37,7 @@ public interface ServicesInterface { @DELETE @Path("/deletemovie") - Response deleteMovie(@QueryParam("imdbID") String imdbID); + Response deleteMovie(@QueryParam("imdbId") String imdbID); diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 052ba081c1..a2b2bd5250 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType; "country", "director", "genre", - "imdbID", + "imdbId", "imdbRating", "imdbVotes", "language", @@ -36,7 +36,7 @@ public class Movie { protected String country; protected String director; protected String genre; - protected String imdbID; + protected String imdbId; protected String imdbRating; protected String imdbVotes; protected String language; @@ -173,27 +173,27 @@ public class Movie { } /** - * Recupera il valore della propriet� imdbID. + * Recupera il valore della propriet� imdbId. * * @return * possible object is * {@link String } * */ - public String getImdbID() { - return imdbID; + public String getImdbId() { + return imdbId; } /** - * Imposta il valore della propriet� imdbID. + * Imposta il valore della propriet� imdbId. * * @param value * allowed object is * {@link String } * */ - public void setImdbID(String value) { - this.imdbID = value; + public void setImdbId(String value) { + this.imdbId = value; } /** @@ -540,7 +540,7 @@ public class Movie { ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + - ", imdbID='" + imdbID + '\'' + + ", imdbId='" + imdbId + '\'' + ", imdbRating='" + imdbRating + '\'' + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + @@ -564,14 +564,14 @@ public class Movie { 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; } @Override public int hashCode() { - int result = imdbID != null ? imdbID.hashCode() : 0; + int result = imdbId != null ? imdbId.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); return result; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 18366e2faa..29226aa0e0 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -22,7 +22,7 @@ public class MovieCrudService { @GET @Path("/getinfo") @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***"); @@ -40,12 +40,12 @@ public class MovieCrudService { System.out.println("*** Calling addMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + 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(); } @@ -58,11 +58,11 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null==inventory.get(movie.getImdbID())){ + 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(); } @@ -70,7 +70,7 @@ public class MovieCrudService { @DELETE @Path("/deletemovie") - public Response deleteMovie(@QueryParam("imdbID") String imdbID){ + public Response deleteMovie(@QueryParam("imdbId") String imdbID){ System.out.println("*** Calling deleteMovie ***"); diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index ab3bc1aa83..f70fdf7975 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -5,47 +5,12 @@ RestEasy Example - - - org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap - - - - RestEasy Example - - - webAppRootKey - RestEasyExample - - - - + resteasy.servlet.mapping.prefix /rest - - resteasy-servlet - - org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher - - - javax.ws.rs.Application - com.baeldung.server.RestEasyServices - - - - - resteasy-servlet - /rest/* - - - - - index.html - - \ No newline at end of file diff --git a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java new file mode 100644 index 0000000000..b474b3d4f8 --- /dev/null +++ b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java @@ -0,0 +1,7 @@ +package baeldung.client; + +/** + * Created by Admin on 29/01/2016. + */ +public class RestEasyClient { +} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index fb4205bcd7..b6a2e2a0c1 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -1,7 +1,7 @@ package com.baeldung.server; -import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import com.baeldung.model.Movie; import org.apache.commons.io.IOUtils; import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; @@ -9,7 +9,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import javax.naming.NamingException; @@ -23,22 +22,13 @@ import java.util.Locale; public class RestEasyClientTest { - Movie transformerMovie=null; Movie batmanMovie=null; ObjectMapper jsonMapper=null; - @BeforeClass - public static void loadMovieInventory(){ - - - - } - @Before public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - 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); @@ -57,133 +47,102 @@ public class RestEasyClientTest { batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException("Test is going to die ...", e); } - } - @Test public void testListAllMovies() { - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } + List movies = simple.listMovies(); + System.out.println(movies); } - @Test - public void testMovieByImdbID() { + public void testMovieByImdbId() { String transformerImdbId="tt0418279"; - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); + Response moviesResponse = simple.addMovie(transformerMovie); + moviesResponse.close(); - final Movie movies = simple.movieByImdbID(transformerImdbId); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } + Movie movies = simple.movieByImdbId(transformerImdbId); + System.out.println(movies); } @Test public void testAddMovie() { - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(transformerMovie); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.addMovie(transformerMovie); - if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { - //System.out.println(moviesResponse.readEntity(String.class)); - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } @Test - public void testDeleteMovie() { + public void testDeleteMovi1e() { - String transformerImdbId="tt0418279"; + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + moviesResponse = simple.deleteMovie(batmanMovie.getImdbId()); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.deleteMovie(transformerImdbId); - moviesResponse.close(); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println(moviesResponse.readEntity(String.class)); + throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } @Test public void testUpdateMovie() { - try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); + Response moviesResponse = simple.addMovie(batmanMovie); + moviesResponse.close(); + batmanMovie.setImdbVotes("300,000"); + moviesResponse = simple.updateMovie(batmanMovie); - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - batmanMovie.setImdbVotes("300,000"); - moviesResponse = simple.updateMovie(batmanMovie); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - //System.out.println(moviesResponse.readEntity(String.class)); - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); + if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { + System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); } + + moviesResponse.close(); + System.out.println("Response Code: "+Response.Status.OK.getStatusCode()); } } \ No newline at end of file From 9b5818262decbcfcfc302ab15c5f3347dbaeecfd Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sat, 30 Jan 2016 17:48:56 +0100 Subject: [PATCH 130/142] RestEasy Tutorial, CRUD Services example --- .../src/main/java/com/baeldung/Movie.java | 535 ++++++++++++++++++ .../server/service/MovieCrudService.java | 94 +++ .../server/service/RestEasyServices.java | 40 ++ .../com/baeldung/server/RestEasyClient.java | 50 ++ .../resources/server/movies/transformer.json | 22 + 5 files changed, 741 insertions(+) create mode 100644 RestEasy Example/src/main/java/com/baeldung/Movie.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java create mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java create mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java create mode 100644 RestEasy Example/src/test/resources/server/movies/transformer.json diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/Movie.java new file mode 100644 index 0000000000..c0041d2e95 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/Movie.java @@ -0,0 +1,535 @@ + +package com.baeldung; + +import javax.xml.bind.annotation.XmlAccessType; +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" +}) +public class Movie { + + protected String actors; + protected String awards; + protected String country; + protected String director; + protected String genre; + protected String imdbID; + protected String imdbRating; + protected String imdbVotes; + protected String language; + protected String metascore; + protected String plot; + protected String poster; + protected String rated; + protected String released; + protected String response; + protected String runtime; + protected String title; + protected String type; + protected String writer; + protected String year; + + /** + * Recupera il valore della propriet� actors. + * + * @return + * possible object is + * {@link String } + * + */ + public String getActors() { + return actors; + } + + /** + * Imposta il valore della propriet� actors. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setActors(String value) { + this.actors = value; + } + + /** + * Recupera il valore della propriet� awards. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAwards() { + return awards; + } + + /** + * Imposta il valore della propriet� awards. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAwards(String value) { + this.awards = value; + } + + /** + * Recupera il valore della propriet� country. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCountry() { + return country; + } + + /** + * Imposta il valore della propriet� country. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCountry(String value) { + this.country = value; + } + + /** + * Recupera il valore della propriet� director. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDirector() { + return director; + } + + /** + * Imposta il valore della propriet� director. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDirector(String value) { + this.director = value; + } + + /** + * Recupera il valore della propriet� genre. + * + * @return + * possible object is + * {@link String } + * + */ + public String getGenre() { + return genre; + } + + /** + * Imposta il valore della propriet� genre. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setGenre(String value) { + this.genre = value; + } + + /** + * Recupera il valore della propriet� imdbID. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbID() { + return imdbID; + } + + /** + * Imposta il valore della propriet� imdbID. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbID(String value) { + this.imdbID = value; + } + + /** + * Recupera il valore della propriet� imdbRating. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbRating() { + return imdbRating; + } + + /** + * Imposta il valore della propriet� imdbRating. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbRating(String value) { + this.imdbRating = value; + } + + /** + * Recupera il valore della propriet� imdbVotes. + * + * @return + * possible object is + * {@link String } + * + */ + public String getImdbVotes() { + return imdbVotes; + } + + /** + * Imposta il valore della propriet� imdbVotes. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setImdbVotes(String value) { + this.imdbVotes = value; + } + + /** + * Recupera il valore della propriet� language. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLanguage() { + return language; + } + + /** + * Imposta il valore della propriet� language. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLanguage(String value) { + this.language = value; + } + + /** + * Recupera il valore della propriet� metascore. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMetascore() { + return metascore; + } + + /** + * Imposta il valore della propriet� metascore. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMetascore(String value) { + this.metascore = value; + } + + /** + * Recupera il valore della propriet� plot. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPlot() { + return plot; + } + + /** + * Imposta il valore della propriet� plot. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPlot(String value) { + this.plot = value; + } + + /** + * Recupera il valore della propriet� poster. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPoster() { + return poster; + } + + /** + * Imposta il valore della propriet� poster. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPoster(String value) { + this.poster = value; + } + + /** + * Recupera il valore della propriet� rated. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRated() { + return rated; + } + + /** + * Imposta il valore della propriet� rated. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRated(String value) { + this.rated = value; + } + + /** + * Recupera il valore della propriet� released. + * + * @return + * possible object is + * {@link String } + * + */ + public String getReleased() { + return released; + } + + /** + * Imposta il valore della propriet� released. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setReleased(String value) { + this.released = value; + } + + /** + * Recupera il valore della propriet� response. + * + * @return + * possible object is + * {@link String } + * + */ + public String getResponse() { + return response; + } + + /** + * Imposta il valore della propriet� response. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setResponse(String value) { + this.response = value; + } + + /** + * Recupera il valore della propriet� runtime. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRuntime() { + return runtime; + } + + /** + * Imposta il valore della propriet� runtime. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRuntime(String value) { + this.runtime = value; + } + + /** + * Recupera il valore della propriet� title. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Imposta il valore della propriet� title. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Recupera il valore della propriet� type. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Imposta il valore della propriet� type. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Recupera il valore della propriet� writer. + * + * @return + * possible object is + * {@link String } + * + */ + public String getWriter() { + return writer; + } + + /** + * Imposta il valore della propriet� writer. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setWriter(String value) { + this.writer = value; + } + + /** + * Recupera il valore della propriet� year. + * + * @return + * possible object is + * {@link String } + * + */ + public String getYear() { + return year; + } + + /** + * Imposta il valore della propriet� year. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setYear(String value) { + this.year = value; + } + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java new file mode 100644 index 0000000000..d1973e7037 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java @@ -0,0 +1,94 @@ +package com.baeldung.server.service; + +import com.baeldung.Movie; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@Path("/movies") +public class MovieCrudService { + + + private Map inventory = new HashMap(); + + @GET + @Path("/getinfo") + @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) + public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ + + System.out.println("*** Calling getinfo ***"); + + Movie movie=new Movie(); + movie.setImdbID(imdbID); + return movie; + } + + @POST + @Path("/addmovie") + @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(); + } + 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){ + + 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(); + } + inventory.put(movie.getImdbID(),movie); + return Response.status(Response.Status.OK).build(); + + } + + + @DELETE + @Path("/deletemovie") + 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(); + } + + inventory.remove(imdbID); + return Response.status(Response.Status.OK).build(); + } + + @GET + @Path("/listmovies") + @Produces({"application/json"}) + public List listMovies(){ + + return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); + + } + + + +} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java new file mode 100644 index 0000000000..16b6200ad1 --- /dev/null +++ b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java @@ -0,0 +1,40 @@ +package com.baeldung.server.service; + + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Created by Admin on 29/01/2016. + */ + + + +@ApplicationPath("/rest") +public class RestEasyServices extends Application { + + private Set singletons = new HashSet(); + + public RestEasyServices() { + singletons.add(new MovieCrudService()); + } + + @Override + public Set getSingletons() { + return singletons; + } + + @Override + public Set> getClasses() { + return super.getClasses(); + } + + @Override + public Map getProperties() { + return super.getProperties(); + } +} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java new file mode 100644 index 0000000000..e711233979 --- /dev/null +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -0,0 +1,50 @@ +package com.baeldung.server; + +import com.baeldung.Movie; +import com.baeldung.client.ServicesInterface; +import org.jboss.resteasy.client.jaxrs.ResteasyClient; +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; + +import java.util.List; + +public class RestEasyClient { + + public static void main(String[] args) { + + Movie st = new Movie(); + st.setImdbID("12345"); + + /* + * Alternatively you can use this simple String to send + * instead of using a Student instance + * + * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; + */ + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + + ServicesInterface simple = target.proxy(ServicesInterface.class); + final List movies = simple.listMovies(); + + /* + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + + System.out.println("Server response : \n"); + System.out.println(response.readEntity(String.class)); + + response.close(); +*/ + } catch (Exception e) { + + e.printStackTrace(); + + } + } + +} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/server/movies/transformer.json new file mode 100644 index 0000000000..2154868265 --- /dev/null +++ b/RestEasy Example/src/test/resources/server/movies/transformer.json @@ -0,0 +1,22 @@ +{ + "title": "Transformers", + "year": "2007", + "rated": "PG-13", + "released": "03 Jul 2007", + "runtime": "144 min", + "genre": "Action, Adventure, Sci-Fi", + "director": "Michael Bay", + "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", + "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", + "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", + "language": "English, Spanish", + "country": "USA", + "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", + "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", + "metascore": "61", + "imdbRating": "7.1", + "imdbVotes": "492,225", + "imdbID": "tt0418279", + "Type": "movie", + "response": "True" +} \ No newline at end of file From df982db26b1a356a77b0b9eaf1ba6e2bb32c9b51 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sat, 30 Jan 2016 20:39:28 +0100 Subject: [PATCH 131/142] Added testCase for List All Movies and Add a Movie --- .../src/main/java/com/baeldung/Movie.java | 535 ------------------ .../main/java/com/baeldung/model/Movie.java | 22 +- .../com/baeldung/server/MovieCrudService.java | 25 +- .../server/service/MovieCrudService.java | 94 --- .../server/service/RestEasyServices.java | 40 -- .../com/baeldung/server/RestEasyClient.java | 104 +++- .../resources/server/movies/transformer.json | 22 - 7 files changed, 104 insertions(+), 738 deletions(-) delete mode 100644 RestEasy Example/src/main/java/com/baeldung/Movie.java delete mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java delete mode 100644 RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java delete mode 100644 RestEasy Example/src/test/resources/server/movies/transformer.json diff --git a/RestEasy Example/src/main/java/com/baeldung/Movie.java b/RestEasy Example/src/main/java/com/baeldung/Movie.java deleted file mode 100644 index c0041d2e95..0000000000 --- a/RestEasy Example/src/main/java/com/baeldung/Movie.java +++ /dev/null @@ -1,535 +0,0 @@ - -package com.baeldung; - -import javax.xml.bind.annotation.XmlAccessType; -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" -}) -public class Movie { - - protected String actors; - protected String awards; - protected String country; - protected String director; - protected String genre; - protected String imdbID; - protected String imdbRating; - protected String imdbVotes; - protected String language; - protected String metascore; - protected String plot; - protected String poster; - protected String rated; - protected String released; - protected String response; - protected String runtime; - protected String title; - protected String type; - protected String writer; - protected String year; - - /** - * Recupera il valore della propriet� actors. - * - * @return - * possible object is - * {@link String } - * - */ - public String getActors() { - return actors; - } - - /** - * Imposta il valore della propriet� actors. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setActors(String value) { - this.actors = value; - } - - /** - * Recupera il valore della propriet� awards. - * - * @return - * possible object is - * {@link String } - * - */ - public String getAwards() { - return awards; - } - - /** - * Imposta il valore della propriet� awards. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setAwards(String value) { - this.awards = value; - } - - /** - * Recupera il valore della propriet� country. - * - * @return - * possible object is - * {@link String } - * - */ - public String getCountry() { - return country; - } - - /** - * Imposta il valore della propriet� country. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setCountry(String value) { - this.country = value; - } - - /** - * Recupera il valore della propriet� director. - * - * @return - * possible object is - * {@link String } - * - */ - public String getDirector() { - return director; - } - - /** - * Imposta il valore della propriet� director. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setDirector(String value) { - this.director = value; - } - - /** - * Recupera il valore della propriet� genre. - * - * @return - * possible object is - * {@link String } - * - */ - public String getGenre() { - return genre; - } - - /** - * Imposta il valore della propriet� genre. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setGenre(String value) { - this.genre = value; - } - - /** - * Recupera il valore della propriet� imdbID. - * - * @return - * possible object is - * {@link String } - * - */ - public String getImdbID() { - return imdbID; - } - - /** - * Imposta il valore della propriet� imdbID. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setImdbID(String value) { - this.imdbID = value; - } - - /** - * Recupera il valore della propriet� imdbRating. - * - * @return - * possible object is - * {@link String } - * - */ - public String getImdbRating() { - return imdbRating; - } - - /** - * Imposta il valore della propriet� imdbRating. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setImdbRating(String value) { - this.imdbRating = value; - } - - /** - * Recupera il valore della propriet� imdbVotes. - * - * @return - * possible object is - * {@link String } - * - */ - public String getImdbVotes() { - return imdbVotes; - } - - /** - * Imposta il valore della propriet� imdbVotes. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setImdbVotes(String value) { - this.imdbVotes = value; - } - - /** - * Recupera il valore della propriet� language. - * - * @return - * possible object is - * {@link String } - * - */ - public String getLanguage() { - return language; - } - - /** - * Imposta il valore della propriet� language. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setLanguage(String value) { - this.language = value; - } - - /** - * Recupera il valore della propriet� metascore. - * - * @return - * possible object is - * {@link String } - * - */ - public String getMetascore() { - return metascore; - } - - /** - * Imposta il valore della propriet� metascore. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setMetascore(String value) { - this.metascore = value; - } - - /** - * Recupera il valore della propriet� plot. - * - * @return - * possible object is - * {@link String } - * - */ - public String getPlot() { - return plot; - } - - /** - * Imposta il valore della propriet� plot. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setPlot(String value) { - this.plot = value; - } - - /** - * Recupera il valore della propriet� poster. - * - * @return - * possible object is - * {@link String } - * - */ - public String getPoster() { - return poster; - } - - /** - * Imposta il valore della propriet� poster. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setPoster(String value) { - this.poster = value; - } - - /** - * Recupera il valore della propriet� rated. - * - * @return - * possible object is - * {@link String } - * - */ - public String getRated() { - return rated; - } - - /** - * Imposta il valore della propriet� rated. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setRated(String value) { - this.rated = value; - } - - /** - * Recupera il valore della propriet� released. - * - * @return - * possible object is - * {@link String } - * - */ - public String getReleased() { - return released; - } - - /** - * Imposta il valore della propriet� released. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setReleased(String value) { - this.released = value; - } - - /** - * Recupera il valore della propriet� response. - * - * @return - * possible object is - * {@link String } - * - */ - public String getResponse() { - return response; - } - - /** - * Imposta il valore della propriet� response. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setResponse(String value) { - this.response = value; - } - - /** - * Recupera il valore della propriet� runtime. - * - * @return - * possible object is - * {@link String } - * - */ - public String getRuntime() { - return runtime; - } - - /** - * Imposta il valore della propriet� runtime. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setRuntime(String value) { - this.runtime = value; - } - - /** - * Recupera il valore della propriet� title. - * - * @return - * possible object is - * {@link String } - * - */ - public String getTitle() { - return title; - } - - /** - * Imposta il valore della propriet� title. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setTitle(String value) { - this.title = value; - } - - /** - * Recupera il valore della propriet� type. - * - * @return - * possible object is - * {@link String } - * - */ - public String getType() { - return type; - } - - /** - * Imposta il valore della propriet� type. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setType(String value) { - this.type = value; - } - - /** - * Recupera il valore della propriet� writer. - * - * @return - * possible object is - * {@link String } - * - */ - public String getWriter() { - return writer; - } - - /** - * Imposta il valore della propriet� writer. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setWriter(String value) { - this.writer = value; - } - - /** - * Recupera il valore della propriet� year. - * - * @return - * possible object is - * {@link String } - * - */ - public String getYear() { - return year; - } - - /** - * Imposta il valore della propriet� year. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setYear(String value) { - this.year = value; - } - -} diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index a2b2bd5250..052ba081c1 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType; "country", "director", "genre", - "imdbId", + "imdbID", "imdbRating", "imdbVotes", "language", @@ -36,7 +36,7 @@ public class Movie { protected String country; protected String director; protected String genre; - protected String imdbId; + protected String imdbID; protected String imdbRating; protected String imdbVotes; protected String language; @@ -173,27 +173,27 @@ public class Movie { } /** - * Recupera il valore della propriet� imdbId. + * Recupera il valore della propriet� imdbID. * * @return * possible object is * {@link String } * */ - public String getImdbId() { - return imdbId; + public String getImdbID() { + return imdbID; } /** - * Imposta il valore della propriet� imdbId. + * Imposta il valore della propriet� imdbID. * * @param value * allowed object is * {@link String } * */ - public void setImdbId(String value) { - this.imdbId = value; + public void setImdbID(String value) { + this.imdbID = value; } /** @@ -540,7 +540,7 @@ public class Movie { ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + - ", imdbId='" + imdbId + '\'' + + ", imdbID='" + imdbID + '\'' + ", imdbRating='" + imdbRating + '\'' + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + @@ -564,14 +564,14 @@ public class Movie { 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; } @Override public int hashCode() { - int result = imdbId != null ? imdbId.hashCode() : 0; + int result = imdbID != null ? imdbID.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); return result; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 29226aa0e0..60e0121966 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -18,21 +18,18 @@ public class MovieCrudService { private Map inventory = new HashMap(); - @GET @Path("/getinfo") @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***"); - - if(inventory.containsKey(imdbID)){ - return inventory.get(imdbID); - }else return null; + System.out.println("*** Calling getinfo ***"); + Movie movie=new Movie(); + movie.setImdbID(imdbID); + return movie; } - @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -40,12 +37,11 @@ public class MovieCrudService { System.out.println("*** Calling addMovie ***"); - if (null!=inventory.get(movie.getImdbId())){ + 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(); } @@ -58,11 +54,11 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null==inventory.get(movie.getImdbId())){ + 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(); } @@ -70,7 +66,7 @@ public class MovieCrudService { @DELETE @Path("/deletemovie") - public Response deleteMovie(@QueryParam("imdbId") String imdbID){ + public Response deleteMovie(@QueryParam("imdbID") String imdbID){ System.out.println("*** Calling deleteMovie ***"); @@ -83,7 +79,6 @@ public class MovieCrudService { return Response.status(Response.Status.OK).build(); } - @GET @Path("/listmovies") @Produces({"application/json"}) diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java deleted file mode 100644 index d1973e7037..0000000000 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/MovieCrudService.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.baeldung.server.service; - -import com.baeldung.Movie; - -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - - -@Path("/movies") -public class MovieCrudService { - - - private Map inventory = new HashMap(); - - @GET - @Path("/getinfo") - @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) - public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ - - System.out.println("*** Calling getinfo ***"); - - Movie movie=new Movie(); - movie.setImdbID(imdbID); - return movie; - } - - @POST - @Path("/addmovie") - @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(); - } - 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){ - - 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(); - } - inventory.put(movie.getImdbID(),movie); - return Response.status(Response.Status.OK).build(); - - } - - - @DELETE - @Path("/deletemovie") - 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(); - } - - inventory.remove(imdbID); - return Response.status(Response.Status.OK).build(); - } - - @GET - @Path("/listmovies") - @Produces({"application/json"}) - public List listMovies(){ - - return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); - - } - - - -} diff --git a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java deleted file mode 100644 index 16b6200ad1..0000000000 --- a/RestEasy Example/src/main/java/com/baeldung/server/service/RestEasyServices.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.server.service; - - -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Created by Admin on 29/01/2016. - */ - - - -@ApplicationPath("/rest") -public class RestEasyServices extends Application { - - private Set singletons = new HashSet(); - - public RestEasyServices() { - singletons.add(new MovieCrudService()); - } - - @Override - public Set getSingletons() { - return singletons; - } - - @Override - public Set> getClasses() { - return super.getClasses(); - } - - @Override - public Map getProperties() { - return super.getProperties(); - } -} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java index e711233979..c77f494862 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java @@ -1,49 +1,111 @@ package com.baeldung.server; -import com.baeldung.Movie; +import com.baeldung.model.Movie; import com.baeldung.client.ServicesInterface; +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import javax.naming.NamingException; +import javax.ws.rs.core.Link; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.List; +import java.util.Locale; public class RestEasyClient { - public static void main(String[] args) { - Movie st = new Movie(); - st.setImdbID("12345"); + Movie transformerMovie=null; + Movie batmanMovie=null; + ObjectMapper jsonMapper=null; - /* - * Alternatively you can use this simple String to send - * instead of using a Student instance - * - * String jsonString = "{\"id\":12,\"firstName\":\"Catain\",\"lastName\":\"Hook\",\"age\":10}"; - */ + @BeforeClass + public static void loadMovieInventory(){ + + + + } + + @Before + public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { + + + 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); + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { + String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { + String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); + batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test is going to die ...", e); + } + + } + + @Test + public void testListAllMovies() { try { ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target("http://localhost:8080/RestEasyTutorial/rest/movies/listmovies"); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); + ServicesInterface simple = target.proxy(ServicesInterface.class); + + final List movies = simple.listMovies(); + System.out.println(movies); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + @Test + public void testAddMovie() { + + try { + ResteasyClient client = new ResteasyClientBuilder().build(); + ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); ServicesInterface simple = target.proxy(ServicesInterface.class); - final List movies = simple.listMovies(); + final Response moviesResponse = simple.addMovie(batmanMovie); - /* - if (response.getStatus() != 200) { + if (moviesResponse.getStatus() != 201) { + System.out.println(moviesResponse.readEntity(String.class)); throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); + + moviesResponse.getStatus()); } - System.out.println("Server response : \n"); - System.out.println(response.readEntity(String.class)); + moviesResponse.close(); - response.close(); -*/ } catch (Exception e) { - e.printStackTrace(); - } } diff --git a/RestEasy Example/src/test/resources/server/movies/transformer.json b/RestEasy Example/src/test/resources/server/movies/transformer.json deleted file mode 100644 index 2154868265..0000000000 --- a/RestEasy Example/src/test/resources/server/movies/transformer.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "title": "Transformers", - "year": "2007", - "rated": "PG-13", - "released": "03 Jul 2007", - "runtime": "144 min", - "genre": "Action, Adventure, Sci-Fi", - "director": "Michael Bay", - "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", - "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", - "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", - "language": "English, Spanish", - "country": "USA", - "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", - "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", - "metascore": "61", - "imdbRating": "7.1", - "imdbVotes": "492,225", - "imdbID": "tt0418279", - "Type": "movie", - "response": "True" -} \ No newline at end of file From 6db36f902b1e7cf6f1c7857e5a14295e8881c732 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sun, 31 Jan 2016 11:05:11 +0100 Subject: [PATCH 132/142] Added testCase for all Services --- .../baeldung/client/ServicesInterface.java | 6 + .../com/baeldung/server/MovieCrudService.java | 15 ++- .../com/baeldung/server/RestEasyClient.java | 112 ------------------ 3 files changed, 16 insertions(+), 117 deletions(-) delete mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 749cabc757..8898b83483 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -23,6 +23,12 @@ public interface ServicesInterface { List listMovies(); + @GET + @Path("/listmovies") + @Produces({"application/json"}) + List listMovies(); + + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 60e0121966..18366e2faa 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -18,18 +18,21 @@ public class MovieCrudService { private Map inventory = new HashMap(); + @GET @Path("/getinfo") @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public Movie movieByImdbID(@QueryParam("imdbID") String imdbID){ - System.out.println("*** Calling getinfo ***"); + System.out.println("*** Calling getinfo for a given ImdbID***"); + + if(inventory.containsKey(imdbID)){ + return inventory.get(imdbID); + }else return null; - Movie movie=new Movie(); - movie.setImdbID(imdbID); - return movie; } + @POST @Path("/addmovie") @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) @@ -41,6 +44,7 @@ public class MovieCrudService { return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is Already in the database.").build(); } + inventory.put(movie.getImdbID(),movie); return Response.status(Response.Status.CREATED).build(); @@ -54,7 +58,7 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + if (null==inventory.get(movie.getImdbID())){ return Response.status(Response.Status.NOT_MODIFIED) .entity("Movie is not in the database.\nUnable to Update").build(); } @@ -79,6 +83,7 @@ public class MovieCrudService { return Response.status(Response.Status.OK).build(); } + @GET @Path("/listmovies") @Produces({"application/json"}) diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java deleted file mode 100644 index c77f494862..0000000000 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClient.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.baeldung.server; - -import com.baeldung.model.Movie; -import com.baeldung.client.ServicesInterface; -import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.naming.NamingException; -import javax.ws.rs.core.Link; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -public class RestEasyClient { - - - Movie transformerMovie=null; - Movie batmanMovie=null; - ObjectMapper jsonMapper=null; - - @BeforeClass - public static void loadMovieInventory(){ - - - - } - - @Before - public void setup() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NamingException { - - - 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); - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/transformer.json")) { - String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - try (InputStream inputStream = new RestEasyClient().getClass().getResourceAsStream("./movies/batman.json")) { - String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); - - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - } - - @Test - public void testListAllMovies() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - final List movies = simple.listMovies(); - System.out.println(movies); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - - - @Test - public void testAddMovie() { - - try { - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/RestEasyTutorial/rest")); - - ServicesInterface simple = target.proxy(ServicesInterface.class); - final Response moviesResponse = simple.addMovie(batmanMovie); - - if (moviesResponse.getStatus() != 201) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " - + moviesResponse.getStatus()); - } - - moviesResponse.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file From 33223becff3f88fd3bb8e5734f621c780c1ba454 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:29:30 +0100 Subject: [PATCH 133/142] Minor Bugfix --- .../main/java/com/baeldung/model/Movie.java | 22 +++++++++---------- .../com/baeldung/server/MovieCrudService.java | 12 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 052ba081c1..a2b2bd5250 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -13,7 +13,7 @@ import javax.xml.bind.annotation.XmlType; "country", "director", "genre", - "imdbID", + "imdbId", "imdbRating", "imdbVotes", "language", @@ -36,7 +36,7 @@ public class Movie { protected String country; protected String director; protected String genre; - protected String imdbID; + protected String imdbId; protected String imdbRating; protected String imdbVotes; protected String language; @@ -173,27 +173,27 @@ public class Movie { } /** - * Recupera il valore della propriet� imdbID. + * Recupera il valore della propriet� imdbId. * * @return * possible object is * {@link String } * */ - public String getImdbID() { - return imdbID; + public String getImdbId() { + return imdbId; } /** - * Imposta il valore della propriet� imdbID. + * Imposta il valore della propriet� imdbId. * * @param value * allowed object is * {@link String } * */ - public void setImdbID(String value) { - this.imdbID = value; + public void setImdbId(String value) { + this.imdbId = value; } /** @@ -540,7 +540,7 @@ public class Movie { ", country='" + country + '\'' + ", director='" + director + '\'' + ", genre='" + genre + '\'' + - ", imdbID='" + imdbID + '\'' + + ", imdbId='" + imdbId + '\'' + ", imdbRating='" + imdbRating + '\'' + ", imdbVotes='" + imdbVotes + '\'' + ", language='" + language + '\'' + @@ -564,14 +564,14 @@ public class Movie { 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; } @Override public int hashCode() { - int result = imdbID != null ? imdbID.hashCode() : 0; + int result = imdbId != null ? imdbId.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); return result; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 18366e2faa..29226aa0e0 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -22,7 +22,7 @@ public class MovieCrudService { @GET @Path("/getinfo") @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***"); @@ -40,12 +40,12 @@ public class MovieCrudService { System.out.println("*** Calling addMovie ***"); - if (null!=inventory.get(movie.getImdbID())){ + 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(); } @@ -58,11 +58,11 @@ public class MovieCrudService { System.out.println("*** Calling updateMovie ***"); - if (null==inventory.get(movie.getImdbID())){ + 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(); } @@ -70,7 +70,7 @@ public class MovieCrudService { @DELETE @Path("/deletemovie") - public Response deleteMovie(@QueryParam("imdbID") String imdbID){ + public Response deleteMovie(@QueryParam("imdbId") String imdbID){ System.out.println("*** Calling deleteMovie ***"); From 783dc6bdc2cb172dd3bacf01faba9531675c45ab Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:39:35 +0100 Subject: [PATCH 134/142] Minor Bugfix --- .../main/java/com/baeldung/model/Movie.java | 321 +----------------- 1 file changed, 1 insertion(+), 320 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index a2b2bd5250..805ba95209 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -52,482 +52,163 @@ public class Movie { protected String writer; protected String year; - /** - * Recupera il valore della propriet� actors. - * - * @return - * possible object is - * {@link String } - * - */ + public String getActors() { return actors; } - /** - * Imposta il valore della propriet� actors. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setActors(String value) { this.actors = value; } - /** - * Recupera il valore della propriet� awards. - * - * @return - * possible object is - * {@link String } - * - */ public String getAwards() { return awards; } - /** - * Imposta il valore della propriet� awards. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setAwards(String value) { this.awards = value; } - /** - * Recupera il valore della propriet� country. - * - * @return - * possible object is - * {@link String } - * - */ public String getCountry() { return country; } - /** - * Imposta il valore della propriet� country. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setCountry(String value) { this.country = value; } - /** - * Recupera il valore della propriet� director. - * - * @return - * possible object is - * {@link String } - * - */ public String getDirector() { return director; } - /** - * Imposta il valore della propriet� director. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setDirector(String value) { this.director = value; } - /** - * Recupera il valore della propriet� genre. - * - * @return - * possible object is - * {@link String } - * - */ public String getGenre() { return genre; } - /** - * Imposta il valore della propriet� genre. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setGenre(String value) { this.genre = value; } - /** - * Recupera il valore della propriet� imdbId. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbId() { return imdbId; } - /** - * Imposta il valore della propriet� imdbId. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbId(String value) { this.imdbId = value; } - /** - * Recupera il valore della propriet� imdbRating. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbRating() { return imdbRating; } - /** - * Imposta il valore della propriet� imdbRating. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbRating(String value) { this.imdbRating = value; } - /** - * Recupera il valore della propriet� imdbVotes. - * - * @return - * possible object is - * {@link String } - * - */ public String getImdbVotes() { return imdbVotes; } - /** - * Imposta il valore della propriet� imdbVotes. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setImdbVotes(String value) { this.imdbVotes = value; } - /** - * Recupera il valore della propriet� language. - * - * @return - * possible object is - * {@link String } - * - */ public String getLanguage() { return language; } - /** - * Imposta il valore della propriet� language. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setLanguage(String value) { this.language = value; } - /** - * Recupera il valore della propriet� metascore. - * - * @return - * possible object is - * {@link String } - * - */ public String getMetascore() { return metascore; } - /** - * Imposta il valore della propriet� metascore. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setMetascore(String value) { this.metascore = value; } - /** - * Recupera il valore della propriet� plot. - * - * @return - * possible object is - * {@link String } - * - */ public String getPlot() { return plot; } - /** - * Imposta il valore della propriet� plot. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setPlot(String value) { this.plot = value; } - /** - * Recupera il valore della propriet� poster. - * - * @return - * possible object is - * {@link String } - * - */ public String getPoster() { return poster; } - /** - * Imposta il valore della propriet� poster. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setPoster(String value) { this.poster = value; } - /** - * Recupera il valore della propriet� rated. - * - * @return - * possible object is - * {@link String } - * - */ public String getRated() { return rated; } - /** - * Imposta il valore della propriet� rated. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setRated(String value) { this.rated = value; } - /** - * Recupera il valore della propriet� released. - * - * @return - * possible object is - * {@link String } - * - */ public String getReleased() { return released; } - /** - * Imposta il valore della propriet� released. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setReleased(String value) { this.released = value; } - /** - * Recupera il valore della propriet� response. - * - * @return - * possible object is - * {@link String } - * - */ public String getResponse() { return response; } - /** - * Imposta il valore della propriet� response. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setResponse(String value) { this.response = value; } - /** - * Recupera il valore della propriet� runtime. - * - * @return - * possible object is - * {@link String } - * - */ public String getRuntime() { return runtime; } - /** - * Imposta il valore della propriet� runtime. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setRuntime(String value) { this.runtime = value; } - /** - * Recupera il valore della propriet� title. - * - * @return - * possible object is - * {@link String } - * - */ public String getTitle() { return title; } - /** - * Imposta il valore della propriet� title. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setTitle(String value) { this.title = value; } - /** - * Recupera il valore della propriet� type. - * - * @return - * possible object is - * {@link String } - * - */ public String getType() { return type; } - /** - * Imposta il valore della propriet� type. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setType(String value) { this.type = value; } - /** - * Recupera il valore della propriet� writer. - * - * @return - * possible object is - * {@link String } - * - */ public String getWriter() { return writer; } - /** - * Imposta il valore della propriet� writer. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setWriter(String value) { this.writer = value; } - /** - * Recupera il valore della propriet� year. - * - * @return - * possible object is - * {@link String } - * - */ public String getYear() { return year; } - /** - * Imposta il valore della propriet� year. - * - * @param value - * allowed object is - * {@link String } - * - */ public void setYear(String value) { this.year = value; } From 71793635d32d50427bc4165b29b39aaabec3d743 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 7 Feb 2016 20:55:46 +0100 Subject: [PATCH 135/142] CleanUp Code --- RestEasy Example/pom.xml | 3 +- .../baeldung/client/ServicesInterface.java | 1 - .../main/java/com/baeldung/model/Movie.java | 2 -- .../com/baeldung/server/MovieCrudService.java | 17 ++++------- .../com/baeldung/server/RestEasyServices.java | 8 ----- .../src/main/resources/schema1.xsd | 29 ------------------- .../src/main/webapp/WEB-INF/web.xml | 3 -- .../java/baeldung/client/RestEasyClient.java | 7 ----- .../baeldung/server/RestEasyClientTest.java | 1 - 9 files changed, 7 insertions(+), 64 deletions(-) delete mode 100644 RestEasy Example/src/main/resources/schema1.xsd delete mode 100644 RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 6935238d91..9c890da2b7 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -36,7 +36,7 @@ - + org.jboss.resteasy jaxrs-api @@ -101,5 +101,4 @@ - \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 8898b83483..22669717a8 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -1,7 +1,6 @@ package com.baeldung.client; import com.baeldung.model.Movie; - import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 805ba95209..56ba766ff4 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -1,11 +1,9 @@ - package com.baeldung.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; - @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "movie", propOrder = { "actors", diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 29226aa0e0..bbb3b1e953 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -1,7 +1,6 @@ package com.baeldung.server; import com.baeldung.model.Movie; - import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -11,23 +10,21 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - @Path("/movies") public class MovieCrudService { - private Map inventory = new HashMap(); @GET @Path("/getinfo") @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***"); - if(inventory.containsKey(imdbID)){ - return inventory.get(imdbID); + if(inventory.containsKey(imdbId)){ + return inventory.get(imdbId); }else return null; } @@ -70,16 +67,16 @@ public class MovieCrudService { @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)){ + 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); + inventory.remove(imdbId); return Response.status(Response.Status.OK).build(); } @@ -93,6 +90,4 @@ public class MovieCrudService { } - - } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java index 8c57d2c9b4..7726e49f38 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/RestEasyServices.java @@ -1,19 +1,11 @@ package com.baeldung.server; - import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; -import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Set; -/** - * Created by Admin on 29/01/2016. - */ - - - @ApplicationPath("/rest") public class RestEasyServices extends Application { diff --git a/RestEasy Example/src/main/resources/schema1.xsd b/RestEasy Example/src/main/resources/schema1.xsd deleted file mode 100644 index 0d74b7c366..0000000000 --- a/RestEasy Example/src/main/resources/schema1.xsd +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index f70fdf7975..1e7f64004d 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -5,12 +5,9 @@ RestEasy Example - resteasy.servlet.mapping.prefix /rest - - \ No newline at end of file diff --git a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java b/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java deleted file mode 100644 index b474b3d4f8..0000000000 --- a/RestEasy Example/src/test/java/baeldung/client/RestEasyClient.java +++ /dev/null @@ -1,7 +0,0 @@ -package baeldung.client; - -/** - * Created by Admin on 29/01/2016. - */ -public class RestEasyClient { -} diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index b6a2e2a0c1..faa39e0199 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -10,7 +10,6 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.junit.Before; import org.junit.Test; - import javax.naming.NamingException; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; From 04d9bbb7682999c0d90054150aac69cbfa442781 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Mon, 8 Feb 2016 14:00:11 +0100 Subject: [PATCH 136/142] CleanUp and reformatting Code; dependency fix in pom.xml --- RestEasy Example/pom.xml | 147 +++++++----------- .../baeldung/client/ServicesInterface.java | 21 +-- .../main/java/com/baeldung/model/Movie.java | 56 ++----- .../com/baeldung/server/MovieCrudService.java | 49 +++--- .../WEB-INF/jboss-deployment-structure.xml | 22 +-- .../src/main/webapp/WEB-INF/web.xml | 14 +- .../baeldung/server/RestEasyClientTest.java | 23 ++- .../com/baeldung/server/movies/batman.json | 2 +- .../baeldung/server/movies/transformer.json | 2 +- 9 files changed, 125 insertions(+), 211 deletions(-) diff --git a/RestEasy Example/pom.xml b/RestEasy Example/pom.xml index 9c890da2b7..ec9e87b0d1 100644 --- a/RestEasy Example/pom.xml +++ b/RestEasy Example/pom.xml @@ -1,104 +1,77 @@ - - 4.0.0 + + 4.0.0 - com.baeldung - resteasy-tutorial - 1.0 - war + com.baeldung + resteasy-tutorial + 1.0 + war - - - jboss - http://repository.jboss.org/nexus/content/groups/public/ - - + + 3.0.14.Final + - - 3.0.14.Final - runtime - + + RestEasyTutorial + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + - - RestEasyTutorial - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - + - + - - org.jboss.resteasy - jaxrs-api - 3.0.12.Final - ${resteasy.scope} - - - - org.jboss.resteasy - resteasy-servlet-initializer - ${resteasy.version} - ${resteasy.scope} - - - jboss-jaxrs-api_2.0_spec - org.jboss.spec.javax.ws.rs - - - - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - ${resteasy.scope} - + + org.jboss.resteasy + resteasy-servlet-initializer + ${resteasy.version} + - - javax.ws.rs - javax.ws.rs-api - 2.0.1 - + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + - - org.jboss.resteasy - resteasy-jackson-provider - ${resteasy.version} - ${resteasy.scope} - + - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - ${resteasy.scope} - + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + - + + org.jboss.resteasy + resteasy-jackson-provider + ${resteasy.version} + - - junit - junit - 4.4 - + - - commons-io - commons-io - 2.4 - + + junit + junit + 4.4 + + + + commons-io + commons-io + 2.4 + + + - \ No newline at end of file diff --git a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java index 22669717a8..3d03c16faf 100644 --- a/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java +++ b/RestEasy Example/src/main/java/com/baeldung/client/ServicesInterface.java @@ -9,41 +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 listMovies(); - - @GET - @Path("/listmovies") - @Produces({"application/json"}) - List 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); - - } diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 56ba766ff4..a959682a75 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -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; } diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index bbb3b1e953..6a0699874a 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -13,78 +13,71 @@ import java.util.stream.Collectors; @Path("/movies") public class MovieCrudService { - private Map inventory = new HashMap(); - + private Map inventory = new HashMap(); @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 listMovies(){ + @Produces({ "application/json" }) + public List listMovies() { return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 84d75934a7..7879603d19 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -1,16 +1,16 @@ - - - - + + + + - - - - - + + + + + - - + + \ No newline at end of file diff --git a/RestEasy Example/src/main/webapp/WEB-INF/web.xml b/RestEasy Example/src/main/webapp/WEB-INF/web.xml index 1e7f64004d..d5f00293f4 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/web.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/web.xml @@ -1,13 +1,13 @@ + 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"> - RestEasy Example + RestEasy Example - - resteasy.servlet.mapping.prefix - /rest - + + resteasy.servlet.mapping.prefix + /rest + \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index faa39e0199..3760ae2415 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -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()); } } \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json index 28061d5bf9..173901c948 100644 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json @@ -16,7 +16,7 @@ "metascore": "66", "imdbRating": "7.6", "imdbVotes": "256,000", - "imdbID": "tt0096895", + "imdbId": "tt0096895", "type": "movie", "response": "True" } \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json index a3b033a8ba..a4fd061a82 100644 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json @@ -16,7 +16,7 @@ "metascore": "61", "imdbRating": "7.1", "imdbVotes": "492,225", - "imdbID": "tt0418279", + "imdbId": "tt0418279", "type": "movie", "response": "True" } \ No newline at end of file From 81f498407142bcc91071110ef20d0ee9a5b5da98 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Mon, 8 Feb 2016 16:08:15 +0100 Subject: [PATCH 137/142] CleanUp and reformatting Code. --- .../src/main/java/com/baeldung/server/MovieCrudService.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java index 6a0699874a..b7f3215f3f 100644 --- a/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java +++ b/RestEasy Example/src/main/java/com/baeldung/server/MovieCrudService.java @@ -26,7 +26,6 @@ public class MovieCrudService { return inventory.get(imdbId); } else return null; - } @POST @@ -41,7 +40,6 @@ public class MovieCrudService { } inventory.put(movie.getImdbId(), movie); - return Response.status(Response.Status.CREATED).build(); } @@ -55,9 +53,9 @@ public class MovieCrudService { 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); return Response.status(Response.Status.OK).build(); - } @DELETE @@ -80,7 +78,6 @@ public class MovieCrudService { public List listMovies() { return inventory.values().stream().collect(Collectors.toCollection(ArrayList::new)); - } } From 1c8e8a2e0c5683bcc0b992e631807b016d1d45a6 Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sat, 13 Feb 2016 23:48:11 +0100 Subject: [PATCH 138/142] Formatting and many fields removed from Movie class --- .../main/java/com/baeldung/model/Movie.java | 188 ++---------------- .../WEB-INF/jboss-deployment-structure.xml | 3 - .../baeldung/server/RestEasyClientTest.java | 2 +- .../com/baeldung/server/movies/batman.json | 20 +- .../baeldung/server/movies/transformer.json | 20 +- 5 files changed, 20 insertions(+), 213 deletions(-) diff --git a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java index 5aade4591a..408f2144fb 100644 --- a/RestEasy Example/src/main/java/com/baeldung/model/Movie.java +++ b/RestEasy Example/src/main/java/com/baeldung/model/Movie.java @@ -5,195 +5,33 @@ 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 = { "imdbId", "title" }) public class Movie { - protected String actors; - protected String awards; - protected String country; - protected String director; - protected String genre; protected String imdbId; - protected String imdbRating; - protected String imdbVotes; - protected String language; - protected String metascore; - protected String plot; - protected String poster; - protected String rated; - protected String released; - protected String response; - protected String runtime; protected String title; - protected String type; - protected String writer; - protected String year; - public String getActors() { - return actors; + public Movie(String imdbId, String title) { + this.imdbId = imdbId; + this.title = title; } - public void setActors(String value) { - this.actors = value; - } - - public String getAwards() { - return awards; - } - - public void setAwards(String value) { - this.awards = value; - } - - public String getCountry() { - return country; - } - - public void setCountry(String value) { - this.country = value; - } - - public String getDirector() { - return director; - } - - public void setDirector(String value) { - this.director = value; - } - - public String getGenre() { - return genre; - } - - public void setGenre(String value) { - this.genre = value; - } + public Movie() {} public String getImdbId() { return imdbId; } - public void setImdbId(String value) { - this.imdbId = value; - } - - public String getImdbRating() { - return imdbRating; - } - - public void setImdbRating(String value) { - this.imdbRating = value; - } - - public String getImdbVotes() { - return imdbVotes; - } - - public void setImdbVotes(String value) { - this.imdbVotes = value; - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String value) { - this.language = value; - } - - public String getMetascore() { - return metascore; - } - - public void setMetascore(String value) { - this.metascore = value; - } - - public String getPlot() { - return plot; - } - - public void setPlot(String value) { - this.plot = value; - } - - public String getPoster() { - return poster; - } - - public void setPoster(String value) { - this.poster = value; - } - - public String getRated() { - return rated; - } - - public void setRated(String value) { - this.rated = value; - } - - public String getReleased() { - return released; - } - - public void setReleased(String value) { - this.released = value; - } - - public String getResponse() { - return response; - } - - public void setResponse(String value) { - this.response = value; - } - - public String getRuntime() { - return runtime; - } - - public void setRuntime(String value) { - this.runtime = value; + public void setImdbId(String imdbId) { + this.imdbId = imdbId; } public String getTitle() { return title; } - public void setTitle(String value) { - this.title = value; - } - - public String getType() { - return type; - } - - public void setType(String value) { - this.type = value; - } - - public String getWriter() { - return writer; - } - - public void setWriter(String value) { - this.writer = value; - } - - public String getYear() { - return year; - } - - public void setYear(String value) { - this.year = value; - } - - @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 + '\'' + '}'; + public void setTitle(String title) { + this.title = title; } @Override @@ -217,4 +55,12 @@ public class Movie { result = 31 * result + (title != null ? title.hashCode() : 0); return result; } + + @Override + public String toString() { + return "Movie{" + + "imdbId='" + imdbId + '\'' + + ", title='" + title + '\'' + + '}'; + } } diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 7879603d19..e5b893e56a 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -3,14 +3,11 @@ - - - \ No newline at end of file diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java index 3760ae2415..2a13465ebc 100644 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java @@ -130,7 +130,7 @@ public class RestEasyClientTest { Response moviesResponse = simple.addMovie(batmanMovie); moviesResponse.close(); - batmanMovie.setImdbVotes("300,000"); + batmanMovie.setTitle("Batman Begins"); moviesResponse = simple.updateMovie(batmanMovie); if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json index 173901c948..82aaaa8f40 100644 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json @@ -1,22 +1,4 @@ { "title": "Batman", - "year": "1989", - "rated": "PG-13", - "released": "23 Jun 1989", - "runtime": "126 min", - "genre": "Action, Adventure", - "director": "Tim Burton", - "writer": "Bob Kane (Batman characters), Sam Hamm (story), Sam Hamm (screenplay), Warren Skaaren (screenplay)", - "actors": "Michael Keaton, Jack Nicholson, Kim Basinger, Robert Wuhl", - "plot": "The Dark Knight of Gotham City begins his war on crime with his first major enemy being the clownishly homicidal Joker.", - "language": "English, French", - "country": "USA, UK", - "awards": "Won 1 Oscar. Another 9 wins & 22 nominations.", - "poster": "http://ia.media-imdb.com/images/M/MV5BMTYwNjAyODIyMF5BMl5BanBnXkFtZTYwNDMwMDk2._V1_SX300.jpg", - "metascore": "66", - "imdbRating": "7.6", - "imdbVotes": "256,000", - "imdbId": "tt0096895", - "type": "movie", - "response": "True" + "imdbId": "tt0096895" } \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json index a4fd061a82..634cefc73c 100644 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json +++ b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json @@ -1,22 +1,4 @@ { "title": "Transformers", - "year": "2007", - "rated": "PG-13", - "released": "03 Jul 2007", - "runtime": "144 min", - "genre": "Action, Adventure, Sci-Fi", - "director": "Michael Bay", - "writer": "Roberto Orci (screenplay), Alex Kurtzman (screenplay), John Rogers (story), Roberto Orci (story), Alex Kurtzman (story)", - "actors": "Shia LaBeouf, Megan Fox, Josh Duhamel, Tyrese Gibson", - "plot": "A long time ago, far away on the planet of Cybertron, a war is being waged between the noble Autobots (led by the wise Optimus Prime) and the devious Decepticons (commanded by the dreaded Megatron) for control over the Allspark, a mystical talisman that would grant unlimited power to whoever possesses it. The Autobots managed to smuggle the Allspark off the planet, but Megatron blasts off in search of it. He eventually tracks it to the planet of Earth (circa 1850), but his reckless desire for power sends him right into the Arctic Ocean, and the sheer cold forces him into a paralyzed state. His body is later found by Captain Archibald Witwicky, but before going into a comatose state Megatron uses the last of his energy to engrave into the Captain's glasses a map showing the location of the Allspark, and to send a transmission to Cybertron. Megatron is then carried away aboard the Captain's ship. A century later, Captain Witwicky's grandson Sam Witwicky (nicknamed Spike by his friends) buys his first car. To his shock, he discovers it to be Bumblebee, an Autobot in disguise who is to protect Spike, who possesses the Captain's glasses and the map engraved on them. But Bumblebee is not the only Transformer to have arrived on Earth - in the desert of Qatar, the Decepticons Blackout and Scorponok attack a U.S. military base, causing the Pentagon to send their special Sector Seven agents to capture all \"specimens of this alien race.\" Spike and his girlfriend Mikaela find themselves in the midst of a grand battle between the Autobots and the Decepticons, stretching from Hoover Dam all the way to Los Angeles. Meanwhile, deep inside Hoover Dam, the cryogenically stored body of Megatron awakens.", - "language": "English, Spanish", - "country": "USA", - "awards": "Nominated for 3 Oscars. Another 18 wins & 40 nominations.", - "poster": "http://ia.media-imdb.com/images/M/MV5BMTQwNjU5MzUzNl5BMl5BanBnXkFtZTYwMzc1MTI3._V1_SX300.jpg", - "metascore": "61", - "imdbRating": "7.1", - "imdbVotes": "492,225", - "imdbId": "tt0418279", - "type": "movie", - "response": "True" + "imdbId": "tt0418279" } \ No newline at end of file From 957b0958e3190caf2790d8cac15715be20a1e57a Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 14 Feb 2016 00:35:19 +0100 Subject: [PATCH 139/142] Reformatting Code. --- .../main/webapp/WEB-INF/jboss-deployment-structure.xml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index e5b893e56a..45dfd9f075 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -1,13 +1,17 @@ + - + + - - + + + + \ No newline at end of file From fa39351b6e31f8ed1483e75df5448e3a333cd7b1 Mon Sep 17 00:00:00 2001 From: "giuseppe.bueti" Date: Sun, 14 Feb 2016 00:40:02 +0100 Subject: [PATCH 140/142] Reformatting Code. --- .../WEB-INF/jboss-deployment-structure.xml | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 45dfd9f075..cb258374a1 100644 --- a/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/RestEasy Example/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -1,17 +1,13 @@ + - - - - - - + + + + - - - - - - - + + + + - \ No newline at end of file + From 72214652846664333aaa334b1f05d88e13a0c070 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 14 Feb 2016 11:15:29 +0200 Subject: [PATCH 141/142] cleanup work --- spring-security-login-and-registration/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-security-login-and-registration/pom.xml b/spring-security-login-and-registration/pom.xml index f5b62be553..bcbe9371e2 100644 --- a/spring-security-login-and-registration/pom.xml +++ b/spring-security-login-and-registration/pom.xml @@ -269,7 +269,8 @@ ${maven-surefire-plugin.version} - + **/*IntegrationTest.java + **/*LiveTest.java From 33e5f14e86ee2913d11d8df5603dd9d20d70d34b Mon Sep 17 00:00:00 2001 From: Giuseppe Bueti Date: Sun, 14 Feb 2016 12:34:32 +0100 Subject: [PATCH 142/142] Example folders cleaned --- .../baeldung/server/RestEasyClientTest.java | 144 ------------------ .../com/baeldung/server/movies/batman.json | 4 - .../baeldung/server/movies/transformer.json | 4 - 3 files changed, 152 deletions(-) delete mode 100644 RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java delete mode 100644 RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json delete mode 100644 RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json diff --git a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java b/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java deleted file mode 100644 index 2a13465ebc..0000000000 --- a/RestEasy Example/src/test/java/com/baeldung/server/RestEasyClientTest.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.baeldung.server; - -import com.baeldung.client.ServicesInterface; -import com.baeldung.model.Movie; -import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.jboss.resteasy.client.jaxrs.ResteasyClient; -import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; -import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; -import org.junit.Before; -import org.junit.Test; -import javax.naming.NamingException; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Locale; - -public class RestEasyClientTest { - - 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.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); - - try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/transformer.json")) { - String transformerMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - transformerMovie = jsonMapper.readValue(transformerMovieAsString, Movie.class); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Test is going to die ...", e); - } - - try (InputStream inputStream = new RestEasyClientTest().getClass().getResourceAsStream("./movies/batman.json")) { - String batmanMovieAsString = String.format(IOUtils.toString(inputStream, StandardCharsets.UTF_8)); - batmanMovie = jsonMapper.readValue(batmanMovieAsString, Movie.class); - - } catch (Exception e) { - throw new RuntimeException("Test is going to die ...", e); - } - } - - @Test - public void testListAllMovies() { - - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - - List movies = simple.listMovies(); - System.out.println(movies); - } - - @Test - public void testMovieByImdbId() { - - String transformerImdbId = "tt0418279"; - - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - Response moviesResponse = simple.addMovie(transformerMovie); - moviesResponse.close(); - - Movie movies = simple.movieByImdbId(transformerImdbId); - System.out.println(movies); - } - - @Test - public void testAddMovie() { - - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.addMovie(transformerMovie); - - if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) { - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - System.out.println("Response Code: " + Response.Status.OK.getStatusCode()); - } - - @Test - public void testDeleteMovi1e() { - - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - moviesResponse = simple.deleteMovie(batmanMovie.getImdbId()); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - System.out.println(moviesResponse.readEntity(String.class)); - throw new RuntimeException("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - System.out.println("Response Code: " + Response.Status.OK.getStatusCode()); - } - - @Test - public void testUpdateMovie() { - - ResteasyClient client = new ResteasyClientBuilder().build(); - ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://127.0.0.1:8080/RestEasyTutorial/rest")); - ServicesInterface simple = target.proxy(ServicesInterface.class); - - Response moviesResponse = simple.addMovie(batmanMovie); - moviesResponse.close(); - batmanMovie.setTitle("Batman Begins"); - moviesResponse = simple.updateMovie(batmanMovie); - - if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) { - System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus()); - } - - moviesResponse.close(); - System.out.println("Response Code: " + Response.Status.OK.getStatusCode()); - } - -} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json deleted file mode 100644 index 82aaaa8f40..0000000000 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/batman.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Batman", - "imdbId": "tt0096895" -} \ No newline at end of file diff --git a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json b/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json deleted file mode 100644 index 634cefc73c..0000000000 --- a/RestEasy Example/src/test/resources/com/baeldung/server/movies/transformer.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "Transformers", - "imdbId": "tt0418279" -} \ No newline at end of file