use of javax.ws.rs.core.GenericType in project linuxtools by eclipse.
the class AbstractRegistry method getImages.
@Override
public List<IDockerImageSearchResult> getImages(String term) throws DockerException {
final Client client = ClientBuilder.newClient(DEFAULT_CONFIG);
List<IDockerImageSearchResult> result = new ArrayList<>();
WebTarget queryImagesResource;
if (isVersion2()) {
final GenericType<ImageSearchResultV2> IMAGE_SEARCH_RESULT_LIST = new GenericType<ImageSearchResultV2>() {
};
ImageSearchResultV2 cisr = null;
queryImagesResource = client.target(getHTTPServerAddress()).path("v2").path(// $NON-NLS-1$ //$NON-NLS-2$
"_catalog");
try {
cisr = queryImagesResource.request(APPLICATION_JSON_TYPE).async().method(GET, IMAGE_SEARCH_RESULT_LIST).get();
} catch (InterruptedException | ExecutionException e) {
throw new DockerException(e);
}
List<ImageSearchResult> tmp = cisr.getRepositories().stream().filter(e -> e.name().contains(term)).collect(Collectors.toList());
result.addAll(tmp.stream().map(r -> new DockerImageSearchResult(r.description(), r.official(), r.automated(), r.name(), r.starCount())).collect(Collectors.toList()));
} else {
ImageSearchResultV1 pisr = null;
final GenericType<ImageSearchResultV1> IMAGE_SEARCH_RESULT_LIST = new GenericType<ImageSearchResultV1>() {
};
int page = 0;
try {
while (pisr == null || pisr.getPage() < pisr.getTotalPages()) {
page++;
queryImagesResource = client.target(getHTTPServerAddress()).path("v1").path(// $NON-NLS-1$ //$NON-NLS-2$
"search").queryParam("q", // $NON-NLS-1$
term).queryParam("page", // $NON-NLS-1$
page);
pisr = queryImagesResource.request(APPLICATION_JSON_TYPE).async().method(GET, IMAGE_SEARCH_RESULT_LIST).get();
List<ImageSearchResult> tmp = pisr.getResult();
result.addAll(tmp.stream().map(r -> new DockerImageSearchResult(r.description(), r.official(), r.automated(), r.name(), r.starCount())).collect(Collectors.toList()));
}
} catch (InterruptedException | ExecutionException e) {
throw new DockerException(e);
}
}
return result;
}
use of javax.ws.rs.core.GenericType in project cxf by apache.
the class JAXRS20ClientServerBookTest method testPostGetCollectionGenericEntityAndType3.
@Test
public void testPostGetCollectionGenericEntityAndType3() throws Exception {
String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections";
WebClient wc = WebClient.create(endpointAddress);
wc.accept("application/xml").type("application/xml");
GenericEntity<List<Book>> collectionEntity = createGenericEntity();
GenericType<List<Book>> genericResponseType = new GenericType<List<Book>>() {
};
Future<Response> future = wc.async().post(Entity.entity(collectionEntity, "application/xml"));
Response r = future.get();
List<Book> books2 = r.readEntity(genericResponseType);
assertNotNull(books2);
List<Book> books = collectionEntity.getEntity();
assertNotSame(books, books2);
assertEquals(2, books2.size());
Book b11 = books.get(0);
assertEquals(123L, b11.getId());
assertEquals("CXF in Action", b11.getName());
Book b22 = books.get(1);
assertEquals(124L, b22.getId());
assertEquals("CXF Rocks", b22.getName());
assertEquals(200, wc.getResponse().getStatus());
}
use of javax.ws.rs.core.GenericType in project cxf by apache.
the class JAXRS20ClientServerBookTest method testPostGetCollectionGenericEntityAndType2.
@Test
public void testPostGetCollectionGenericEntityAndType2() throws Exception {
String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections";
WebClient wc = WebClient.create(endpointAddress);
wc.accept("application/xml").type("application/xml");
GenericEntity<List<Book>> collectionEntity = createGenericEntity();
GenericType<List<Book>> genericResponseType = new GenericType<List<Book>>() {
};
Future<List<Book>> future = wc.async().post(Entity.entity(collectionEntity, "application/xml"), genericResponseType);
List<Book> books2 = future.get();
assertNotNull(books2);
List<Book> books = collectionEntity.getEntity();
assertNotSame(books, books2);
assertEquals(2, books2.size());
Book b11 = books.get(0);
assertEquals(123L, b11.getId());
assertEquals("CXF in Action", b11.getName());
Book b22 = books.get(1);
assertEquals(124L, b22.getId());
assertEquals("CXF Rocks", b22.getName());
assertEquals(200, wc.getResponse().getStatus());
}
use of javax.ws.rs.core.GenericType in project cxf by apache.
the class JAXRSClientServerBookTest method testPostGetCollectionGenericEntityAndType.
@Test
public void testPostGetCollectionGenericEntityAndType() throws Exception {
String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections";
WebClient wc = WebClient.create(endpointAddress);
wc.accept("application/xml").type("application/xml");
Book b1 = new Book("CXF in Action", 123L);
Book b2 = new Book("CXF Rocks", 124L);
List<Book> books = new ArrayList<>();
books.add(b1);
books.add(b2);
GenericEntity<List<Book>> genericCollectionEntity = new GenericEntity<List<Book>>(books) {
};
GenericType<List<Book>> genericResponseType = new GenericType<List<Book>>() {
};
List<Book> books2 = wc.post(genericCollectionEntity, genericResponseType);
assertNotNull(books2);
assertNotSame(books, books2);
assertEquals(2, books2.size());
Book b11 = books.get(0);
assertEquals(123L, b11.getId());
assertEquals("CXF in Action", b11.getName());
Book b22 = books.get(1);
assertEquals(124L, b22.getId());
assertEquals("CXF Rocks", b22.getName());
assertEquals(200, wc.getResponse().getStatus());
}
use of javax.ws.rs.core.GenericType in project cxf by apache.
the class JAXRSClientServerResourceJacksonSpringProviderTest method testGetGenericSuperBookInt1.
@Test
public void testGetGenericSuperBookInt1() throws Exception {
String endpointAddress = "http://localhost:" + PORT + "/webapp/genericstoreInt1/int/books/superbook";
WebClient wc = WebClient.create(endpointAddress, Collections.singletonList(new JacksonJsonProvider()));
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000000L);
GenericType<List<SuperBook>> genericResponseType = new GenericType<List<SuperBook>>() {
};
List<SuperBook> books = wc.get(genericResponseType);
assertEquals(1, books.size());
assertEquals(111L, books.get(0).getId());
}
Aggregations