Package org.apache.cxf.jaxrs.client

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


        doTestGetBookISOXML(null, "1");
    }
    private void doTestGetBookISO(String charset, String pathSegment) throws Exception {
        String address = "http://localhost:" + PORT + "/the/bookstore/ISO-8859-1/" + pathSegment;   
        WebClient wc = WebClient.create(address);
        wc.accept("application/json" + (charset == null ? "" : ";charset=ISO-8859-1"));
        byte[] iso88591bytes = wc.get(byte[].class);
        String helloStringISO88591 = new String(iso88591bytes, "ISO-8859-1");
       
        String name = helloStringISO88591.substring(
            helloStringISO88591.indexOf("\"name\":\"") + "\"name\":\"".length(),
View Full Code Here


    }
    private void doTestGetBookISOXML(String charset, String pathSegment) throws Exception {
        String address = "http://localhost:" + PORT + "/the/bookstore/ISO-8859-1/" + pathSegment;   
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
        wc.accept("application/xml" + (charset == null ? "" : ";charset=ISO-8859-1"));
        byte[] iso88591bytes = wc.get(byte[].class);
        String helloStringISO88591 = new String(iso88591bytes, "ISO-8859-1");
       
        String name = helloStringISO88591.substring(
            helloStringISO88591.indexOf("<name>") + "<name>".length(),
View Full Code Here

    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);
        source.setBuffering();
        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);
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 testGetBookJsonpJackson() throws Exception {
        String url = "http://localhost:" + PORT + "/the/jsonp2/books/123";
        WebClient client = WebClient.create(url);
        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(10000000);
        client.accept("application/json, application/x-javascript");
        client.query("_jsonp", "callback");
        Response r = client.get();
        assertEquals("application/x-javascript", r.getMetadata().getFirst("Content-Type"));
        String response = IOUtils.readStringFromStream((InputStream)r.getEntity());
        assertTrue(response.startsWith("callback({\"class\":\"org.apache.cxf.systest.jaxrs.Book\","));
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<Book> provider = new JAXBElementProvider<Book>();
        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, true);
        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

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.