/** * Send the file as an attachment * * @param file * @throws MessagingException * @throws IOException */ public static final void addFileAsAttachment(final File file, final String filename, final NormalizedMessage message) throws MessagingException, IOException { final DataHandler attachment = new DataHandler(file.toURI().toURL()); message.addAttachment(filename, attachment); }
/** * Convert SoapMessage attachments to NormalizedMessage attachments */ private void toNMSAttachments(NormalizedMessage normalizedMessage, Message soapMessage) throws MessagingException { for (Map.Entry<String, DataHandler> entry : soapMessage.getAttachments().entrySet()) { normalizedMessage.addAttachment(entry.getKey(), entry.getValue()); } }
/** * Copies the attachments from a message to another message * * @param from the message with the attachments * @param to the message to which attachments are added * @throws MessagingException if an attachment could not be added */ public static void copyAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException { for (Iterator iter = from.getAttachmentNames().iterator(); iter .hasNext();) { String name = (String) iter.next(); DataHandler value = from.getAttachment(name); to.addAttachment(name, value); } }
to.addAttachment(contentId, dh); if (logger.isLoggable(Level.FINE)) { try {
outMessage.addAttachment(filename, attachment); retrievedFileName.add(filename); } else {
public static void transfer(NormalizedMessage source, NormalizedMessage dest) throws MessagingException { dest.setContent(source.getContent()); for (Iterator it = source.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.setProperty(name, source.getProperty(name)); } for (Iterator it = source.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.addAttachment(name, source.getAttachment(name)); } dest.setSecuritySubject(source.getSecuritySubject()); }
public static void transfer(NormalizedMessage source, NormalizedMessage dest) throws MessagingException { dest.setContent(source.getContent()); for (Iterator it = source.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.setProperty(name, source.getProperty(name)); } for (Iterator it = source.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.addAttachment(name, source.getAttachment(name)); } dest.setSecuritySubject(source.getSecuritySubject()); }
private static void copyAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException { for (Object name : from.getAttachmentNames()) { DataHandler handler = from.getAttachment((String)name); DataSource source = handler.getDataSource(); if (!(source instanceof ByteArrayDataSource)) { DataSource copy = copyDataSource(source); handler = new DataHandler(copy); } to.addAttachment((String)name, handler); } }
final OMText binaryNode = (OMText) node; final DataHandler dh = (DataHandler) binaryNode.getDataHandler(); to.addAttachment(attachmentId, dh);
/** * Copies attachments from one message to another that do not already exist * * @param from the message with the attachments * @param to the destination message where the attachments are to be added * @throws javax.jbi.messaging.MessagingException if an attachment could not be added */ protected void copyAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException { for (String attachmentName : (Set<String>) from.getAttachmentNames()) { // Do not copy existing attachments if (to.getAttachment(attachmentName) == null) { DataHandler value = from.getAttachment(attachmentName); to.addAttachment(attachmentName, value); } } }
/** * Copies attachments from one message to another that do not already exist * * @param from the message with the attachments * @param to the destination message where the attachments are to be added * @throws javax.jbi.messaging.MessagingException if an attachment could not be added */ protected void copyAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException { for (String attachmentName : (Set<String>) from.getAttachmentNames()) { // Do not copy existing attachments if (to.getAttachment(attachmentName) == null) { DataHandler value = from.getAttachment(attachmentName); to.addAttachment(attachmentName, value); } } } }
public void copyFromCamelToJbi(Message message, NormalizedMessage normalizedMessage) throws MessagingException { if (message != null && message.getBody() != null) { Source body = message.getBody(Source.class); if (body == null) { logger.warn("Unable to convert message body of type {} into an XML Source", message.getBody().getClass()); } else { normalizedMessage.setContent(body); } } Subject securitySubject = getSecuritySubject(message); if (securitySubject != null) { normalizedMessage.setSecuritySubject(securitySubject); } Exchange exchange = message.getExchange(); for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value != null && !strategies.applyFilterToCamelHeaders(key, value, exchange)) { normalizedMessage.setProperty(key, value); } } for (String id : message.getAttachmentNames()) { normalizedMessage.addAttachment(id, message.getAttachment(id)); } }
/** * Convert SoapMessage attachments to NormalizedMessage attachments */ private void toNMSAttachments(NormalizedMessage normalizedMessage, Message soapMessage) throws MessagingException { if (soapMessage.getAttachments() != null) { for (Attachment att : soapMessage.getAttachments()) { normalizedMessage.addAttachment(att.getId(), att .getDataHandler()); } } }
private void toNMSAttachments(NormalizedMessage normalizedMessage, Message soapMessage) throws MessagingException { if (soapMessage.getAttachments() != null) { for (Attachment att : soapMessage.getAttachments()) { normalizedMessage.addAttachment(att.getId(), att .getDataHandler()); } } }
/** * If enabled the properties and attachments are copied to the destination message */ protected void copyPropertiesAndAttachments(NormalizedMessage source, NormalizedMessage dest) throws Exception { if (isCopyProperties()) { for (Iterator it = source.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.setProperty(name, source.getProperty(name)); } } if (isCopyAttachments()) { for (Iterator it = source.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.addAttachment(name, source.getAttachment(name)); } } if (isCopySubject()) { dest.setSecuritySubject(source.getSecuritySubject()); } }
protected MessageExchange createPart(URI pattern, NormalizedMessage srcMessage, Source content) throws Exception { MessageExchange me = getExchangeFactory().createExchange(pattern); NormalizedMessage in = me.createMessage(); in.setContent(content); me.setMessage(in, "in"); if (forwardAttachments) { Set names = srcMessage.getAttachmentNames(); for (Iterator iter = names.iterator(); iter.hasNext();) { String name = (String) iter.next(); in.addAttachment(name, srcMessage.getAttachment(name)); } } if (forwardProperties) { Set names = srcMessage.getPropertyNames(); for (Iterator iter = names.iterator(); iter.hasNext();) { String name = (String) iter.next(); in.setProperty(name, srcMessage.getProperty(name)); } } return me; }
protected void populateMessage(Message message, NormalizedMessage normalizedMessage) throws Exception { if (message instanceof TextMessage) { PhaseInterceptorChain chain = new PhaseInterceptorChain(); chain.add(new AttachmentsInInterceptor()); chain.add(new StaxInInterceptor()); org.apache.servicemix.soap.api.Message msg = new MessageImpl(); msg.setContent(InputStream.class, new ByteArrayInputStream(((TextMessage) message).getText().getBytes())); if (message.propertyExists(CONTENT_TYPE_PROPERTY)) { msg.put(org.apache.servicemix.soap.api.Message.CONTENT_TYPE, message.getStringProperty(CONTENT_TYPE_PROPERTY)); } chain.doIntercept(msg); XMLStreamReader xmlReader = msg.getContent(XMLStreamReader.class); normalizedMessage.setContent(new StaxSource(xmlReader)); for (Map.Entry<String, DataHandler> attachment : msg.getAttachments().entrySet()) { normalizedMessage.addAttachment(attachment.getKey(), attachment.getValue()); } } else { throw new UnsupportedOperationException("JMS message is not a TextMessage"); } }
public void populateMessage(Message message, MessageExchange exchange, NormalizedMessage normalizedMessage) throws Exception { if (message instanceof TextMessage) { PhaseInterceptorChain chain = new PhaseInterceptorChain(); chain.add(new AttachmentsInInterceptor()); chain.add(new StaxInInterceptor()); org.apache.servicemix.soap.api.Message msg = new MessageImpl(); msg.setContent(InputStream.class, new ByteArrayInputStream(((TextMessage) message).getText().getBytes())); if (message.propertyExists(CONTENT_TYPE_PROPERTY)) { msg.put(org.apache.servicemix.soap.api.Message.CONTENT_TYPE, message.getStringProperty(CONTENT_TYPE_PROPERTY)); } chain.doIntercept(msg); XMLStreamReader xmlReader = msg.getContent(XMLStreamReader.class); normalizedMessage.setContent(new StaxSource(xmlReader)); for (Map.Entry<String, DataHandler> attachment : msg.getAttachments().entrySet()) { normalizedMessage.addAttachment(attachment.getKey(), attachment.getValue()); } if (isCopyProperties()) { copyPropertiesFromJMS(message, normalizedMessage); } } else { throw new UnsupportedOperationException("JMS message is not a TextMessage"); } }
Convert.deleteAllAttachments(concrete); for (Object attachmentName : fake.getAttachmentNames()) { concrete.addAttachment((String) attachmentName, fake.getAttachment((String) attachmentName));
Convert.deleteAllAttachments(fake); for (Object attachmentName : concrete.getAttachmentNames()) { fake.addAttachment((String) attachmentName, concrete.getAttachment((String) attachmentName));