@POST @Consumes("multipart/form-data") @Produces("text/xml") @Path("form") public StreamingOutput getXMLFromMultipart(Attachment att, @Context final UriInfo info) { return produceOutput(att.getObject(InputStream.class), att.getHeaders(), info, "xml"); }
@POST @Consumes("multipart/form-data") @Produces({"text/csv", "application/json", "application/rdf+xml"}) @Path("form") public Response getMetadataFromMultipart(Attachment att, @Context UriInfo info) throws Exception { return Response.ok( parseMetadata(att.getObject(InputStream.class), att.getHeaders(), info)).build(); }
@POST @Consumes("multipart/form-data") @Produces("text/plain") @Path("form/main") public StreamingOutput getTextMainFromMultipart(final Attachment att, @Context final UriInfo info) { return produceTextMain(att.getObject(InputStream.class), att.getHeaders(), info); }
@POST @Consumes("multipart/form-data") @Produces("text/html") @Path("form") public StreamingOutput getHTMLFromMultipart(Attachment att, @Context final UriInfo info) { return produceOutput(att.getObject(InputStream.class), att.getHeaders(), info, "html"); }
@POST @Consumes("multipart/form-data") @Produces("text/plain") @Path("form") public StreamingOutput getTextFromMultipart(Attachment att, @Context final UriInfo info) { return produceText(att.getObject(InputStream.class), att.getHeaders(), info); }
throws Exception { return Response.ok( parseMetadata(att.getObject(InputStream.class), att.getHeaders(), info, handlerTypeName)).build();
public Response postMultiPart( @Multipart(value="stream") Attachment img, @Multipart(value="person", type="application/json") Person person) throws Exception { Image image = ImageIO.read(img.getObject(InputStream.class));
public <T> T getAttachmentObject(String contentId, Class<T> cls) { Attachment att = getAttachment(contentId); if (att != null) { return att.getObject(cls); } return null; } }
public <T> T getAttachmentObject(String contentId, Class<T> cls) { Attachment att = getAttachment(contentId); if (att != null) { return att.getObject(cls); } return null; } }
/** * Save/Update the given import configuration. * Prepare the file to be processed with Camel routes * * @param file file * @param importConfigId config * @return OK / NOK Http Code. */ @POST @Path("/oneshot") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) public Response processOneshotImportConfigurationCSV(@Multipart(value = "importConfigId") String importConfigId, @Multipart(value = "file") Attachment file) { try { java.nio.file.Path path = Paths.get(configSharingService.getProperty(RouterConstants.IMPORT_ONESHOT_UPLOAD_DIR) + importConfigId + ".csv"); Files.deleteIfExists(path); InputStream in = file.getObject(InputStream.class); Files.copy(in, path); } catch (IOException e) { logger.error("Error processing one shot configuration CSV", e); return Response.serverError().build(); } return Response.ok().build(); } }
/** * Uploads a file encoded in a multipart/form message. * * @param multipart * the multiPart object containing the file to be uploaded * @return a URI with the (custom) uploaded:// scheme and a unique * identifier to be used future ingests. Returns 202 if request succeeds */ @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Response upload(MultipartBody multipart){ Attachment file = multipart.getAttachment("file"); if (file == null) { return Response.status(400).entity("Missing file part").type(MediaType.TEXT_PLAIN).build(); } InputStream fileStream = file.getObject(InputStream.class); String uploaded; try { uploaded = m_management.putTempStream(getContext(), fileStream); logger.debug("File uploaded: ", uploaded); } catch (ServerException e) { logger.error(e.toString()); return handleException(e, false); } return Response.status(Response.Status.ACCEPTED).entity(uploaded).type( MediaType.TEXT_PLAIN).build(); } }
/** * Uploads a file encoded in a multipart/form message. * * @param multipart * the multiPart object containing the file to be uploaded * @return a URI with the (custom) uploaded:// scheme and a unique * identifier to be used future ingests. Returns 202 if request succeeds */ @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Response upload(MultipartBody multipart){ Attachment file = multipart.getAttachment("file"); if (file == null) { return Response.status(400).entity("Missing file part").type(MediaType.TEXT_PLAIN).build(); } InputStream fileStream = file.getObject(InputStream.class); String uploaded; try { uploaded = m_management.putTempStream(getContext(), fileStream); logger.debug("File uploaded: ", uploaded); } catch (ServerException e) { logger.error(e.toString()); return handleException(e, false); } return Response.status(Response.Status.ACCEPTED).entity(uploaded).type( MediaType.TEXT_PLAIN).build(); } }
} else if (Attachment.class.isAssignableFrom(obj.getClass())) { Attachment att = (Attachment)obj; if (att.getObject() == null) { return att; dh = getHandlerForObject(att.getObject(), att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); return new Attachment(att.getContentId(), dh, att.getHeaders());
} else if (Attachment.class.isAssignableFrom(obj.getClass())) { Attachment att = (Attachment)obj; if (att.getObject() == null) { return att; dh = getHandlerForObject(att.getObject(), att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); return new Attachment(att.getContentId(), dh, att.getHeaders());
@POST @Path("/books/filesform2") @Produces("text/xml") @Consumes("multipart/form-data") public Response addBookFilesFormNoOwnerParam(@Multipart("files") List<Book> books) throws Exception { Attachment attOwner = AttachmentUtils.getFirstMatchingPart(context, "owner"); return addBookFilesForm(attOwner.getObject(String.class), books); }
@Path("/books/file/semicolon") @Consumes("multipart/form-data") @Produces("text/plain") @POST public String addBookFileNameSemicolon(@Multipart("a") Attachment att) { return att.getObject(String.class) + ", filename:" + att.getContentDisposition().getParameter("filename"); }
InputStream logoStream = att.getObject(InputStream.class); CachedOutputStream cos = new CachedOutputStream(); try {
InputStream logoStream = att.getObject(InputStream.class); CachedOutputStream cos = new CachedOutputStream(); try {
@Test public void testMultipart() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/multipart"; MultipartStore proxy = JAXRSClientFactory.create(endpointAddress, MultipartStore.class, Collections.singletonList(new JacksonJsonProvider())); Book json = new Book("json", 1L); InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"); Map<String, Object> attachments = proxy.addBookJsonImageStream(json, is1); assertEquals(2, attachments.size()); Book json2 = ((Attachment)attachments.get("application/json")).getObject(Book.class); assertEquals("json", json2.getName()); assertEquals(1L, json2.getId()); InputStream is2 = ((Attachment)attachments.get("application/octet-stream")).getObject(InputStream.class); byte[] image1 = IOUtils.readBytesFromStream( getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg")); byte[] image2 = IOUtils.readBytesFromStream(is2); assertTrue(Arrays.equals(image1, image2)); }
private void doTestGetBookAsPlainContent(String address) throws Exception { WebClient wc = WebClient.create(address); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000); wc.accept("multipart/mixed"); MultipartBody book = wc.get(MultipartBody.class); Book b = book.getRootAttachment().getObject(Book.class); assertEquals(888L, b.getId()); }