org.apache.camel.Message.getExchange()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(249)

本文整理了Java中org.apache.camel.Message.getExchange()方法的一些代码示例,展示了Message.getExchange()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getExchange()方法的具体详情如下:
包路径:org.apache.camel.Message
类名称:Message
方法名:getExchange

Message.getExchange介绍

暂无

代码示例

代码示例来源:origin: org.apache.camel/camel-web3j

  1. private void setQuorumEndpointError(Message message) {
  2. message.getExchange().setException(new CamelExchangeException("This is not a Quorum endpoint. Create one by specifying quorumAPI=true", message.getExchange()));
  3. }
  4. }

代码示例来源:origin: org.apache.camel/camel-consul

  1. protected <D> D getMandatoryHeader(Message message, String header, D defaultValue, Class<D> type) throws Exception {
  2. D value = message.getHeader(header, defaultValue, type);
  3. if (value == null) {
  4. throw new NoSuchHeaderException(message.getExchange(), header, type);
  5. }
  6. return value;
  7. }

代码示例来源:origin: org.apache.camel/camel-caffeine

  1. private Object getValue(final Message message, final Class<?> type) throws Exception {
  2. Object value = message.getHeader(CaffeineConstants.VALUE, type);
  3. if (value == null) {
  4. value = message.getBody(type);
  5. }
  6. if (value == null) {
  7. throw new CamelExchangeException("No value provided in header or body (" + CaffeineConstants.VALUE + ")", message.getExchange());
  8. }
  9. return value;
  10. }

代码示例来源:origin: org.apache.camel/camel-http-common

  1. private void copyProtocolHeaders(Message request, Message response) {
  2. if (request.getHeader(Exchange.CONTENT_ENCODING) != null) {
  3. String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING, String.class);
  4. response.setHeader(Exchange.CONTENT_ENCODING, contentEncoding);
  5. }
  6. if (checkChunked(response, response.getExchange())) {
  7. response.setHeader(Exchange.TRANSFER_ENCODING, "chunked");
  8. }
  9. }

代码示例来源:origin: org.apache.camel/camel-caffeine

  1. private Object getValue(final Message message, final Class<?> type) throws Exception {
  2. Object value = message.getHeader(CaffeineConstants.VALUE, type);
  3. if (value == null) {
  4. value = message.getBody(type);
  5. }
  6. if (value == null) {
  7. throw new CamelExchangeException("No value provided in header or body (" + CaffeineConstants.VALUE + ")", message.getExchange());
  8. }
  9. return value;
  10. }

代码示例来源:origin: io.syndesis.integration/integration-runtime

  1. @Override
  2. public void process(Exchange exchange) throws Exception {
  3. final Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
  4. final String id = message.getHeader(IntegrationLoggingConstants.STEP_ID, String.class);
  5. if (id != null) {
  6. Message copy = message.copy();
  7. Map<String, Message> outMessagesMap = getCapturedMessageMap(exchange);
  8. if (copy instanceof MessageSupport && copy.getExchange() == null) {
  9. ((MessageSupport) copy).setExchange(message.getExchange());
  10. }
  11. outMessagesMap.put(id, copy);
  12. }
  13. }

代码示例来源:origin: eclipse/kapua

  1. /**
  2. * Bridge the error condition putting the in the JmsMessage header (At the present only the Exception raised is handled by this method)
  3. *
  4. * @param exchange
  5. * @param value
  6. */
  7. public void bridgeError(Exchange exchange, Object value) {
  8. // TODO is the in message null check needed?
  9. if (exchange.getIn() != null && exchange.getIn().getExchange().getException() != null) {
  10. exchange.getIn().setHeader(MessageConstants.HEADER_KAPUA_PROCESSING_EXCEPTION,
  11. Base64.getEncoder().encodeToString(SerializationUtils.serialize(exchange.getIn().getExchange().getException())));
  12. } else if (exchange.getException() != null) {
  13. exchange.getIn().setHeader(MessageConstants.HEADER_KAPUA_PROCESSING_EXCEPTION,
  14. Base64.getEncoder().encodeToString(SerializationUtils.serialize(exchange.getException())));
  15. } else {
  16. logger.debug("Cannot serialize exception since it is null!");
  17. }
  18. }
  19. }

