32 lines
1.0 KiB
Java
Raw Normal View History

2019-12-02 12:17:12 +01:00
package at.technikumwien.movies;
import at.technikumwien.movies.generated.Movie;
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 MovieResourceClient {
public static void main(String[] args) {
var target = ClientBuilder.newClient().target("http://localhost:8080/movieservice/resources/movie");
//var response = target.request().post(Entity.json(new Movie()));
//System.out.println(response.getLocation());
List<Movie> allMovies = target
.request(MediaType.APPLICATION_XML)
.get(new GenericType<List<Movie>>() {}); // Solution for List<Movie>.class
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(movie);
}
}