Added import from json for studio and actor
This commit is contained in:
parent
9bbf2bccf8
commit
15ce324c04
@ -97,5 +97,6 @@
|
||||
<orderEntry type="library" name="Maven: com.github.fge:msg-simple:1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.fge:btf:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:25.0-jre" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.1" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -47,6 +47,12 @@
|
||||
<artifactId>resteasy-jackson2-provider</artifactId>
|
||||
<version>4.3.1.Final</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -0,0 +1,42 @@
|
||||
package at.technikumwien.movies;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.GenericType;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class StudioResourceClient {
|
||||
private static final Logger LOGGER = Logger.getLogger(StudioResourceClient.class.getName());
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String filename = "import_studio.json";
|
||||
var target = ClientBuilder.newClient()
|
||||
.register(new RequestFilter("moviesadmin", "topsecret"))
|
||||
.target("http://localhost:8080/movieservice/resources/studio");
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
// Read JSON file and convert to java object
|
||||
InputStream fileInputStream = new FileInputStream(filename);
|
||||
Studio studio = mapper.readValue(fileInputStream, Studio.class);
|
||||
fileInputStream.close();
|
||||
LOGGER.info("Importing studio from json: " + studio);
|
||||
|
||||
// Import studio into the database
|
||||
target.request().post(Entity.entity(studio, MediaType.APPLICATION_JSON), Studio.class);
|
||||
|
||||
// Show all studios
|
||||
var studios = target
|
||||
.request(MediaType.APPLICATION_JSON)
|
||||
.get(new GenericType<List<Studio>>() {});
|
||||
|
||||
System.out.println("All studios:");
|
||||
studios.forEach(System.out::println);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package at.technikumwien.movies;
|
||||
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.core.GenericType;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.List;
|
||||
|
||||
public class MovieResourceClient {
|
||||
public static void main(String[] args) {
|
||||
var target = ClientBuilder.newClient()
|
||||
.register(new RequestFilter("moviesuser", "topsecret"))
|
||||
.target("http://localhost:8080/movieservice/resources/movie");
|
||||
|
||||
List<Movie> allMovies = target
|
||||
.request(MediaType.APPLICATION_XML)
|
||||
.get(new GenericType<List<Movie>>() {}); // Solution for List<Movie>.class
|
||||
|
||||
System.out.println("All movies by XML:");
|
||||
allMovies.forEach(System.out::println);
|
||||
|
||||
var movie = target.path("/{id}")
|
||||
.resolveTemplate("id", 1) // Useful for pre-defining templates
|
||||
.request(MediaType.APPLICATION_JSON)
|
||||
.get(Movie.class);
|
||||
|
||||
System.out.println("First movie by ID by JSON:");
|
||||
System.out.println(movie);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package at.technikumwien.movies;
|
||||
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.GenericType;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.List;
|
||||
|
||||
public class StudioResourceClient {
|
||||
public static void main(String[] args) {
|
||||
var target = ClientBuilder.newClient()
|
||||
.register(new RequestFilter("moviesadmin", "topsecret"))
|
||||
.target("http://localhost:8080/movieservice/resources/studio");
|
||||
|
||||
target.request().post(Entity.entity(new Studio(":)", "AT", "664"),
|
||||
MediaType.APPLICATION_JSON), Studio.class);
|
||||
|
||||
var studios = target
|
||||
.request(MediaType.APPLICATION_JSON)
|
||||
.get(new GenericType<List<Studio>>() {});
|
||||
|
||||
System.out.println("All studios:");
|
||||
studios.forEach(System.out::println);
|
||||
}
|
||||
}
|
6
import_actor.json
Normal file
6
import_actor.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"firstname": "Test3",
|
||||
"lastname": "Actor",
|
||||
"sex": "MALE",
|
||||
"birthdate": "01.01.1888"
|
||||
}
|
5
import_studio.json
Normal file
5
import_studio.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "studio2",
|
||||
"countrycode": "AT",
|
||||
"postcode": "123PO"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user