30 lines
1.0 KiB
Java
30 lines
1.0 KiB
Java
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);
|
|
}
|
|
}
|