Examples of WebClient


Examples of org.apache.cxf.jaxrs.client.WebClient

    @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<Book>();
        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());
    }
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

    @Test
    public void testPostCollectionOfBooksWebClient() 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<Book>();
        books.add(b1);
        books.add(b2);
        List<Book> books2 = new ArrayList<Book>(wc.postAndGetCollection(books, Book.class, Book.class));
        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());
    }
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

    @Test
    public void testPostObjectGetCollection() throws Exception {
       
        String endpointAddress =
            "http://localhost:" + PORT + "/bookstore/collectionBook";
        WebClient wc = WebClient.create(endpointAddress);
        wc.accept("application/xml").type("application/xml");
        Book b1 = new Book("Book", 666L);
        List<Book> books = new ArrayList<Book>(wc.postObjectGetCollection(b1, Book.class));
        assertNotNull(books);
        assertEquals(1, books.size());
        Book b = books.get(0);
        assertEquals(666L, b.getId());
        assertEquals("Book", b.getName());
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

    @Test
    public void testGetBookResponseAndETag() throws Exception {
       
        String endpointAddress =
            "http://localhost:" + PORT + "/bookstore/books/response/123";
        WebClient wc = WebClient.create(endpointAddress);
        Book book = wc.get(Book.class);
        assertEquals(200, wc.getResponse().getStatus());
        assertEquals(123L, book.getId());
        MultivaluedMap<String, Object> headers = wc.getResponse().getMetadata();
        assertTrue(headers.size() > 0);
        Object etag = headers.getFirst("ETag");
        assertNotNull(etag);
        assertTrue(etag.toString().startsWith("\""));
        assertTrue(etag.toString().endsWith("\""));
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

    }
   
   
    @Test
    public void testOnewayWebClient() throws Exception {
        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/oneway");
        Response r = client.header("OnewayRequest", "true").post(null);
        assertEquals(202, r.getStatus());
        assertFalse(r.getHeaders().isEmpty());
    }
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

        assertFalse(r.getHeaders().isEmpty());
    }
   
    @Test
    public void testBookWithSpace() throws Exception {
        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/").path("the books/123");
        Book book = client.get(Book.class);
        assertEquals(123L, book.getId());
    }
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

        }
    }
   
    @Test
    public void testTempRedirectWebClient() throws Exception {
        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/tempredirect");
        Response r = client.type("*/*").get();
        assertEquals(307, r.getStatus());
        MultivaluedMap<String, Object> map = r.getMetadata();
        assertEquals("http://localhost:" + PORT + "/whatever/redirection?css1=http%3A//bar",
                     map.getFirst("Location").toString());
        List<Object> cookies = r.getMetadata().get("Set-Cookie");
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

        assertEquals(2, cookies.size());
    }
   
    @Test
    public void testSetCookieWebClient() throws Exception {
        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/setcookies");
        Response r = client.type("*/*").get();
        assertEquals(200, r.getStatus());
        List<Object> cookies = r.getMetadata().get("Set-Cookie");
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
    }
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

        assertEquals(1, cookies.size());
    }
   
    @Test
    public void testSetManyCookiesWebClient() throws Exception {
        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/setmanycookies");
        Response r = client.type("*/*").get();
        assertEquals(200, r.getStatus());
        List<Object> cookies = r.getMetadata().get("Set-Cookie");
        assertNotNull(cookies);
        assertEquals(3, cookies.size());
    }
View Full Code Here

Examples of org.apache.cxf.jaxrs.client.WebClient

                      data, "application/xml", 500);
    }
   
    @Test
    public void testServerWebApplicationException() throws Exception {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexception");
        wc.accept("application/xml");
        try {
            wc.get(Book.class);
            fail("Exception expected");
        } catch (ServerErrorException ex) {
            assertEquals(500, ex.getResponse().getStatus());
            assertEquals("This is a WebApplicationException", ex.getResponse().readEntity(String.class));
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.