Package org.apache.cxf.jaxrs.client

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


        assertEquals("{\"id\":123,\"name\":\"CXF in Action\"}", response);
    }
   
    @Test
    public void testFormattedJSON() {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/123");
        wc.accept("application/json");
        String response = wc.get(String.class);
        // {"Book":{"id":123,"name":"CXF in Action"}}
       
        assertTrue(response.startsWith("{"));
        assertTrue(response.endsWith("}"));
        assertTrue(response.contains("\"Book\":{"));
        assertTrue(response.indexOf("\"Book\":{") == 1);
       
        wc.query("_format", "");
        response = wc.get(String.class);
        //{
        //    "Book":{
        //      "id":123,
        //      "name":"CXF in Action"
        //    }
View Full Code Here


    }
   
    @Test
    public void testGetBookByHeaderPerRequestInjected() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore2/bookheaders/injected";
        WebClient wc = WebClient.create(address);
        wc.accept("application/xml");
        wc.header("BOOK", "1", "2", "3");
        Book b = wc.get(Book.class);
        assertEquals(123L, b.getId());
    }
View Full Code Here

    }
   
    @Test
    public void testGetBookByHeaderPerRequestInjectedFault() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore2/bookheaders/injected";
        WebClient wc = WebClient.create(address);
        wc.accept("application/xml");
        wc.header("BOOK", "2", "3");
        Response r = wc.get();
        assertEquals(400, r.getStatus());
        assertEquals("Param setter: 3 header values are required", r.readEntity(String.class));
    }
View Full Code Here

    }
   
    @Test
    public void testGetBookByHeaderPerRequestConstructorFault() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore2/bookheaders";
        WebClient wc = WebClient.create(address);
        wc.accept("application/xml");
        wc.header("BOOK", "1", "2", "4");
        Response r = wc.get();
        assertEquals(400, r.getStatus());
        assertEquals("Constructor: Header value 3 is required", r.readEntity(String.class));
    }
View Full Code Here

    }
   
    @Test
    public void testGetBookByHeaderPerRequestContextFault() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore2/bookheaders";
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
        wc.accept("application/xml");
        wc.header("BOOK", "1", "3", "4");
        Response r = wc.get();
        assertEquals(400, r.getStatus());
        assertEquals("Context setter: unexpected header value", r.readEntity(String.class));
    }
View Full Code Here

        JAXBElementProvider<?> provider = new JAXBElementProvider<Object>();
        Map<String, String> outMap = new HashMap<String, String>();
        outMap.put("Books", "CollectionWrapper");
        outMap.put("books", "Book");
        provider.setOutTransformElements(outMap);
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/adapter-list",
                                        Collections.singletonList(provider));
        Collection<? extends Book> books = wc.type("application/xml").accept("application/xml")
            .postAndGetCollection(new Books(new Book("CXF", 123L)), Book.class);
        assertEquals(1, books.size());
        assertEquals(123L, books.iterator().next().getId());
    }
View Full Code Here

        JAXBElementProvider<?> provider = new JAXBElementProvider<Object>();
        Map<String, String> outMap = new HashMap<String, String>();
        outMap.put("Books", "CollectionWrapper");
        outMap.put("books", "Book");
        provider.setOutTransformElements(outMap);
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/adapter-list",
                                        Collections.singletonList(provider));
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000);
        Response r = wc.type("application/xml").accept("application/json")
            .post(new Books(new Book("CXF", 123L)));
        assertEquals("{\"Book\":[{\"id\":123,\"name\":\"CXF\"}]}",
                     IOUtils.readStringFromStream((InputStream)r.getEntity()));
    }
View Full Code Here

        String address = "http://localhost:" + PORT + "/bookstore/booksubresource/instance/context/rc";
        doTestGetBookWithResourceContext(address);
    }
   
    private void doTestGetBookWithResourceContext(String address) throws Exception {
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
        wc.accept("application/xml");
        wc.query("bookid", "12345");
        wc.query("bookname", "bookcontext");
        Book2 book = wc.get(Book2.class);
        assertEquals(12345L, book.getId());
        assertEquals("bookcontext", book.getName());
    }
View Full Code Here

   
   
    @Test
    public void testAddBookCustomFailureStatus() throws Exception {
        String endpointAddress = "http://localhost:" + PORT + "/bookstore/books/customstatus";
        WebClient client = WebClient.create(endpointAddress);
        Book book = client.type("text/xml").accept("application/xml").post(new Book(), Book.class);
        assertEquals(888L, book.getId());
        Response r = client.getResponse();
        assertEquals("CustomValue", r.getMetadata().getFirst("CustomHeader"));
        assertEquals(233, r.getStatus());
        assertEquals("application/xml", r.getMetadata().getFirst("Content-Type"));
    }
View Full Code Here

    }
       
    @Test
    public void testGetCDs() throws Exception {
       
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/cds");
        CDs cds = wc.get(CDs.class);
        Collection<CD> collection = cds.getCD();
        assertEquals(2, collection.size());
        assertTrue(collection.contains(new CD("BICYCLE RACE", 124)));
        assertTrue(collection.contains(new CD("BOHEMIAN RHAPSODY", 123)));
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.client.WebClient

Copyright © 2018 www.massapicom. 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.