Package org.apache.cxf.jaxrs.client

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


    public void testGetBookXSLTHtml() throws Exception {

        String endpointAddress =
            "http://localhost:" + PORT + "/the/thebooks5/bookstore/books/xslt";
        WebClient wc = WebClient.create(endpointAddress);
        wc.accept("application/xhtml+xml").path(666).matrix("name2", 2).query("name", "Action - ");
        XMLSource source = wc.get(XMLSource.class);
        Map<String, String> namespaces = new HashMap<String, String>();
        namespaces.put("xhtml", "http://www.w3.org/1999/xhtml");
        Book2 b = source.getNode("xhtml:html/xhtml:body/xhtml:ul/xhtml:Book", namespaces, Book2.class);
        assertEquals(666, b.getId());
View Full Code Here


    @Test
    public void testBookDepthExceededJettison() throws Exception {
        String endpointAddress =
            "http://localhost:" + PORT + "/the/thebooks10/depth";
        WebClient wc = WebClient.create(endpointAddress);
        wc.accept("application/json").type("application/json");
        Response r = wc.post(new Book("CXF", 123L));
        assertEquals(413, r.getStatus());
    }
   
    @Test
View Full Code Here

   
    @Test
    public void testGetBookJsonp() throws Exception {
        String url = "http://localhost:" + PORT + "/the/jsonp/books/123";
        WebClient client = WebClient.create(url);
        client.accept("application/json, application/x-javascript");
        client.query("_jsonp", "callback");
        Response r = client.get();
        assertEquals("application/x-javascript", r.getMetadata().getFirst("Content-Type"));
        assertEquals("callback({\"Book\":{\"id\":123,\"name\":\"CXF in Action\"}});",
                     IOUtils.readStringFromStream((InputStream)r.getEntity()));
View Full Code Here

   
    @Test
    public void testGetBookWithoutJsonpCallback() throws Exception {
        String url = "http://localhost:" + PORT + "/the/jsonp/books/123";
        WebClient client = WebClient.create(url);
        client.accept("application/json, application/x-javascript");
        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000L);
        Response r = client.get();
        assertEquals("application/json", r.getMetadata().getFirst("Content-Type"));
        assertEquals("{\"Book\":{\"id\":123,\"name\":\"CXF in Action\"}}",
                     IOUtils.readStringFromStream((InputStream)r.getEntity()));
View Full Code Here

   
    @Test
    public void testGetBookXsiType() throws Exception {
        String address = "http://localhost:" + PORT + "/the/thebooksxsi/bookstore/books/xsitype";
        WebClient wc = WebClient.create(address);
        wc.accept("application/xml");
        Book book = wc.get(Book.class);
        assertEquals("SuperBook", book.getName());
       
    }
   
View Full Code Here

        String address = "http://localhost:" + PORT + "/the/thebooksxsi/bookstore/books/xsitype";
        JAXBElementProvider provider = new JAXBElementProvider();
        provider.setExtraClass(new Class[]{SuperBook.class});
        provider.setJaxbElementClassNames(Collections.singletonList(Book.class.getName()));
        WebClient wc = WebClient.create(address, Collections.singletonList(provider));
        wc.accept("application/xml");
        wc.type("application/xml");
        SuperBook book = new SuperBook("SuperBook2", 999L);
        Book book2 = wc.invoke("POST", book, Book.class, Book.class);
        assertEquals("SuperBook2", book2.getName());
       
View Full Code Here

        WebClient client = WebClient.create(endpointAddress,
            Collections.singletonList(new AegisElementProvider<Object>()));
        if (mHeader != null) {
            client = client.header("X-HTTP-Method-Override", mHeader);
        }
        Book book = client.accept(type).get(Book.class);

        assertEquals(124L, book.getId());
        assertEquals("CXF in Action - 2", book.getName());
    }
   
View Full Code Here

    @Test
    public void testGetBookXSLTXml() throws Exception {
        String endpointAddress =
            "http://localhost:" + PORT + "/the/thebooks5/bookstore/books/xslt";
        WebClient wc = WebClient.create(endpointAddress);
        wc.accept("application/xml").path(666).matrix("name2", 2).query("name", "Action - ");
        Book b = wc.get(Book.class);
        assertEquals(666, b.getId());
        assertEquals("CXF in Action - 2", b.getName());
    }
   
View Full Code Here

        JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean;
       
        WebClient wc = (WebClient)cfb.create();
        assertEquals("https://localhost:" + PORT, wc.getBaseURI().toString());
       
        wc.accept("application/xml");
        wc.path("bookstore/securebooks/123");
        TheBook b = wc.get(TheBook.class);
       
        assertEquals(b.getId(), 123);
        b = wc.get(TheBook.class);
View Full Code Here

   
    private void doTestGetBookWebEx(String address) throws Exception {
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
        try {
            wc.accept("text/plain", "application/json").get(Book.class);
            fail("InternalServerErrorException is expected");
        } catch (InternalServerErrorException ex) {
            String errorMessage = ex.getResponse().readEntity(String.class);
            assertEquals("Book web exception", errorMessage);
        }
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.