protected void addMessagePropertiesToDocument(NormalizedMessage nm, Document document, String type) throws MessagingException { Set propertyNames = nm.getPropertyNames(); for (Iterator iter = propertyNames.iterator(); iter.hasNext();) { String propertyName = (String) iter.next(); Object value = nm.getProperty(propertyName); if (value instanceof String) { //org.apache.servicemix.out.myproperty document.add(Field.Keyword("org.apache.servicemix." + type + "." + propertyName, String.valueOf(value))); } } }
/** * Copies all of the properties from one message to another * * @param from the message containing the properties * @param to the destination messages where the properties are set */ public static void copyProperties(NormalizedMessage from, NormalizedMessage to) { for (Iterator iter = from.getPropertyNames().iterator(); iter.hasNext();) { String name = (String) iter.next(); // Do not copy transient properties if (!PojoMarshaler.BODY.equals(name)) { Object value = from.getProperty(name); to.setProperty(name, value); } } }
private static void copyProperties(NormalizedMessage from, NormalizedMessage to) { for (Object name : from.getPropertyNames()) { to.setProperty((String)name, from.getProperty((String)name)); } }
/** * <p> * Copy properties from the JBI message exchange normalized message into the * JMS message. * </p> * * @param normalizedMessage * The JBI message exchange normalized message from which the * properties are extracted. * @param jmsMessage * The JMS message in which the properties are set. * @throws JMSException */ private void setMessageProperties(final Message jmsMessage, final NormalizedMessage normalizedMessage) throws JMSException { for (final Iterator<?> it = normalizedMessage.getPropertyNames().iterator(); it.hasNext();) { final String propertyName = (String) it.next(); final Object propertyValue = normalizedMessage.getProperty(propertyName); jmsMessage.setObjectProperty(propertyName, propertyValue); } } }
/** * A hook to allow the transformer to be configured from the current * exchange and inbound message */ protected void configureTransformer(Transformer transformer, MessageExchange exchange, NormalizedMessage in) { for (Iterator iter = exchange.getPropertyNames().iterator(); iter.hasNext();) { String name = (String) iter.next(); Object value = exchange.getProperty(name); transformer.setParameter(name, value); } for (Iterator iter = in.getPropertyNames().iterator(); iter.hasNext();) { String name = (String) iter.next(); Object value = in.getProperty(name); transformer.setParameter(name, value); } Map parameters = getParameters(); if (parameters != null) { for (Iterator iter = parameters.keySet().iterator(); iter.hasNext();) { String name = (String) iter.next(); Object value = parameters.get(name); transformer.setParameter(name, value); } } transformer.setParameter("exchange", exchange); transformer.setParameter("in", in); transformer.setParameter("component", this); }
/** * Transfer message properties from the JBI message exchange to the ODE message exchange object. * * @param odeMex destination ODE message-exchange * @param jbiMex source JBI message-exchange */ @SuppressWarnings("unchecked") protected void copyMexProperties(MyRoleMessageExchange odeMex, javax.jbi.messaging.MessageExchange jbiMex) { __log.debug(odeMex + ": mmex copyProperties"); NormalizedMessage in = jbiMex.getMessage("in"); for (String propName : (Set<String>) in.getPropertyNames()) { Object val = in.getProperty(propName); if (propName.startsWith("org.apache.ode") ) { // Handle ODE-specific properties if (val != null) { String sval = val.toString(); odeMex.setProperty(propName, sval); __log.debug(odeMex + ": set mmex property " + propName + " = " + sval); } } else { // Non ODE-specific properties, // TODO: Should we copy these? __log.debug(odeMex + ": other mmex property " + propName + " = " + val); } } } }
/** * Copies properties from one message to another that do not already exist * * @param from the message containing the properties * @param to the destination message where the properties are set */ protected void copyProperties(NormalizedMessage from, NormalizedMessage to) { for (String propertyName : (Set<String>) from.getPropertyNames()) { // Do not copy existing properties or transient properties if (to.getProperty(propertyName) == null && !PojoMarshaler.BODY.equals(propertyName)) { Object value = from.getProperty(propertyName); to.setProperty(propertyName, value); } } }
/** * Copies properties from one message to another that do not already exist * * @param from the message containing the properties * @param to the destination message where the properties are set */ protected void copyProperties(NormalizedMessage from, NormalizedMessage to) { for (String propertyName : (Set<String>) from.getPropertyNames()) { // Do not copy existing properties or transient properties if (to.getProperty(propertyName) == null && !PojoMarshaler.BODY.equals(propertyName)) { Object value = from.getProperty(propertyName); to.setProperty(propertyName, 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()); }
private void writeNormalizedMessage(NormalizedMessage message) { for (Object key : message.getPropertyNames()) { writeProperty(key, message.getProperty(key.toString())); } println(); println("- content -"); }
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()); }
/** * Outputs the properties on the {@link NormalizedMessage}. Properties of * type {@link Source} are transformed to a {@link String} before * being output. * * @param message The {@link NormalizedMessage} to be processed */ @SuppressWarnings("unchecked") protected void outputProperties(NormalizedMessage message) { // Loop over all the properties on the normalized message for (Object o : message.getPropertyNames()) { // NormalizedMessage API does not use generics. This interface is // written in Java older than 5.0. On the basis of other methods and // the default implementation of this interface we can assume that // only String keys are allowed. String key = (String) o; try { Object contents = message.getProperty(key); // Is this the only value type that we would like to treat // differently? The default behavior is to invoke toString() on // the object. if (contents instanceof Source) { contents = getSourceTransformer().toString((Source) contents); } LOGGER.info("Value for property '{}' is: {}", key, contents); } catch (TransformerException e) { LOGGER.error("Failed to turn property '{}' value into text", key, e); } } }
/** * A utility method to copy properties from the input of the original * exchange to the output of the original exchange. * * @param exchange * @param srcMessage * @param @dstMessage * @throws Exception */ private void copyExchangeProperties(MessageExchange exchange, String srcMessage, String dstMessage) { NormalizedMessage src = exchange.getMessage(srcMessage); NormalizedMessage dst = exchange.getMessage(dstMessage); for (Iterator iter = src.getPropertyNames().iterator(); iter.hasNext();) { String name = (String) iter.next(); if (dst.getProperty(name) == null) { Object prop = src.getProperty(name); dst.setProperty(name, prop); } } }
protected void configureQuery(DynamicQueryContext dynamicEnv, MessageExchange exchange, NormalizedMessage in) throws Exception { for (Iterator iter = exchange.getPropertyNames().iterator(); iter.hasNext();) { String name = (String) iter.next(); Object value = exchange.getProperty(name); dynamicEnv.setParameter(name, value); } for (Iterator iter = in.getPropertyNames().iterator(); iter.hasNext();) { String name = (String) iter.next(); Object value = in.getProperty(name); dynamicEnv.setParameter(name, value); } Map parameters = getParameters(); if (parameters != null) { for (Iterator iter = parameters.keySet().iterator(); iter.hasNext();) { String name = (String) iter.next(); Object value = parameters.get(name); dynamicEnv.setParameter(name, value); } } dynamicEnv.setParameter("exchange", exchange); dynamicEnv.setParameter("in", in); dynamicEnv.setParameter("component", this); }
/** * 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())); } }
/** * 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()); } }
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; }
/** * Copy properties from JBI message to JMS message. * * @param outMessage Received JBI message. * @param message Created JMS message. * @throws JMSException If there is any problems with saving JMS message * properties. */ @SuppressWarnings("unchecked") protected void copyPropertiesFromNM(NormalizedMessage outMessage, Message message) throws JMSException { Set<String> names = outMessage.getPropertyNames(); for (String name : names) { Object value = outMessage.getProperty(name); if (!isBlackListed(name)) { if (shouldIncludeHeader(name, value)) { message.setObjectProperty(name, value); } } } }
Set normalizedMessageProps = nm.getPropertyNames(); for (Object name : normalizedMessageProps) { inMessage.put((String)name, nm.getProperty((String)name));