Search in sources :

Example 31 with GenericType

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;
}
Also used : GET(javax.ws.rs.HttpMethod.GET) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) TimeoutException(java.util.concurrent.TimeoutException) ArrayList(java.util.ArrayList) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) ClientBuilder(javax.ws.rs.client.ClientBuilder) ImageSearchResultV1(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV1) Map(java.util.Map) Status(javax.ws.rs.core.Response.Status) ObjectMapperProvider(com.spotify.docker.client.ObjectMapperProvider) CancellationException(java.util.concurrent.CancellationException) NLS(org.eclipse.osgi.util.NLS) JacksonFeature(org.glassfish.jersey.jackson.JacksonFeature) Collectors(java.util.stream.Collectors) ImageSearchResultV2(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV2) BearerTokenResponse(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils.BearerTokenResponse) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) ImageSearchResult(com.spotify.docker.client.messages.ImageSearchResult) Response(javax.ws.rs.core.Response) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) RepositoryTagV2(org.eclipse.linuxtools.internal.docker.core.RepositoryTagV2) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) OAuth2Utils(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils) ImageSearchResultV2(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV2) GenericType(javax.ws.rs.core.GenericType) ImageSearchResultV1(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV1) ArrayList(java.util.ArrayList) ImageSearchResult(com.spotify.docker.client.messages.ImageSearchResult) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ExecutionException(java.util.concurrent.ExecutionException)

Example 32 with GenericType

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());
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 33 with GenericType

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());
}
Also used : GenericType(javax.ws.rs.core.GenericType) List(java.util.List) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 34 with GenericType

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());
}
Also used : GenericType(javax.ws.rs.core.GenericType) GenericEntity(javax.ws.rs.core.GenericEntity) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 35 with GenericType

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());
}
Also used : GenericType(javax.ws.rs.core.GenericType) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) List(java.util.List) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

GenericType (javax.ws.rs.core.GenericType)71 WebTarget (javax.ws.rs.client.WebTarget)42 List (java.util.List)35 Test (org.junit.Test)35 Response (javax.ws.rs.core.Response)24 ArrayList (java.util.ArrayList)15 GenericEntity (javax.ws.rs.core.GenericEntity)15 Collection (java.util.Collection)12 WebClient (org.apache.cxf.jaxrs.client.WebClient)9 JerseyTest (org.glassfish.jersey.test.JerseyTest)9 Queue (java.util.Queue)8 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 MediaType (javax.ws.rs.core.MediaType)7 Type (java.lang.reflect.Type)6 HashSet (java.util.HashSet)6 ExecutionException (java.util.concurrent.ExecutionException)6 Path (javax.ws.rs.Path)6 JAXBElement (javax.xml.bind.JAXBElement)6 Comparator (java.util.Comparator)5