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

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

本文整理了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

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

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

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;
}

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

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;
}

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

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");
  }
}

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

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;
}

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

@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);
  }
}

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

/**
   * 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!");
    }
  }
}

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

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;
}

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

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;
}

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

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;
  }
}

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

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;
  }
}

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

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));
  }
}

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

@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;
  }
}

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

/**
   * {@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;
  }
}

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

@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;
  }
}

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

/**
   * {@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;
  }
}

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

/**
 * 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++;
  }
}

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

/**
 * 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()));
      }
    }
  }
}

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

@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());
}

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

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());
  }
}

相关文章