代码示例来源:origin: org.apache.camel/camel-caffeine

  1. private Object getKey(final Message message) throws Exception {
  2. Object value = message.getHeader(CaffeineConstants.KEY, configuration.getKeyType());
  3. if (value == null) {
  4. value = configuration.getKey();
  5. }
  6. if (value == null) {
  7. throw new CamelExchangeException("No value provided in header or as default value (" + CaffeineConstants.KEY + ")", message.getExchange());
  8. }
  9. return value;
  10. }

代码示例来源:origin: org.apache.camel/camel-caffeine

  1. private Object getKey(final Message message) throws Exception {
  2. Object value = message.getHeader(CaffeineConstants.KEY, configuration.getKeyType());
  3. if (value == null) {
  4. value = configuration.getKey();
  5. }
  6. if (value == null) {
  7. throw new CamelExchangeException("No value provided in header or as default value (" + CaffeineConstants.KEY + ")", message.getExchange());
  8. }
  9. return value;
  10. }

代码示例来源:origin: org.apache.camel/camel-mail

  1. private Message extractAttachment(Message inMessage, String attachmentName) throws Exception {
  2. final Message outMessage = new DefaultMessage(inMessage.getExchange().getContext());
  3. outMessage.setHeader(HEADER_NAME, attachmentName);
  4. Object attachment = inMessage.getAttachment(attachmentName).getContent();
  5. if (attachment instanceof InputStream) {
  6. outMessage.setBody(readMimePart((InputStream) attachment));
  7. return outMessage;
  8. } else if (attachment instanceof String || attachment instanceof byte[]) {
  9. outMessage.setBody(attachment);
  10. return outMessage;
  11. } else {
  12. return null;
  13. }
  14. }

代码示例来源:origin: org.apache.camel/camel-web3j

  1. private boolean checkForError(Message message, Response response) {
  2. if (response.hasError()) {
  3. int code = response.getError().getCode();
  4. String data = response.getError().getData();
  5. String messages = response.getError().getMessage();
  6. message.setHeader(Web3jConstants.ERROR_CODE, code);
  7. message.setHeader(Web3jConstants.ERROR_DATA, data);
  8. message.setHeader(Web3jConstants.ERROR_MESSAGE, messages);
  9. message.getExchange().setException(new CamelExchangeException("Web3j failed. Error code: " + code + " data: " + data + " messages: " + messages, message.getExchange()));
  10. return true;
  11. } else {
  12. return false;
  13. }
  14. }

代码示例来源:origin: org.apache.servicemix/servicemix-camel

  1. public void copyFromCamelToJbi(Message message, NormalizedMessage normalizedMessage) throws MessagingException {
  2. if (message != null && message.getBody() != null) {
  3. Source body = message.getBody(Source.class);
  4. if (body == null) {
  5. logger.warn("Unable to convert message body of type {} into an XML Source", message.getBody().getClass());
  6. } else {
  7. normalizedMessage.setContent(body);
  8. }
  9. }
  10. Subject securitySubject = getSecuritySubject(message);
  11. if (securitySubject != null) {
  12. normalizedMessage.setSecuritySubject(securitySubject);
  13. }
  14. Exchange exchange = message.getExchange();
  15. for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
  16. String key = entry.getKey();
  17. Object value = entry.getValue();
  18. if (value != null && !strategies.applyFilterToCamelHeaders(key, value, exchange)) {
  19. normalizedMessage.setProperty(key, value);
  20. }
  21. }
  22. for (String id : message.getAttachmentNames()) {
  23. normalizedMessage.addAttachment(id, message.getAttachment(id));
  24. }
  25. }

