Package org.apache.cxf.jaxrs.resources

Examples of org.apache.cxf.jaxrs.resources.Book


    @Ignore
    public static class TheBooks {

        @Path("/books/{bookId}/{new}")
        public Book getNewBook(Book b) {
            return new Book();
        }
View Full Code Here


            return new Book();
        }
       
        @Path("/books/{bookId}/{new}")
        public Book getNewBook2() {
            return new Book();
        }
View Full Code Here

    @Test
    public void testWrite() throws Exception {
        XSLTJaxbProvider provider = new XSLTJaxbProvider();
        provider.setOutTemplate(TEMPLATE_LOCATION);
       
        Book b = new Book();
        b.setId(123L);
        b.setName("TheBook");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(b, Book.class, Book.class, b.getClass().getAnnotations(),
                         MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
        Unmarshaller um = provider.getClassContext(Book.class).createUnmarshaller();
        Book b2 = (Book)um.unmarshal(new StringReader(bos.toString()));
        b.setName("TheBook2");
        assertEquals("Transformation is bad", b, b2);
    }
View Full Code Here

    @Test
    public void testRead() throws Exception {
        XSLTJaxbProvider provider = new XSLTJaxbProvider();
        provider.setInTemplate(TEMPLATE_LOCATION);
       
        Book b = new Book();
        b.setId(123L);
        b.setName("TheBook");
        Book b2 = (Book)provider.readFrom((Class)Book.class, Book.class, b.getClass().getAnnotations(),
                          MediaType.TEXT_XML_TYPE, new MetadataMap<String, String>(),
                          new ByteArrayInputStream(BOOK_XML.getBytes()));
        b.setName("TheBook2");
        assertEquals("Transformation is bad", b, b2);
    }
View Full Code Here

        SearchContext context = new SearchContextImpl(m);
        SearchCondition<Book> sc = context.getCondition(Book.class);
        assertNotNull(sc);
       
        List<Book> books = new ArrayList<Book>();
        books.add(new Book("CXF is cool", 125L));
        books.add(new Book("CXF Rocks", 125L));
       
        List<Book> found = sc.findAll(books);
        assertEquals(1, found.size());
        assertEquals(new Book("CXF Rocks", 125L), found.get(0));
    }
View Full Code Here

   
    @Test
    public void testWriteBookWithStringConverter() throws Exception {
        JSONProvider p = new JSONProvider();
        p.setConvertTypesToStrings(true);
        Book book = new Book("CXF", 125);
       
        ByteArrayOutputStream os = new ByteArrayOutputStream();
       
        p.writeTo(book, (Class)Book.class, Book.class, Book.class.getAnnotations(),
                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);
View Full Code Here

        JAXBElementProvider provider = new JAXBElementProvider();
        if (setName) {
            provider.setCollectionWrapperName("Books");
        }
        List<Book> books = new ArrayList<Book>();
        books.add(new Book("CXF in Action", 123L));
        books.add(new Book("CXF Rocks", 124L));
        Object o = type.isArray() ? books.toArray() : type == Set.class
            ? new HashSet<Book>(books) : books;
       
        Method m = CollectionsResource.class.getMethod(mName, new Class[0]);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
View Full Code Here

   
    @Test
    public void testWriteDerivedType() throws Exception {
        JAXBElementProvider provider = new JAXBElementProvider();
        provider.setJaxbElementClassNames(Collections.singletonList(Book.class.getName()));
        Book b = new SuperBook("CXF in Action", 123L, 124L);
       
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(b, Book.class, Book.class,
                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
        readSuperBook(bos.toString(), true);
View Full Code Here

    }
   
    @Test
    public void testWriteDerivedType2() throws Exception {
        JAXBElementProvider provider = new JAXBElementProvider();
        Book b = new SuperBook("CXF in Action", 123L, 124L);
       
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(b, Book.class, Book.class,
                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
       
View Full Code Here

   
    private void doTestWriteJAXBCollection(String mName) throws Exception {
        JAXBElementProvider provider = new JAXBElementProvider();
        List<JAXBElement<Book>> books = new ArrayList<JAXBElement<Book>>();
        books.add(new JAXBElement<Book>(new QName("Books"), Book.class, null,
            new Book("CXF in Action", 123L)));
        books.add(new JAXBElement<Book>(new QName("Books"), Book.class, null,
            new Book("CXF Rocks", 124L)));
       
        Method m = CollectionsResource.class.getMethod(mName, new Class[0]);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        provider.writeTo(books, m.getReturnType(), m.getGenericReturnType(),
                       new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.resources.Book

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.