List<Object> providers = new ArrayList<Object>(); providers.add( new JacksonJaxbJsonProvider() ); WebClient client=WebClient.create("http://localhost:6969/CXF3/rest",providers); client = client.accept("application/json").type("application/json").path("/service/getAll"); Collection<? extends Person> order=client.getCollection(Person.class); for(Person p:order){ System.out.println(p.getEname()+" "+p.getEmpid()+" "+p.getEsal()); }
@Override public List<GroupPrincipal> loadRoles(final List<UserPrincipal> principals) { final WebClient client = createClient(); final List<GroupPrincipal> result = new ArrayList<GroupPrincipal>(); for (final String s : client.getCollection(String.class)) { result.add(new GroupPrincipal(s)); } return result; }
private void getAllMembers(WebClient webClient) { System.out.println("Retrieving list of all members:"); List<Person> persons = new ArrayList<Person>(webClient.getCollection(Person.class)); for (Person person : persons) { System.out .println("ID " + person.getId() + ": " + person.getName() + ", age: " + person.getAge()); } }
@Override public Object execute() throws Exception { List providers = new ArrayList(); providers.add(new JacksonJsonProvider()); WebClient webClient = WebClient.create(restLocation, providers); List<Booking> bookings = (List<Booking>) webClient.accept(MediaType.APPLICATION_JSON).getCollection(Booking.class); for (Booking booking : bookings) { System.out.println(booking.getId() + " " + booking.getCustomer() + " " + booking.getFlight()); } return null; }
@Test public void testGetCollectionOfBooks() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/store1/bookstore/collections"; WebClient wc = WebClient.create(endpointAddress, Collections.singletonList(new JacksonJsonProvider())); wc.accept("application/json"); Collection<? extends Book> collection = wc.getCollection(Book.class); assertEquals(1, collection.size()); Book book = collection.iterator().next(); assertEquals(123L, book.getId()); }
@Test public void testGetCollectionOfBooks() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections"; WebClient wc = WebClient.create(endpointAddress); wc.accept("application/xml"); Collection<? extends Book> collection = wc.getCollection(Book.class); assertEquals(1, collection.size()); Book book = collection.iterator().next(); assertEquals(123L, book.getId()); }
@Test public void testGetCollectionOfSuperBooks() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/store2/books/superbooks"; WebClient wc = WebClient.create(endpointAddress, Collections.singletonList(new JacksonJsonProvider())); wc.accept("application/json"); Collection<? extends Book> collection = wc.getCollection(Book.class); assertEquals(1, collection.size()); Book book = collection.iterator().next(); assertEquals(999L, book.getId()); }
Collection<? extends PersonInfo> personInfos = wc.getCollection(PersonInfo.class); for (PersonInfo pi : personInfos) { System.out.println("ID : " + pi.getId());