Package common.attachment

Examples of common.attachment.Book


     * @return
     * @throws Exception
     */
    private MultipartBody createMultipartBody() throws Exception  {
        List<Attachment> atts = new LinkedList<Attachment>();
        atts.add(new Attachment("book1", "application/xml", new Book("JAXB", 1L)));
        atts.add(new Attachment("book2", "application/json", new Book("JSON", 2L)));
       
        atts.add(new Attachment("image", "application/octet-stream",
                                getClass().getResourceAsStream("/java.jpg")));
       
        return new MultipartBody(atts, true)
View Full Code Here


        return new MultipartBody(atts, true)

    }
   
    private void verifyMultipartResponse(MultipartBody bodyResponse) throws Exception {
        Book jaxbBook = bodyResponse.getAttachmentObject("book1", Book.class);
        Book jsonBook = bodyResponse.getAttachmentObject("book2", Book.class);
       
        byte[] receivedImageBytes = bodyResponse.getAttachmentObject("image", byte[].class);
        InputStream is = getClass().getResourceAsStream("/java.jpg");
        byte[] imageBytes = IOUtils.readBytesFromStream(is);
       
        if ("JAXB".equals(jaxbBook.getName()) && 1L == jaxbBook.getId()
            && "JSON".equals(jsonBook.getName()) && 2L == jsonBook.getId()
            && Arrays.equals(imageBytes, receivedImageBytes)) {
            System.out.println();
            System.out.println("Book attachments have been successfully received");
        } else {
            throw new RuntimeException("Received Book attachment is corrupted");
View Full Code Here

       
        // MultipartBody will use the Content-Type value of the individual
        // part to read its data in a type safe way by delegating to a matching
        // JAX-RS MessageBodyReader provider
       
        Book jaxbBook = body.getAttachmentObject("book1", Book.class);
        Book jsonBook = body.getAttachmentObject("book2", Book.class);
       
        // Accessing individual attachment part, its DataHandler will be
        // used to access the underlying input stream, the type-safe access
        // is also possible
       
        Attachment imageAtt = body.getAttachment("image");
       
        if ("JAXB".equals(jaxbBook.getName()) && 1L == jaxbBook.getId()
            && "JSON".equals(jsonBook.getName()) && 2L == jsonBook.getId()
            && imageAtt != null) {
            return createMultipartBody(jaxbBook, jsonBook, imageAtt.getDataHandler());
        }
        throw new RuntimeException("Received Book attachment is corrupted");
    }
View Full Code Here

TOP

Related Classes of common.attachment.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.