private void checkOriginalMessage(Message camelMessage) throws IllegalStateException { /** * We purposely don't want to support injecting messages half-way through * broker processing - use the activemq camel component for that - but * we will support changing message headers and destinations. */ if (!(camelMessage instanceof JmsMessage)) { throw new IllegalStateException("Not the original message from the broker " + camelMessage); } javax.jms.Message message = ((JmsMessage) camelMessage).getJmsMessage(); if (!(message instanceof ActiveMQMessage)) { throw new IllegalStateException("Not the original message from the broker " + message); } }
@Override public JmsMessage newInstance() { JmsMessage answer = new JmsMessage(null, null, binding); answer.setCamelContext(getCamelContext()); return answer; }
@Override public void copyFrom(org.apache.camel.Message that) { super.copyFrom(that); if (that instanceof JmsMessage && getJmsMessage() == null) { setJmsMessage(((JmsMessage) that).getJmsMessage()); } }
/** * Ensure that the headers have been populated from the underlying JMS message * before we start mutating the headers */ protected void ensureInitialHeaders() { if (jmsMessage != null && !hasPopulatedHeaders()) { // we have not populated headers so force this by creating // new headers and set it on super super.setHeaders(createHeaders()); } }
protected void setMessageId(Exchange exchange) { if (exchange.hasOut()) { JmsMessage out = exchange.getOut(JmsMessage.class); try { if (out != null && out.getJmsMessage() != null) { out.setMessageId(out.getJmsMessage().getJMSMessageID()); } } catch (JMSException e) { LOG.warn("Unable to retrieve JMSMessageID from outgoing JMS Message and set it into Camel's MessageId", e); } } }
getHeaders().clear(); setMessageId(that.getMessageId()); if (getExchange() == null) { setExchange(that.getExchange()); setBody(that.getBody()); setFault(that.isFault()); getHeaders().putAll(that.getHeaders()); getAttachments().clear(); if (that.hasAttachments()) { getAttachmentObjects().putAll(that.getAttachmentObjects());
if (!alwaysCopy && camelMessage instanceof JmsMessage) { JmsMessage jmsMessage = (JmsMessage)camelMessage; if (!jmsMessage.shouldCreateNewMessage() || force) { answer = jmsMessage.getJmsMessage();
public Exchange createExchange(Message message, Session session) { Exchange exchange = createExchange(getExchangePattern()); exchange.setIn(new JmsMessage(message, session, getBinding())); return exchange; }
Message message = holder.getMessage(); Session session = holder.getSession(); JmsMessage response = new JmsMessage(message, session, endpoint.getBinding()); Object body = response.getBody(); Object faultHeader = response.removeHeader(JmsConstants.JMS_TRANSFER_FAULT); if (faultHeader != null) { boolean isFault = exchange.getContext().getTypeConverter().tryConvertTo(boolean.class, faultHeader);
@Override public void setBody(Object body) { super.setBody(body); if (body == null) { // preserver headers even if we set body to null ensureInitialHeaders(); // remove underlying jmsMessage since we mutated body to null jmsMessage = null; } }
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { CamelDestination camelDestination = null; if (ObjectHelper.equal(destination, this.destination)) { camelDestination = this.destination; } else { // TODO support any CamelDestination? throw new IllegalArgumentException("Invalid destination setting: " + destination + " when expected: " + this.destination); } try { Exchange exchange = endpoint.createExchange(ExchangePattern.InOnly); exchange.setIn(new JmsMessage(message, camelDestination.getBinding())); producer.process(exchange); } catch (JMSException e) { throw e; } catch (Exception e) { throw JMSExceptionSupport.create(e); } }
public Object getHeader(String name) { ensureInitialHeaders(); return super.getHeader(name); }
private void checkOriginalMessage(Message camelMessage) throws IllegalStateException { /** * We purposely don't want to support injecting messages half-way through * broker processing - use the activemq camel component for that - but * we will support changing message headers and destinations. */ if (!(camelMessage instanceof JmsMessage)) { throw new IllegalStateException("Not the original message from the broker " + camelMessage); } javax.jms.Message message = ((JmsMessage) camelMessage).getJmsMessage(); if (!(message instanceof ActiveMQMessage)) { throw new IllegalStateException("Not the original message from the broker " + message); } }
@Override public void copyFrom(org.apache.camel.Message that) { super.copyFrom(that); if (that instanceof JmsMessage && getJmsMessage() == null) { setJmsMessage(((JmsMessage) that).getJmsMessage()); } }
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { CamelDestination camelDestination = null; if (ObjectHelper.equal(destination, this.destination)) { camelDestination = this.destination; } else { // TODO support any CamelDestination? throw new IllegalArgumentException("Invalid destination setting: " + destination + " when expected: " + this.destination); } try { Exchange exchange = endpoint.createExchange(ExchangePattern.InOnly); exchange.setIn(new JmsMessage(message, camelDestination.getBinding())); producer.process(exchange); } catch (JMSException e) { throw e; } catch (Exception e) { throw JMSExceptionSupport.create(e); } }
@Override public void setHeader(String name, Object value) { ensureInitialHeaders(); super.setHeader(name, value); }
/** * Convert incoming message to a javax.jms.Message * * @param exchange * @param value * @return jms Message * @throws KapuaException if incoming message does not contain a javax.jms.BytesMessage */ @Converter public Message convertToJmsMessage(Exchange exchange, Object value) throws KapuaException { metricConverterJmsMessage.inc(); // assume that the message is a Camel Jms message JmsMessage message = exchange.getIn(JmsMessage.class); if (message.getJmsMessage() instanceof BytesMessage) { return message.getJmsMessage(); } metricConverterJmsErrorMessage.inc(); throw KapuaException.internalError("Cannot convert the message - Wrong instance type: " + exchange.getIn().getClass()); }
@Override public void copyFrom(org.apache.camel.Message that) { super.copyFrom(that); if (that instanceof JmsMessage) { JmsMessage thatJmsMessage = (JmsMessage) that; if (getJmsMessage() == null) { setJmsMessage(thatJmsMessage.getJmsMessage()); } } if (that instanceof ControllerJmsMessage) { ControllerJmsMessage thatControllerJmsMessage = (ControllerJmsMessage) that; if (getMessageRouter() == null) { setMessageRouter(thatControllerJmsMessage.getMessageRouter()); } } }
public Exchange createExchange(Message message, Session session, Object replyDestination) { Exchange exchange = endpoint.createExchange(); JmsBinding binding = getBinding(); exchange.setProperty(Exchange.BINDING, binding); exchange.setIn(new JmsMessage(message, session, binding)); // lets set to an InOut if we have some kind of reply-to destination if (replyDestination != null && !disableReplyTo) { // only change pattern if not already out capable if (!exchange.getPattern().isOutCapable()) { exchange.setPattern(ExchangePattern.InOut); } } return exchange; }
@Override public Map<String, Object> getHeaders() { ensureInitialHeaders(); return super.getHeaders(); }