Package org.apache.cxf.jaxrs.client

Examples of org.apache.cxf.jaxrs.client.WebClient.accept()


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


    }
   
    @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 (ServerWebApplicationException ex) {
            assertEquals(500, ex.getStatus());
View Full Code Here

    public void testServerWebApplicationExceptionXML() throws Exception {
        ResponseReader reader = new ResponseReader();
        reader.setEntityClass(Book.class);
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexceptionXML",
                                        Collections.singletonList(reader));
        wc.accept("application/xml");
        try {
            wc.get(Book.class);
            fail("Exception expected");
        } catch (ServerWebApplicationException ex) {
            assertEquals(406, ex.getStatus());
View Full Code Here

    public void testGetBookFromResponseWithWebClient() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/genericresponse/123";
        WebClient wc = WebClient.create(address,
                                        Collections.singletonList(
                                        new ResponseReader(Book.class)));
        Response r = wc.accept("application/xml").get();
        assertEquals(200, r.getStatus());
        Book book = (Book)r.getEntity();
        assertEquals(123L, book.getId());
    }
   
View Full Code Here

        return serviceProxy;
    }

    public WebClient createWebClient(final String path) {
        WebClient wc = restClientFactory.createWebClient().to(BASE_URL, false);
        wc.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE);
        wc.path(path);
        return wc;
    }

    public void setupContentType(final Client restClient) {
View Full Code Here

    public void testPostCollectionGenericEntityWebClient() throws Exception {
       
        String endpointAddress =
            "http://localhost:" + PORT + "/bookstore/collections3";
        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);
View Full Code Here

    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);
View Full Code Here

    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);
View Full Code Here

    }
   
    @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 (ServerWebApplicationException ex) {
            assertEquals(500, ex.getStatus());
View Full Code Here

    }
   
    @Test
    public void testServerWebApplicationExceptionResponse() throws Exception {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexception");
        wc.accept("application/xml");
        try {
            Response r = wc.get(Response.class);
            assertEquals(500, r.getStatus());
        } catch (ServerWebApplicationException ex) {
            fail("Unexpected exception");
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.