use of org.apache.camel.component.jms.JmsMessageType.Object in project camel by apache.
the class JmsBinding method createMapFromMapMessage.
/**
* Extracts a {@link Map} from a {@link MapMessage}
*/
public Map<String, Object> createMapFromMapMessage(MapMessage message) throws JMSException {
Map<String, Object> answer = new HashMap<String, Object>();
Enumeration<?> names = message.getMapNames();
while (names.hasMoreElements()) {
String name = names.nextElement().toString();
Object value = message.getObject(name);
answer.put(name, value);
}
return answer;
}
use of org.apache.camel.component.jms.JmsMessageType.Object in project camel by apache.
the class JmsBinding method getObjectProperty.
public Object getObjectProperty(Message jmsMessage, String name) throws JMSException {
// try a direct lookup first
Object answer = jmsMessage.getObjectProperty(name);
if (answer == null) {
// then encode the key and do another lookup
String key = jmsKeyFormatStrategy.encodeKey(name);
answer = jmsMessage.getObjectProperty(key);
}
return answer;
}
use of org.apache.camel.component.jms.JmsMessageType.Object in project camel by apache.
the class JmsBinding method appendJmsProperties.
/**
* Appends the JMS headers from the Camel {@link JmsMessage}
*/
public void appendJmsProperties(Message jmsMessage, Exchange exchange, org.apache.camel.Message in) throws JMSException {
Set<Map.Entry<String, Object>> entries = in.getHeaders().entrySet();
for (Map.Entry<String, Object> entry : entries) {
String headerName = entry.getKey();
Object headerValue = entry.getValue();
appendJmsProperty(jmsMessage, exchange, in, headerName, headerValue);
}
}
use of org.apache.camel.component.jms.JmsMessageType.Object in project camel by apache.
the class JmsBinding method extractHeadersFromJms.
public Map<String, Object> extractHeadersFromJms(Message jmsMessage, Exchange exchange) {
Map<String, Object> map = new HashMap<String, Object>();
if (jmsMessage != null) {
// lets populate the standard JMS message headers
try {
map.put("JMSCorrelationID", jmsMessage.getJMSCorrelationID());
map.put("JMSCorrelationIDAsBytes", JmsMessageHelper.getJMSCorrelationIDAsBytes(jmsMessage));
map.put("JMSDeliveryMode", jmsMessage.getJMSDeliveryMode());
map.put("JMSDestination", jmsMessage.getJMSDestination());
map.put("JMSExpiration", jmsMessage.getJMSExpiration());
map.put("JMSMessageID", jmsMessage.getJMSMessageID());
map.put("JMSPriority", jmsMessage.getJMSPriority());
map.put("JMSRedelivered", jmsMessage.getJMSRedelivered());
map.put("JMSTimestamp", jmsMessage.getJMSTimestamp());
map.put("JMSReplyTo", JmsMessageHelper.getJMSReplyTo(jmsMessage));
map.put("JMSType", JmsMessageHelper.getJMSType(jmsMessage));
// this works around a bug in the ActiveMQ property handling
map.put(JMS_X_GROUP_ID, JmsMessageHelper.getStringProperty(jmsMessage, JMS_X_GROUP_ID));
map.put("JMSXUserID", JmsMessageHelper.getStringProperty(jmsMessage, "JMSXUserID"));
} catch (JMSException e) {
throw new RuntimeCamelException(e);
}
Enumeration<?> names;
try {
names = jmsMessage.getPropertyNames();
} catch (JMSException e) {
throw new RuntimeCamelException(e);
}
while (names.hasMoreElements()) {
String name = names.nextElement().toString();
try {
Object value = JmsMessageHelper.getProperty(jmsMessage, name);
if (headerFilterStrategy != null && headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange)) {
continue;
}
// must decode back from safe JMS header name to original header name
// when storing on this Camel JmsMessage object.
String key = jmsKeyFormatStrategy.decodeKey(name);
map.put(key, value);
} catch (JMSException e) {
throw new RuntimeCamelException(name, e);
}
}
}
return map;
}
use of org.apache.camel.component.jms.JmsMessageType.Object in project camel by apache.
the class JmsBinding method extractBodyFromJms.
/**
* Extracts the body from the JMS message
*
* @param exchange the exchange
* @param message the message to extract its body
* @return the body, can be <tt>null</tt>
*/
public Object extractBodyFromJms(Exchange exchange, Message message) {
try {
// based on message type
if (endpoint != null && endpoint.getMessageConverter() != null) {
if (LOG.isTraceEnabled()) {
LOG.trace("Extracting body using a custom MessageConverter: {} from JMS message: {}", endpoint.getMessageConverter(), message);
}
return endpoint.getMessageConverter().fromMessage(message);
}
// if we are configured to not map the jms message then return it as body
if (endpoint != null && !endpoint.getConfiguration().isMapJmsMessage()) {
LOG.trace("Option map JMS message is false so using JMS message as body: {}", message);
return message;
}
if (message instanceof ObjectMessage) {
LOG.trace("Extracting body as a ObjectMessage from JMS message: {}", message);
ObjectMessage objectMessage = (ObjectMessage) message;
Object payload = objectMessage.getObject();
if (payload instanceof DefaultExchangeHolder) {
DefaultExchangeHolder holder = (DefaultExchangeHolder) payload;
DefaultExchangeHolder.unmarshal(exchange, holder);
return exchange.getIn().getBody();
} else {
return objectMessage.getObject();
}
} else if (message instanceof TextMessage) {
LOG.trace("Extracting body as a TextMessage from JMS message: {}", message);
TextMessage textMessage = (TextMessage) message;
return textMessage.getText();
} else if (message instanceof MapMessage) {
LOG.trace("Extracting body as a MapMessage from JMS message: {}", message);
return createMapFromMapMessage((MapMessage) message);
} else if (message instanceof BytesMessage) {
LOG.trace("Extracting body as a BytesMessage from JMS message: {}", message);
return createByteArrayFromBytesMessage((BytesMessage) message);
} else if (message instanceof StreamMessage) {
LOG.trace("Extracting body as a StreamMessage from JMS message: {}", message);
return message;
} else {
return null;
}
} catch (JMSException e) {
throw new RuntimeCamelException("Failed to extract body due to: " + e + ". Message: " + message, e);
}
}
Aggregations