代码示例来源:origin: com.bluelock/camel-spring-amqp

  1. @Override
  2. public Message postProcessMessage(Message msg) throws AmqpException {
  3. if(camelMessage == null || camelMessage.getHeaders() == null)
  4. return msg;
  5. //Set headers
  6. msg = SpringAMQPHeader.setBasicPropertiesFromHeaders(msg, camelMessage.getHeaders());
  7. msg = SpringAMQPHeader.copyHeaders(msg, camelMessage.getHeaders());
  8. //Set the exchange pattern so we can re-set it upon receipt
  9. if(camelMessage.getExchange() != null) {
  10. String exchangePattern = camelMessage.getExchange().getPattern().name();
  11. msg.getMessageProperties().setHeader(EXCHANGE_PATTERN, exchangePattern);
  12. } else {
  13. throw new IllegalStateException("No exchange was found for this message "+camelMessage.getMessageId());
  14. }
  15. return msg;
  16. }
  17. }

代码示例来源:origin: jboss-switchyard/components

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception {
  6. Message sourceMessage = exchange.getMessage();
  7. getContextMapper().mapTo(exchange.getContext(), target);
  8. org.apache.camel.Message targetMessage = target.getMessage();
  9. if (!sourceMessage.getAttachmentMap().isEmpty()) {
  10. for (Entry<String, DataSource> entry : sourceMessage.getAttachmentMap().entrySet()) {
  11. targetMessage.addAttachment(entry.getKey(), new DataHandler(entry.getValue()));
  12. }
  13. }
  14. ServiceOperation operation = exchange.getContract().getProviderOperation();
  15. target.getMessage().getExchange().setProperty(OPERATION_NAME, operation.getName());
  16. target.getMessage().getExchange().setProperty(FAULT_TYPE, operation.getFaultType());
  17. target.getMessage().getExchange().setProperty(SERVICE_NAME, exchange.getProvider().getName());
  18. targetMessage.setBody(sourceMessage.getContent());
  19. return target;
  20. }
  21. }

代码示例来源:origin: Bluelock/camel-spring-amqp

  1. @Override
  2. public Message postProcessMessage(Message msg) throws AmqpException {
  3. if(camelMessage == null || camelMessage.getHeaders() == null)
  4. return msg;
  5. //Set headers
  6. msg = SpringAMQPHeader.setBasicPropertiesFromHeaders(msg, camelMessage.getHeaders());
  7. msg = SpringAMQPHeader.copyHeaders(msg, camelMessage.getHeaders());
  8. //Set the exchange pattern so we can re-set it upon receipt
  9. if(camelMessage.getExchange() != null) {
  10. String exchangePattern = camelMessage.getExchange().getPattern().name();
  11. msg.getMessageProperties().setHeader(EXCHANGE_PATTERN, exchangePattern);
  12. } else {
  13. throw new IllegalStateException("No exchange was found for this message "+camelMessage.getMessageId());
  14. }
  15. return msg;
  16. }
  17. }

代码示例来源:origin: org.switchyard.components/switchyard-component-common-camel

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception {
  6. Message sourceMessage = exchange.getMessage();
  7. getContextMapper().mapTo(exchange.getContext(), target);
  8. org.apache.camel.Message targetMessage = target.getMessage();
  9. if (!sourceMessage.getAttachmentMap().isEmpty()) {
  10. for (Entry<String, DataSource> entry : sourceMessage.getAttachmentMap().entrySet()) {
  11. targetMessage.addAttachment(entry.getKey(), new DataHandler(entry.getValue()));
  12. }
  13. }
  14. ServiceOperation operation = exchange.getContract().getProviderOperation();
  15. target.getMessage().getExchange().setProperty(OPERATION_NAME, operation.getName());
  16. target.getMessage().getExchange().setProperty(FAULT_TYPE, operation.getFaultType());
  17. target.getMessage().getExchange().setProperty(SERVICE_NAME, exchange.getProvider().getName());
  18. targetMessage.setBody(sourceMessage.getContent());
  19. return target;
  20. }
  21. }

