Package org.apache.cxf.jaxrs.client

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


    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


   
    @Test
    public void testBookExistsMalformedMt() throws Exception {
        WebClient wc =
            WebClient.create("http://localhost:" + PORT + "/bookstore/books/check/malformedmt/123");
        wc.accept(MediaType.TEXT_PLAIN);
        WebClient.getConfig(wc).getInInterceptors().add(new ReplaceContentTypeInterceptor());
        assertTrue(wc.get(Boolean.class));
    }
   
    @Test
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

    }
   
    private void doTestEmptyResponse(String mt) {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/emptybook");
        WebClient.getConfig(wc).getInInterceptors().add(new ReplaceStatusInterceptor());
        wc.accept(mt);
        wc.get(Book.class);
    }
   
    @Test(expected = ClientWebApplicationException.class)
    public void testEmptyResponseProxy() {
View Full Code Here

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

   
    @Test
    public void testWithComplexPath() {
        WebClient wc =
            WebClient.create("http://localhost:" + PORT + "/bookstore/allCharsButA-B/:@!$&'()*+,;=-._~");
        wc.accept("application/xml");
        Book book = wc.get(Book.class);
        assertEquals("Encoded Path", book.getName());
    }
   
    @Test
View Full Code Here

   
    @Test
    public void testMalformedAcceptType() {
        WebClient wc =
            WebClient.create("http://localhost:" + PORT + "/bookstore/books/123");
        wc.accept("application");
        Response r = wc.get();
        assertEquals(406, r.getStatus());
    }
   
    @Test
View Full Code Here

    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

    public void testPostCollectionGetBooksWebClient() 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

    ObjectMapper objectMapper = new ObjectMapper();
    String writeValueAsString = objectMapper.writeValueAsString(new CustomerData("mirek", 27, BigDecimal.TEN));

    // when
    Response response =
        rsclient.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON_TYPE).path(
            "/command/execute/pl.com.stream.CustomerService/add").put(writeValueAsString);

  }
}
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.