/** * Delete all the attachments. * @param nm * the normalized message * @throws MessagingException * impossible to delete the message */ private static void deleteAllAttachments(final NormalizedMessage nm) throws MessagingException { // Delete all attachments if (nm.getAttachmentNames() != null) { for (Object attachmentName : nm.getAttachmentNames()) { nm.removeAttachment((String) attachmentName); } } }
/** * Copy NormalizedMessage attachments to SoapMessage attachments */ private void fromNMSAttachments(Message message, NormalizedMessage normalizedMessage) { Set attachmentNames = normalizedMessage.getAttachmentNames(); for (Iterator it = attachmentNames.iterator(); it.hasNext();) { String id = (String) it.next(); DataHandler handler = normalizedMessage.getAttachment(id); message.getAttachments().put(id, handler); } }
/** * 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); } }
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()); }
if (message.getAttachmentNames().size() > 0) { sb.append(" attachments: [").append('\n'); for (String key : (Set<String>) message.getAttachmentNames()) { sb.append(" ").append(key).append(" = ").append(message.getAttachment(key)).append('\n');
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); } }
this.log.fine("set the email attachments"); NormalizedMessage in = exchange.getInMessage(); final Set<String> attachmentIds = in.getAttachmentNames(); MimeBodyPart attachementBodyPart = null; DataHandler handler = null;
/** * 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); } } } }
/** * Copies content, headers, security subject and attachments from the JBI NormalizedMessage to the Camel Message. * * @param from the source {@link NormalizedMessage} * @param to the target {@link Message} */ public void copyFromJbiToCamel(NormalizedMessage from, Message to) { to.setBody(from.getContent()); Subject securitySubject = from.getSecuritySubject(); if (securitySubject != null) { to.setHeader(SECURITY_SUBJECT, securitySubject); } Exchange exchange = to.getExchange(); for (Object object : from.getPropertyNames()) { String key = object.toString(); Object value = from.getProperty(key); if (!strategies.applyFilterToCamelHeaders(key, value, exchange)) { to.setHeader(key, value); } } for (Object id : from.getAttachmentNames()) { to.addAttachment(id.toString(), from.getAttachment(id.toString())); } }
public NormalizedMessageImpl(NormalizedMessage message) throws MessagingException { try { DOMSource domSource = (DOMSource)sourceTransformer.toDOMSource(message); if (domSource != null) { this.content = domSource; } for (Iterator it = message.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); this.properties.put(name, message.getProperty(name)); } for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); DataHandler dh = message.getAttachment(name); DataSource ds = dh.getDataSource(); if (!(ds instanceof ByteArrayDataSource)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copyInputStream(ds.getInputStream(), baos); ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType()); bads.setName(ds.getName()); dh = new DataHandler(bads); } this.attachments.put(name, dh); } this.subject = message.getSecuritySubject(); } catch (MessagingException e) { throw e; } catch (Exception e) { throw new MessagingException(e); } }
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; }
/** * 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()); } }
/** * Copy NormalizedMessage attachments to SoapMessage attachments */ private void fromNMSAttachments(Message message, NormalizedMessage normalizedMessage) { Set attachmentNames = normalizedMessage.getAttachmentNames(); Collection<Attachment> attachmentList = new ArrayList<Attachment>(); for (Iterator it = attachmentNames.iterator(); it.hasNext();) { String id = (String) it.next(); DataHandler handler = normalizedMessage.getAttachment(id); Attachment attachment = new AttachmentImpl(id, handler); attachmentList.add(attachment); } message.setAttachments(attachmentList); if (message instanceof SoapMessage) { SoapMessage soapMessage = (SoapMessage)message; SoapVersion soapVersion = soapMessage.getVersion(); message.put(Message.CONTENT_TYPE, soapVersion.getContentType()); } if (attachmentList.size() > 0) { message.put(org.apache.cxf.message.Message.MTOM_ENABLED, true); message.put("write.attachments", true); message.getInterceptorChain().add(new AttachmentOutInterceptor()); } }
public NormalizedMessageImpl(NormalizedMessage message) throws MessagingException { try { String str = new SourceTransformer().contentToString(message); if (str != null) { this.content = new StringSource(str); } for (Iterator it = message.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); this.properties.put(name, message.getProperty(name)); } for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); DataHandler dh = message.getAttachment(name); DataSource ds = dh.getDataSource(); if (!(ds instanceof ByteArrayDataSource)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileUtil.copyInputStream(ds.getInputStream(), baos); ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType()); bads.setName(ds.getName()); dh = new DataHandler(bads); } this.attachments.put(name, dh); } this.subject = message.getSecuritySubject(); } catch (MessagingException e) { throw e; } catch (Exception e) { throw new MessagingException(e); } }
public void handleMessage(Message message) { List<Attachment> attachmentList = new ArrayList<Attachment>(); MessageExchange exchange = message.get(MessageExchange.class); NormalizedMessage norMessage = null; if (isRequestor(message)) { norMessage = (NormalizedMessage) exchange.getMessage("out"); } else { norMessage = (NormalizedMessage) exchange.getMessage("in"); } if (norMessage == null) { norMessage = (NormalizedMessage) exchange.getFault(); } if (norMessage ==null) { return; } Set names = norMessage.getAttachmentNames(); for (Object obj : names) { String id = (String)obj; DataHandler dh = norMessage.getAttachment(id); attachmentList.add(new AttachmentImpl(id, dh)); } message.setAttachments(attachmentList); }
public Message createMessage(MessageExchange exchange, NormalizedMessage in, Session session) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PhaseInterceptorChain chain = new PhaseInterceptorChain(); chain.add(new AttachmentsOutInterceptor()); chain.add(new StaxOutInterceptor()); chain.add(new BodyOutInterceptor()); org.apache.servicemix.soap.api.Message msg = new MessageImpl(); msg.setContent(Source.class, in.getContent()); msg.setContent(OutputStream.class, baos); for (String attId : (Set<String>) in.getAttachmentNames()) { msg. getAttachments().put(attId, in.getAttachment(attId)); } chain.doIntercept(msg); TextMessage text = session.createTextMessage(baos.toString()); if (msg.get(org.apache.servicemix.soap.api.Message.CONTENT_TYPE) != null) { text.setStringProperty(CONTENT_TYPE_PROPERTY, (String) msg.get(org.apache.servicemix.soap.api.Message.CONTENT_TYPE)); } if (jmsProperties != null) { for (Map.Entry<String, Object> e : jmsProperties.entrySet()) { text.setObjectProperty(e.getKey(), e.getValue()); } } if (isCopyProperties()) { copyPropertiesFromNM(in, text); } return text; }
public Message createOut(MessageExchange exchange, NormalizedMessage outMsg, Session session, JmsContext context) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PhaseInterceptorChain chain = new PhaseInterceptorChain(); chain.add(new AttachmentsOutInterceptor()); chain.add(new StaxOutInterceptor()); chain.add(new BodyOutInterceptor()); org.apache.servicemix.soap.api.Message msg = new MessageImpl(); msg.setContent(Source.class, outMsg.getContent()); msg.setContent(OutputStream.class, baos); for (String attId : (Set<String>) outMsg.getAttachmentNames()) { msg. getAttachments().put(attId, outMsg.getAttachment(attId)); } chain.doIntercept(msg); TextMessage text = session.createTextMessage(baos.toString()); if (msg.get(org.apache.servicemix.soap.api.Message.CONTENT_TYPE) != null) { text.setStringProperty(CONTENT_TYPE_PROPERTY, (String) msg.get(org.apache.servicemix.soap.api.Message.CONTENT_TYPE)); } if (isCopyProperties()) { copyPropertiesFromNM(outMsg, text); } return text; }
if (concrete.getAttachmentNames() != null) { Convert.deleteAllAttachments(fake); for (Object attachmentName : concrete.getAttachmentNames()) { fake.addAttachment((String) attachmentName, concrete.getAttachment((String) attachmentName));