代码示例来源:origin: org.apache.camel/camel-hbase

  1. /**
  2. * Applies the cells to the {@link org.apache.camel.Exchange}.
  3. */
  4. public void applyScanResults(Message message, HBaseData data) {
  5. message.setHeaders(message.getExchange().getIn().getHeaders());
  6. int index = 1;
  7. if (data == null || data.getRows() == null) {
  8. return;
  9. }
  10. for (HBaseRow hRow : data.getRows()) {
  11. Set<HBaseCell> cells = hRow.getCells();
  12. for (HBaseCell cell : cells) {
  13. message.setHeader(HBaseAttribute.HBASE_ROW_ID.asHeader(index), hRow.getId());
  14. message.setHeader(HBaseAttribute.HBASE_FAMILY.asHeader(index), cell.getFamily());
  15. message.setHeader(HBaseAttribute.HBASE_QUALIFIER.asHeader(index), cell.getQualifier());
  16. message.setHeader(HBaseAttribute.HBASE_VALUE.asHeader(index), cell.getValue());
  17. }
  18. index++;
  19. }
  20. }

代码示例来源:origin: org.apache.camel/camel-hbase

  1. /**
  2. * Applies the cells to the {@link org.apache.camel.Exchange}.
  3. */
  4. public void applyGetResults(Message message, HBaseData data) {
  5. message.setHeaders(message.getExchange().getIn().getHeaders());
  6. int index = 1;
  7. if (data == null || data.getRows() == null) {
  8. return;
  9. }
  10. for (HBaseRow hRow : data.getRows()) {
  11. if (hRow.getId() != null) {
  12. Set<HBaseCell> cells = hRow.getCells();
  13. for (HBaseCell cell : cells) {
  14. message.setHeader(HBaseAttribute.HBASE_VALUE.asHeader(index++), getValueForColumn(cells, cell.getFamily(), cell.getQualifier()));
  15. }
  16. }
  17. }
  18. }

代码示例来源:origin: org.apache.camel/camel-spring-integration

  1. @Override
  2. public void copyFrom(org.apache.camel.Message that) {
  3. if (that == this) {
  4. // the same instance so do not need to copy
  5. return;
  6. }
  7. if (that instanceof CamelContextAware) {
  8. this.setCamelContext(((CamelContextAware) that).getCamelContext());
  9. }
  10. // cover over exchange if none has been assigned
  11. if (getExchange() == null) {
  12. setExchange(that.getExchange());
  13. }
  14. setMessageId(that.getMessageId());
  15. setBody(that.getBody());
  16. super.getHeaders().putAll(that.getHeaders());
  17. if (that instanceof SpringIntegrationMessage) {
  18. SpringIntegrationMessage orig = (SpringIntegrationMessage) that;
  19. setMessage(orig.getMessage());
  20. }
  21. getAttachments().putAll(that.getAttachments());
  22. }

代码示例来源:origin: org.apache.camel/camel-mail

  1. public void copyFrom(org.apache.camel.Message that) {
  2. // only do a deep copy if we need to (yes when that is not a mail message, or if the mapMailMessage is true)
  3. boolean needCopy = !(that instanceof MailMessage) || (((MailMessage) that).mapMailMessage);
  4. if (needCopy) {
  5. super.copyFrom(that);
  6. } else {
  7. // no deep copy needed, but copy message id
  8. setMessageId(that.getMessageId());
  9. setFault(that.isFault());
  10. }
  11. if (that instanceof MailMessage) {
  12. MailMessage mailMessage = (MailMessage) that;
  13. this.originalMailMessage = mailMessage.originalMailMessage;
  14. this.mailMessage = mailMessage.mailMessage;
  15. this.mapMailMessage = mailMessage.mapMailMessage;
  16. }
  17. // cover over exchange if none has been assigned
  18. if (getExchange() == null) {
  19. setExchange(that.getExchange());
  20. }
  21. }

相关文章