private void setQuorumEndpointError(Message message) { message.getExchange().setException(new CamelExchangeException("This is not a Quorum endpoint. Create one by specifying quorumAPI=true", message.getExchange())); } }
protected <D> D getMandatoryHeader(Message message, String header, D defaultValue, Class<D> type) throws Exception { D value = message.getHeader(header, defaultValue, type); if (value == null) { throw new NoSuchHeaderException(message.getExchange(), header, type); } return value; }
private Object getValue(final Message message, final Class<?> type) throws Exception { Object value = message.getHeader(CaffeineConstants.VALUE, type); if (value == null) { value = message.getBody(type); } if (value == null) { throw new CamelExchangeException("No value provided in header or body (" + CaffeineConstants.VALUE + ")", message.getExchange()); } return value; }
private void copyProtocolHeaders(Message request, Message response) { if (request.getHeader(Exchange.CONTENT_ENCODING) != null) { String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING, String.class); response.setHeader(Exchange.CONTENT_ENCODING, contentEncoding); } if (checkChunked(response, response.getExchange())) { response.setHeader(Exchange.TRANSFER_ENCODING, "chunked"); } }
private Object getValue(final Message message, final Class<?> type) throws Exception { Object value = message.getHeader(CaffeineConstants.VALUE, type); if (value == null) { value = message.getBody(type); } if (value == null) { throw new CamelExchangeException("No value provided in header or body (" + CaffeineConstants.VALUE + ")", message.getExchange()); } return value; }
@Override public void process(Exchange exchange) throws Exception { final Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn(); final String id = message.getHeader(IntegrationLoggingConstants.STEP_ID, String.class); if (id != null) { Message copy = message.copy(); Map<String, Message> outMessagesMap = getCapturedMessageMap(exchange); if (copy instanceof MessageSupport && copy.getExchange() == null) { ((MessageSupport) copy).setExchange(message.getExchange()); } outMessagesMap.put(id, copy); } }
/** * Bridge the error condition putting the in the JmsMessage header (At the present only the Exception raised is handled by this method) * * @param exchange * @param value */ public void bridgeError(Exchange exchange, Object value) { // TODO is the in message null check needed? if (exchange.getIn() != null && exchange.getIn().getExchange().getException() != null) { exchange.getIn().setHeader(MessageConstants.HEADER_KAPUA_PROCESSING_EXCEPTION, Base64.getEncoder().encodeToString(SerializationUtils.serialize(exchange.getIn().getExchange().getException()))); } else if (exchange.getException() != null) { exchange.getIn().setHeader(MessageConstants.HEADER_KAPUA_PROCESSING_EXCEPTION, Base64.getEncoder().encodeToString(SerializationUtils.serialize(exchange.getException()))); } else { logger.debug("Cannot serialize exception since it is null!"); } } }
private Object getKey(final Message message) throws Exception { Object value = message.getHeader(CaffeineConstants.KEY, configuration.getKeyType()); if (value == null) { value = configuration.getKey(); } if (value == null) { throw new CamelExchangeException("No value provided in header or as default value (" + CaffeineConstants.KEY + ")", message.getExchange()); } return value; }
private Object getKey(final Message message) throws Exception { Object value = message.getHeader(CaffeineConstants.KEY, configuration.getKeyType()); if (value == null) { value = configuration.getKey(); } if (value == null) { throw new CamelExchangeException("No value provided in header or as default value (" + CaffeineConstants.KEY + ")", message.getExchange()); } return value; }
private Message extractAttachment(Message inMessage, String attachmentName) throws Exception { final Message outMessage = new DefaultMessage(inMessage.getExchange().getContext()); outMessage.setHeader(HEADER_NAME, attachmentName); Object attachment = inMessage.getAttachment(attachmentName).getContent(); if (attachment instanceof InputStream) { outMessage.setBody(readMimePart((InputStream) attachment)); return outMessage; } else if (attachment instanceof String || attachment instanceof byte[]) { outMessage.setBody(attachment); return outMessage; } else { return null; } }
private boolean checkForError(Message message, Response response) { if (response.hasError()) { int code = response.getError().getCode(); String data = response.getError().getData(); String messages = response.getError().getMessage(); message.setHeader(Web3jConstants.ERROR_CODE, code); message.setHeader(Web3jConstants.ERROR_DATA, data); message.setHeader(Web3jConstants.ERROR_MESSAGE, messages); message.getExchange().setException(new CamelExchangeException("Web3j failed. Error code: " + code + " data: " + data + " messages: " + messages, message.getExchange())); return true; } else { return false; } }
public void copyFromCamelToJbi(Message message, NormalizedMessage normalizedMessage) throws MessagingException { if (message != null && message.getBody() != null) { Source body = message.getBody(Source.class); if (body == null) { logger.warn("Unable to convert message body of type {} into an XML Source", message.getBody().getClass()); } else { normalizedMessage.setContent(body); } } Subject securitySubject = getSecuritySubject(message); if (securitySubject != null) { normalizedMessage.setSecuritySubject(securitySubject); } Exchange exchange = message.getExchange(); for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value != null && !strategies.applyFilterToCamelHeaders(key, value, exchange)) { normalizedMessage.setProperty(key, value); } } for (String id : message.getAttachmentNames()) { normalizedMessage.addAttachment(id, message.getAttachment(id)); } }
@Override public Message postProcessMessage(Message msg) throws AmqpException { if(camelMessage == null || camelMessage.getHeaders() == null) return msg; //Set headers msg = SpringAMQPHeader.setBasicPropertiesFromHeaders(msg, camelMessage.getHeaders()); msg = SpringAMQPHeader.copyHeaders(msg, camelMessage.getHeaders()); //Set the exchange pattern so we can re-set it upon receipt if(camelMessage.getExchange() != null) { String exchangePattern = camelMessage.getExchange().getPattern().name(); msg.getMessageProperties().setHeader(EXCHANGE_PATTERN, exchangePattern); } else { throw new IllegalStateException("No exchange was found for this message "+camelMessage.getMessageId()); } return msg; } }
/** * {@inheritDoc} */ @Override public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception { Message sourceMessage = exchange.getMessage(); getContextMapper().mapTo(exchange.getContext(), target); org.apache.camel.Message targetMessage = target.getMessage(); if (!sourceMessage.getAttachmentMap().isEmpty()) { for (Entry<String, DataSource> entry : sourceMessage.getAttachmentMap().entrySet()) { targetMessage.addAttachment(entry.getKey(), new DataHandler(entry.getValue())); } } ServiceOperation operation = exchange.getContract().getProviderOperation(); target.getMessage().getExchange().setProperty(OPERATION_NAME, operation.getName()); target.getMessage().getExchange().setProperty(FAULT_TYPE, operation.getFaultType()); target.getMessage().getExchange().setProperty(SERVICE_NAME, exchange.getProvider().getName()); targetMessage.setBody(sourceMessage.getContent()); return target; } }
@Override public Message postProcessMessage(Message msg) throws AmqpException { if(camelMessage == null || camelMessage.getHeaders() == null) return msg; //Set headers msg = SpringAMQPHeader.setBasicPropertiesFromHeaders(msg, camelMessage.getHeaders()); msg = SpringAMQPHeader.copyHeaders(msg, camelMessage.getHeaders()); //Set the exchange pattern so we can re-set it upon receipt if(camelMessage.getExchange() != null) { String exchangePattern = camelMessage.getExchange().getPattern().name(); msg.getMessageProperties().setHeader(EXCHANGE_PATTERN, exchangePattern); } else { throw new IllegalStateException("No exchange was found for this message "+camelMessage.getMessageId()); } return msg; } }
/** * {@inheritDoc} */ @Override public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception { Message sourceMessage = exchange.getMessage(); getContextMapper().mapTo(exchange.getContext(), target); org.apache.camel.Message targetMessage = target.getMessage(); if (!sourceMessage.getAttachmentMap().isEmpty()) { for (Entry<String, DataSource> entry : sourceMessage.getAttachmentMap().entrySet()) { targetMessage.addAttachment(entry.getKey(), new DataHandler(entry.getValue())); } } ServiceOperation operation = exchange.getContract().getProviderOperation(); target.getMessage().getExchange().setProperty(OPERATION_NAME, operation.getName()); target.getMessage().getExchange().setProperty(FAULT_TYPE, operation.getFaultType()); target.getMessage().getExchange().setProperty(SERVICE_NAME, exchange.getProvider().getName()); targetMessage.setBody(sourceMessage.getContent()); return target; } }
/** * Applies the cells to the {@link org.apache.camel.Exchange}. */ public void applyScanResults(Message message, HBaseData data) { message.setHeaders(message.getExchange().getIn().getHeaders()); int index = 1; if (data == null || data.getRows() == null) { return; } for (HBaseRow hRow : data.getRows()) { Set<HBaseCell> cells = hRow.getCells(); for (HBaseCell cell : cells) { message.setHeader(HBaseAttribute.HBASE_ROW_ID.asHeader(index), hRow.getId()); message.setHeader(HBaseAttribute.HBASE_FAMILY.asHeader(index), cell.getFamily()); message.setHeader(HBaseAttribute.HBASE_QUALIFIER.asHeader(index), cell.getQualifier()); message.setHeader(HBaseAttribute.HBASE_VALUE.asHeader(index), cell.getValue()); } index++; } }
/** * Applies the cells to the {@link org.apache.camel.Exchange}. */ public void applyGetResults(Message message, HBaseData data) { message.setHeaders(message.getExchange().getIn().getHeaders()); int index = 1; if (data == null || data.getRows() == null) { return; } for (HBaseRow hRow : data.getRows()) { if (hRow.getId() != null) { Set<HBaseCell> cells = hRow.getCells(); for (HBaseCell cell : cells) { message.setHeader(HBaseAttribute.HBASE_VALUE.asHeader(index++), getValueForColumn(cells, cell.getFamily(), cell.getQualifier())); } } } }
@Override public void copyFrom(org.apache.camel.Message that) { if (that == this) { // the same instance so do not need to copy return; } if (that instanceof CamelContextAware) { this.setCamelContext(((CamelContextAware) that).getCamelContext()); } // cover over exchange if none has been assigned if (getExchange() == null) { setExchange(that.getExchange()); } setMessageId(that.getMessageId()); setBody(that.getBody()); super.getHeaders().putAll(that.getHeaders()); if (that instanceof SpringIntegrationMessage) { SpringIntegrationMessage orig = (SpringIntegrationMessage) that; setMessage(orig.getMessage()); } getAttachments().putAll(that.getAttachments()); }
public void copyFrom(org.apache.camel.Message that) { // only do a deep copy if we need to (yes when that is not a mail message, or if the mapMailMessage is true) boolean needCopy = !(that instanceof MailMessage) || (((MailMessage) that).mapMailMessage); if (needCopy) { super.copyFrom(that); } else { // no deep copy needed, but copy message id setMessageId(that.getMessageId()); setFault(that.isFault()); } if (that instanceof MailMessage) { MailMessage mailMessage = (MailMessage) that; this.originalMailMessage = mailMessage.originalMailMessage; this.mailMessage = mailMessage.mailMessage; this.mapMailMessage = mailMessage.mapMailMessage; } // cover over exchange if none has been assigned if (getExchange() == null) { setExchange(that.getExchange()); } }