Package org.apache.cxf.jaxrs.client

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


    @Test
    public void testReaderWriterFromInterceptors() throws Exception {
        String endpointAddress =
            "http://localhost:" + PORT + "/the/thebooksWithStax/bookstore/books/convert";
        WebClient wc = WebClient.create(endpointAddress);
        wc.type("application/xml").accept("application/xml");
        Book2 b = new Book2();
        b.setId(777L);
        b.setName("CXF - 777");
        Book2 b2 = wc.invoke("POST", b, Book2.class);
        assertNotSame(b, b2);
View Full Code Here


    }
   
    @Test
    public void testAddInvalidBookDuplicateElementJson() throws Exception {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/the/bookstore/books/convert");
        wc.type("application/json");
        InputStream is = getClass().getResourceAsStream("resources/add_book2json_duplicate.txt");
        assertNotNull(is);
        Response r = wc.post(is);
        assertEquals(400, r.getStatus());
        String content = IOUtils.readStringFromStream((InputStream)r.getEntity());
View Full Code Here

  public void testSimpleWordMultipartXML() throws Exception {
    ClassLoader.getSystemResourceAsStream(TEST_DOC)
    Attachment attachmentPart =
        new Attachment("myworddoc", "application/msword", ClassLoader.getSystemResourceAsStream(TEST_DOC));
    WebClient webClient = WebClient.create(endPoint + TIKA_PATH + "/form");
    Response response = webClient.type("multipart/form-data")
      .accept("text/xml")
      .put(attachmentPart);
    String responseMsg = getStringFromInputStream((InputStream) response
      .getEntity());
    assertTrue(responseMsg.contains("test"));
View Full Code Here

    @Test
    public void testGetGenericBook() throws Exception {
        String baseAddress = "http://localhost:" + PORT + "/the/thebooks8/books";
        WebClient wc = WebClient.create(baseAddress);
        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000);
        Long id = wc.type("application/xml").accept("text/plain").post(new Book("CXF", 1L), Long.class);
        assertEquals(new Long(1), id);
        Book book = wc.replaceHeader("Accept", "application/xml").query("id", 1L).get(Book.class);
        assertEquals("CXF", book.getName());
    }
   
View Full Code Here

    @Test
    public void testGetBookWithRequestScope() {
        // the BookStore method which will handle this request depends on the injected HttpHeaders
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/test/request/bookstore/booksecho2");
        wc.type("text/plain").accept("text/plain");
        wc.header("CustomHeader", "custom-header");
        String value = wc.post("CXF", String.class);
        assertEquals("CXF", value);
        assertEquals("custom-header", wc.getResponse().getMetadata().getFirst("CustomHeader"));
    }
View Full Code Here

        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

    @Test
    public void testReaderWriterFromJaxrsFilters() throws Exception {
        String endpointAddress =
            "http://localhost:" + PORT + "/the/thebooksWithStax/bookstore/books/convert2/123";
        WebClient wc = WebClient.create(endpointAddress);
        wc.type("application/xml").accept("application/xml");
        Book2 b = new Book2();
        b.setId(777L);
        b.setName("CXF - 777");
        Book2 b2 = wc.invoke("PUT", b, Book2.class);
        assertNotSame(b, b2);
View Full Code Here

    @Test
    public void testReaderWriterFromInterceptors() throws Exception {
        String endpointAddress =
            "http://localhost:" + PORT + "/the/thebooksWithStax/bookstore/books/convert";
        WebClient wc = WebClient.create(endpointAddress);
        wc.type("application/xml").accept("application/xml");
        Book2 b = new Book2();
        b.setId(777L);
        b.setName("CXF - 777");
        Book2 b2 = wc.invoke("POST", b, Book2.class);
        assertNotSame(b, b2);
View Full Code Here

    }
   
    @Test
    public void testAddInvalidBookDuplicateElementJson() throws Exception {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/the/bookstore/books/convert");
        wc.type("application/json");
        InputStream is = getClass().getResourceAsStream("resources/add_book2json_duplicate.txt");
        assertNotNull(is);
        Response r = wc.post(is);
        assertEquals(400, r.getStatus());
        String content = IOUtils.readStringFromStream((InputStream)r.getEntity());
View Full Code Here

   
    @Test
    public void testBookAsRootAttachmentInputStreamReadItself() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/books/istream2";
        WebClient wc = WebClient.create(address);
        wc.type("multipart/mixed;type=text/xml");
        wc.accept("text/xml");
       
        Book book = wc.post(new Book("CXF in Action - 2", 12345L), Book.class);
        assertEquals(432L, book.getId());
    }
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.