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"); } }
@POST @Path("/books/fileform") @Produces("text/xml") @Consumes("multipart/form-data") public Response addBookFilesForm(MultipartBody body) throws Exception { String owner = body.getAttachmentObject("owner", String.class); Book book = body.getAttachmentObject("file", Book.class); if (!"CXF in Action - 1".equals(book.getName()) || !"Larry".equals(owner)) { throw new WebApplicationException(); } book.setId(124); book.setName("CXF in Action - 2"); return Response.ok(book).build(); }
@POST @Path("/books/jaxb-body") @Consumes("multipart/related;type=\"text/xml\"") @Produces("text/xml") public Response addBookParts2(MultipartBody body) throws Exception { Book b1 = body.getAttachmentObject("rootPart", Book.class); Book b2 = body.getAttachmentObject("book2", Book.class); if (b1.equals(b2)) { throw new WebApplicationException(); } if (!b1.getName().equals(b2.getName())) { throw new WebApplicationException(); } b1.setId(124); return Response.ok(b1).build(); }
@Path("/") public ConsumerRegistration register(MultipartBody body) { String appName = body.getAttachmentObject("appName", String.class); String appURI = body.getAttachmentObject("appURI", String.class); String appRedirectURI = body.getAttachmentObject("appRedirectURI", String.class); String appDesc = body.getAttachmentObject("appDescription", String.class);
@Path("/") public ConsumerRegistration register(MultipartBody body) { String appName = body.getAttachmentObject("appName", String.class); String appURI = body.getAttachmentObject("appURI", String.class); String appDesc = body.getAttachmentObject("appDescription", String.class);
Book jaxbBook = body.getAttachmentObject("book1", Book.class); Book jsonBook = body.getAttachmentObject("book2", Book.class);