/* * @see javax.jms.MessageListener#onMessage(javax.jms.Message) * * @param message */ @Override public void onMessage(Message message) { RuntimeCamelException rce = null; try { final DefaultExchange exchange = (DefaultExchange) JmsMessageHelper.createExchange(message, getEndpoint()); log.debug("Processing Exchange.id:{}", exchange.getExchangeId()); if (isTransacted() && synchronization != null) { exchange.addOnCompletion(synchronization); } try { if (isTransacted() || isSynchronous()) { log.debug(" Handling synchronous message: {}", exchange.getIn().getBody()); handleMessage(exchange); } else { log.debug(" Handling asynchronous message: {}", exchange.getIn().getBody()); executor.execute( new Runnable() { @Override public void run() { try { handleMessage(exchange); } catch (Exception e) { exchange.setException(e); } } }); } } catch (Exception e) { if (exchange != null) { if (exchange.getException() == null) { exchange.setException(e); } else { throw e; } } } } catch (Exception e) { rce = wrapRuntimeCamelException(e); } finally { if (rce != null) { throw rce; } } }
public Exchange copy(boolean safeCopy) { DefaultExchange exchange = new DefaultExchange(this); if (hasProperties()) { exchange.setProperties(safeCopyProperties(getProperties())); } if (safeCopy) { exchange.getIn().setBody(getIn().getBody()); if (getIn().hasHeaders()) { exchange.getIn().setHeaders(safeCopyHeaders(getIn().getHeaders())); // just copy the attachments here exchange.getIn().copyAttachments(getIn()); } if (hasOut()) { exchange.getOut().setBody(getOut().getBody()); if (getOut().hasHeaders()) { exchange.getOut().setHeaders(safeCopyHeaders(getOut().getHeaders())); } // Just copy the attachments here exchange.getOut().copyAttachments(getOut()); } } else { // old way of doing copy which is @deprecated // TODO: remove this in Camel 3.0, and always do a safe copy exchange.setIn(getIn().copy()); if (hasOut()) { exchange.setOut(getOut().copy()); } } exchange.setException(getException()); return exchange; }