Search in sources :

Example 96 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSClientServerResourceJacksonSpringProviderTest method testGetCollectionOfBooks.

@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());
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 97 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider 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)

Example 98 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSClientServerResourceJacksonSpringProviderTest method testEchoGenericSuperBookWebClient.

@Test
public void testEchoGenericSuperBookWebClient() throws Exception {
    String endpointAddress = "http://localhost:" + PORT + "/webapp/custombus/genericstore/books/superbook";
    WebClient wc = WebClient.create(endpointAddress, Collections.singletonList(new JacksonJsonProvider()));
    wc.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON);
    SuperBook book = wc.post(new SuperBook("Super", 124L, true), SuperBook.class);
    assertEquals(124L, book.getId());
    assertTrue(book.isSuperBook());
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 99 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSClientServerResourceJacksonSpringProviderTest method testMultipart.

@Test
public void testMultipart() throws Exception {
    String endpointAddress = "http://localhost:" + PORT + "/webapp/multipart";
    MultipartStore proxy = JAXRSClientFactory.create(endpointAddress, MultipartStore.class, Collections.singletonList(new JacksonJsonProvider()));
    Book json = new Book("json", 1L);
    InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
    Map<String, Object> attachments = proxy.addBookJsonImageStream(json, is1);
    assertEquals(2, attachments.size());
    Book json2 = ((Attachment) attachments.get("application/json")).getObject(Book.class);
    assertEquals("json", json2.getName());
    assertEquals(1L, json2.getId());
    InputStream is2 = ((Attachment) attachments.get("application/octet-stream")).getObject(InputStream.class);
    byte[] image1 = IOUtils.readBytesFromStream(getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
    byte[] image2 = IOUtils.readBytesFromStream(is2);
    assertArrayEquals(image1, image2);
}
Also used : InputStream(java.io.InputStream) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) Test(org.junit.Test)

Example 100 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSClientServerResourceJacksonSpringProviderTest method testGetCollectionOfSuperBooks.

@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());
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)225 WebClient (org.apache.cxf.jaxrs.client.WebClient)152 Response (javax.ws.rs.core.Response)129 ArrayList (java.util.ArrayList)112 HashMap (java.util.HashMap)104 URL (java.net.URL)103 Book (org.apache.cxf.systest.jaxrs.security.Book)76 Test (org.junit.Test)66 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)50 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)50 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)45 List (java.util.List)31 ClientBuilder (javax.ws.rs.client.ClientBuilder)28 Number (org.apache.coheigea.cxf.jaxrs.json.common.Number)28 LinkedList (java.util.LinkedList)27 GenericType (javax.ws.rs.core.GenericType)27 JwsWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor)27 MediaType (javax.ws.rs.core.MediaType)26 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)26 AbstractBusClientServerTestBase (org.apache.cxf.testutil.common.AbstractBusClientServerTestBase)26