Refine search
if (a.getId().startsWith(start)) { DataHandler dh = a.getDataHandler(); String ct = dh.getContentType(); Object o = null; Class<?> typeClass = mpi.getTypeClass(); try { o = dh.getContent(); } catch (IOException e) { throw new Fault(e); o = IOUtils.readBytesFromStream(dh.getInputStream()); } catch (IOException e) { throw new Fault(e);
if (writingHeaders) { writingHeaders = false; current = att.getDataHandler().getInputStream(); } else if (atts.hasNext()) { att = atts.next(); writer.append("\r\n"); writer.append("--").append(boundary).append("\r\n"); Iterator<String> heads = att.getHeaderNames(); while (heads.hasNext()) { String s = heads.next(); writer.append(s).append(": ").append(att.getHeader(s)).append("\r\n");
public boolean add(Attachment e) { if (!attachments.containsKey(e.getId())) { attachments.put(e.getId(), e.getDataHandler()); cache.put(e.getId(), e); return true; } return false; }
public static Attachment getAttachment(String id, Collection<Attachment> attachments) { if (id == null) { throw new DatabindingException("Cannot get attachment: null id"); } int i = id.indexOf("cid:"); if (i != -1) { id = id.substring(4).trim(); } if (attachments == null) { return null; } for (Iterator<Attachment> iter = attachments.iterator(); iter.hasNext();) { Attachment a = iter.next(); if (a.getId().equals(id)) { return a; } } // Try loading the URL remotely try { URLDataSource source = new URLDataSource(new URL(id)); return new AttachmentImpl(id, new DataHandler(source)); } catch (MalformedURLException e) { return null; } } }
Iterator<String> it = a.getHeaderNames(); if (it.hasNext()) { headers = new LinkedHashMap<String, List<String>>(); while (it.hasNext()) { String key = it.next(); headers.put(key, Collections.singletonList(a.getHeader(key))); DataHandler handler = a.getDataHandler(); handler.setCommandMap(AttachmentUtil.getCommandMap()); writeHeaders(handler.getContentType(), a.getId(), headers, writer); out.write(writer.getBuffer().toString().getBytes(encoding)); handler.writeTo(out);
org.apache.cxf.message.Attachment attachment = iterator.next(); if (attachmentId != null && !attachmentId.equals(attachment.getId())) { continue; att.setMimeType(attachment.getDataHandler().getContentType()); att.setId(attachment.getId()); att.setSourceStream(attachment.getDataHandler().getInputStream()); Iterator<String> headerIterator = attachment.getHeaderNames(); while (headerIterator.hasNext()) { String next = headerIterator.next(); att.addHeader(next, attachment.getHeader(next));
@Override protected Object readAttachment(Attachment att, Context context) throws IOException { DataHandler handler = att.getDataHandler(); InputStream is = handler.getInputStream(); // try // { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(is, out); is.close(); return out.toByteArray(); }
if (atts != null) { for (Attachment a : atts) { if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) { try { ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(inMessage); } catch (IOException e) { throw new Fault(e);
private SoapAttachment getSoapAttachment(Attachment attachment) { DataHandler dataHandler = attachment.getDataHandler(); try { MediaType contentType = MediaType.parse(dataHandler.getContentType()); return new SoapAttachment(dataHandler.getInputStream(), contentType); } catch (IOException e) { throw new SoapFault("Error copying received attachment [" + getName(attachment) + "]", e, FAULT_CODE_SERVER); } } }
public Attachment(org.apache.cxf.message.Attachment a, Providers providers) { handler = a.getDataHandler(); for (Iterator<String> i = a.getHeaderNames(); i.hasNext();) { String name = i.next(); if ("Content-ID".equalsIgnoreCase(name)) { continue; } headers.add(name, a.getHeader(name)); } headers.putSingle("Content-ID", a.getId()); this.providers = providers; }
public static String getAttachmentPartHeader(Attachment att) { StringBuilder buffer = new StringBuilder(200); buffer.append(HttpHeaderHelper.getHeaderKey(HttpHeaderHelper.CONTENT_TYPE) + ": " + att.getDataHandler().getContentType() + ";\r\n"); if (att.isXOP()) { buffer.append("Content-Transfer-Encoding: binary\r\n"); } String id = att.getId(); if (id.charAt(0) == '<') { id = id.substring(1, id.length() - 1); } buffer.append("Content-ID: <" + id + ">\r\n\r\n"); return buffer.toString(); }
private synchronized void load() { if (dataSource == null) { for (Attachment a : attachments) { if (a.getId().equals(id)) { this.dataSource = a.getDataHandler().getDataSource(); break; } } } if (dataSource == null) { //couldn't find it, build up error message List<String> ids = new ArrayList<>(10); for (Attachment a : attachments) { ids.add(a.getId()); if (a.getId().equals(id)) { this.dataSource = a.getDataHandler().getDataSource(); if (dataSource != null) { ids = null; break; } throw new IllegalStateException("Could not get DataSource for " + "attachment of id " + id); } } if (ids != null) { throw new IllegalStateException("No attachment for " + " id " + id + " found in " + ids); } } }
private String getName(Attachment attachment) { DataHandler dataHandler = attachment.getDataHandler(); return dataHandler.getName() != null ? dataHandler.getName() : attachment.getId(); }
public boolean contains(Object o) { if (o instanceof Attachment) { return attachments.containsKey(((Attachment) o).getId()); } return false; }
@Override protected Object readAttachment(Attachment att, Context context) { return att.getDataHandler(); }
private DefaultAttachment createCamelAttachment(Attachment attachment) { DefaultAttachment camelAttachment = new DefaultAttachment(attachment.getDataHandler()); Iterator<String> headers = attachment.getHeaderNames(); while (headers.hasNext()) { String name = headers.next(); camelAttachment.addHeader(name, attachment.getHeader(name)); } return camelAttachment; }
@Consumes({MediaType.MULTIPART_FORM_DATA,"multipart/mixed" }) public Response uploadImages(final List<Attachment> attachments) { Map<String, InputStream> imageMap = new HashMap<String, InputStream>(); for (Attachment attachment : attachments) { String imageName = attachment.getContentDisposition().getParameter("filename"); if (imageName == null) { imageName = UUID.randomUUID().toString(); } InputStream image = attachment.getDataHandler().getInputStream(); imageMap.put(imageName, image); } return imageMap; }
public static Attachment getAttachment(String id, Collection<Attachment> attachments) { if (id == null) { throw new DatabindingException("Cannot get attachment: null id"); } int i = id.indexOf("cid:"); if (i != -1) { id = id.substring(4).trim(); } if (attachments == null) { return null; } for (Iterator<Attachment> iter = attachments.iterator(); iter.hasNext();) { Attachment a = iter.next(); if (a.getId().equals(id)) { return a; } } // Try loading the URL remotely try { URLDataSource source = new URLDataSource(new URL(id)); return new AttachmentImpl(id, new DataHandler(source)); } catch (MalformedURLException e) { return null; } } }
Iterator<String> it = a.getHeaderNames(); if (it.hasNext()) { headers = new LinkedHashMap<>(); while (it.hasNext()) { String key = it.next(); headers.put(key, Collections.singletonList(a.getHeader(key))); DataHandler handler = a.getDataHandler(); handler.setCommandMap(AttachmentUtil.getCommandMap()); writeHeaders(handler.getContentType(), a.getId(), headers, writer); out.write(writer.getBuffer().toString().getBytes(encoding)); if ("base64".equals(contentTransferEncoding)) { try (InputStream inputStream = handler.getInputStream()) { encodeBase64(inputStream, out, IOUtils.DEFAULT_BUFFER_SIZE);
org.apache.cxf.message.Attachment attachment = iterator.next(); if (attachmentId != null && !attachmentId.equals(attachment.getId())) { continue; att.setMimeType(attachment.getDataHandler().getContentType()); att.setId(attachment.getId()); att.setSourceStream(attachment.getDataHandler().getInputStream()); Iterator<String> headerIterator = attachment.getHeaderNames(); while (headerIterator.hasNext()) { String next = headerIterator.next(); att.addHeader(next, attachment.getHeader(next));