@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/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/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/plain") @Path("form") public StreamingOutput getTextFromMultipart(Attachment att, @Context final UriInfo info) { return produceText(att.getObject(InputStream.class), att.getHeaders(), info); }
@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); }
throws Exception { return Response.ok( parseMetadata(att.getObject(InputStream.class), att.getHeaders(), info, handlerTypeName)).build();
/** * Gets an element from the given {@link Attachment} object. * * @param attachment * the attachment * @param element * the element * @return the element or null if not found. */ private String getElementFromContentDisposition(final Attachment attachment, final String element) { final MultivaluedMap<String, String> multivaluedMap = attachment.getHeaders(); final String[] contentDispositions = multivaluedMap.getFirst("Content-Disposition") .split(";"); for (final String contentDisposition : contentDispositions) { if ((contentDisposition.trim().startsWith(element))) { final String[] keyValue = contentDisposition.split("="); final String value = keyValue[1].trim(); return value; } } return null; }
@Override public void filter(List<Attachment> atts) { Attachment dataPart = atts.remove(0); Attachment newDataPart = new Attachment(new ByteArrayInputStream("Hi".getBytes()), dataPart.getHeaders()); atts.add(0, newDataPart); } }
private DefaultAttachment createCamelAttachment(Attachment attachment) { DefaultAttachment camelAttachment = new DefaultAttachment(attachment.getDataHandler()); for (String name : attachment.getHeaders().keySet()) { for (String value : attachment.getHeaderAsList(name)) { camelAttachment.addHeader(name, value); } } return camelAttachment; }
att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); return new Attachment(att.getContentId(), dh, att.getHeaders()); } else if (byte[].class.isAssignableFrom(obj.getClass())) { ByteDataSource source = new ByteDataSource((byte[])obj);
Attachment handler = (Attachment)handlers.get(i); AttachmentImpl att = new AttachmentImpl(handler.getContentId(), handler.getDataHandler()); for (String key : handler.getHeaders().keySet()) { att.setHeader(key, handler.getHeader(key)); MultivaluedMap<String, String> rootHeaders = new MetadataMap<>(root.getHeaders()); if (!AttachmentUtil.isMtomEnabled(outMessage)) { rootHeaders.putSingle(Message.CONTENT_TYPE, rootContentType);
att.getObject().getClass(), new Annotation[]{}, att.getContentType().toString(), id); return new Attachment(att.getContentId(), dh, att.getHeaders()); } else if (byte[].class.isAssignableFrom(obj.getClass())) { ByteDataSource source = new ByteDataSource((byte[])obj);
@POST @Path("/books/formimage") @Consumes("multipart/form-data") @Produces("multipart/form-data") public MultipartBody addBookFormImage(MultipartBody image) throws Exception { List<Attachment> atts = image.getAllAttachments(); if (atts.size() != 1) { throw new WebApplicationException(); } List<Attachment> newAtts = new ArrayList<>(); Attachment at = atts.get(0); MultivaluedMap<String, String> headers = at.getHeaders(); if (!"http://host/bar".equals(headers.getFirst("Content-Location"))) { throw new WebApplicationException(); } if (!"custom".equals(headers.getFirst("Custom-Header"))) { throw new WebApplicationException(); } headers.putSingle("Content-Location", "http://host/location"); newAtts.add(new Attachment(at.getContentId(), at.getDataHandler(), headers)); return new MultipartBody(newAtts); }
Attachment handler = (Attachment)handlers.get(i); AttachmentImpl att = new AttachmentImpl(handler.getContentId(), handler.getDataHandler()); for (String key : handler.getHeaders().keySet()) { att.setHeader(key, handler.getHeader(key)); MultivaluedMap<String, String> rootHeaders = new MetadataMap<String, String>(root.getHeaders()); if (!AttachmentUtil.isMtomEnabled(outMessage)) { rootHeaders.putSingle(Message.CONTENT_TYPE, rootContentType);
private <T> Object fromAttachment(Attachment multipart, Class<T> c, Type t, Annotation[] anns) throws IOException { if (DataHandler.class.isAssignableFrom(c)) { return multipart.getDataHandler(); } else if (DataSource.class.isAssignableFrom(c)) { return multipart.getDataHandler().getDataSource(); } else if (Attachment.class.isAssignableFrom(c)) { return multipart; } else { if (mediaTypeSupported(multipart.getContentType())) { mc.put("org.apache.cxf.multipart.embedded", true); mc.put("org.apache.cxf.multipart.embedded.ctype", multipart.getContentType()); mc.put("org.apache.cxf.multipart.embedded.input", multipart.getDataHandler().getInputStream()); anns = new Annotation[]{}; } MessageBodyReader<T> r = mc.getProviders().getMessageBodyReader(c, t, anns, multipart.getContentType()); if (r != null) { InputStream is = multipart.getDataHandler().getInputStream(); return r.readFrom(c, t, anns, multipart.getContentType(), multipart.getHeaders(), is); } } return null; }
newStream = jwsStream; Attachment newDataPart = new Attachment(newStream, dataPart.getHeaders()); atts.add(i, newDataPart);
private <T> Object fromAttachment(Attachment multipart, Class<T> c, Type t, Annotation anns[]) throws IOException { if (DataHandler.class.isAssignableFrom(c)) { return multipart.getDataHandler(); } else if (DataSource.class.isAssignableFrom(c)) { return multipart.getDataHandler().getDataSource(); } else if (Attachment.class.isAssignableFrom(c)) { return multipart; } else { if (mediaTypeSupported(multipart.getContentType())) { mc.put("org.apache.cxf.multipart.embedded", true); mc.put("org.apache.cxf.multipart.embedded.ctype", multipart.getContentType()); mc.put("org.apache.cxf.multipart.embedded.input", multipart.getDataHandler().getInputStream()); anns = new Annotation[]{}; } MessageBodyReader<T> r = mc.getProviders().getMessageBodyReader(c, t, anns, multipart.getContentType()); if (r != null) { InputStream is = multipart.getDataHandler().getInputStream(); is = decodeIfNeeded(multipart, is); return r.readFrom(c, t, anns, multipart.getContentType(), multipart.getHeaders(), is); } } return null; }