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

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

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

Message.setHeaders介绍

暂无

代码示例

代码示例来源:origin: org.jbpm.contrib/camel-workitem

@Override
  public void process(Exchange exchange) throws Exception {
    exchange.getIn().setBody(payload);
    exchange.getIn().setHeaders(headers);
  }
}

代码示例来源:origin: org.jboss.integration.fuse/jbpm-workitems-camel

@Override
  public void process(Exchange exchange) throws Exception {
    exchange.getIn().setBody(payload);
    exchange.getIn().setHeaders(headers);
  }
}

代码示例来源:origin: PerfCake/PerfCake

@Override
 public void process(Exchange exchange) throws Exception {
   exchange.getIn().setBody(body);
   exchange.getIn().setHeaders(headers);
 }
}

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

public static void storeToCamelMessage(org.springframework.messaging.Message<?> siMessage, org.apache.camel.Message cMessage) {
  cMessage.setBody(siMessage.getPayload());
  cMessage.setHeaders(siMessage.getHeaders());
}

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

@Override
public void onComplete(Object response) {
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  if (response == null) {
    exchange.getOut().setBody(response);
  } else {
    exchange.getOut().setBody(response, response.getClass());
  }
  callback.done(false);
}

代码示例来源:origin: stackoverflow.com

public class CustomService {
 public List split(Exchange exchange) {
  List list = new ArrayList();

  Map map = exchange.getIn().getBody(Map.class);
  for (Object value : map.values()) {
    // either copy or create a new DefaultMessage
    Message msg = new DefaultMessage();
    msg.setBody(value);
    // we want to copy the existing headers
    msg.setHeaders(exchange.getIn().getHeaders();
    // and then customize the headers
    msg.setHeader("foo", "bar");
    list.add(msg);
  }
  return list;
 }
}

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

public static void setOut(Exchange exchange, Object payload) {
  if (payload instanceof DefaultExchangeHolder) {
    DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) payload);
  } else {
    // normal transfer using the body only and preserve the headers
    exchange.getOut().setHeaders(exchange.getIn().getHeaders());
    exchange.getOut().setBody(payload);
  }
}

代码示例来源:origin: camelinaction/camelinaction2

public void process(Exchange exchange) throws Exception {
  String input = exchange.getIn().getBody(String.class);
  // if the verbose switch is turned on then log to System out
  if (getEndpoint().isVerbose()) {
    System.out.println("Calling ERP with: " + input);
  }
  // simulate calling ERP system and setting reply on the OUT body
  exchange.getOut().setBody("Simulated response from ERP");
  // support propagating headers (by copying headers from IN -> OUT)
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
}

代码示例来源:origin: com.googlecode.metridoc/metridoc-camel-core

@Override
@SuppressWarnings("unchecked")
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
  
  if (oldExchange == null) {
    oldExchange = new DefaultExchange(newExchange);
    oldExchange.getIn().setHeaders(newExchange.getIn().getHeaders());
    List<Object> body = new ArrayList<Object>();
    oldExchange.getIn().setBody(body);
    oldExchange.getExchangeId();
  }
  oldExchange.getIn().getBody(List.class).add(newExchange.getIn().getBody());
  
  return oldExchange;
}

代码示例来源:origin: camelinaction/camelinaction

public void process(Exchange exchange) throws Exception {
  String input = exchange.getIn().getBody(String.class);
  // if the verbose switch is turned on then log to System out
  if (getEndpoint().isVerbose()) {
    System.out.println("Calling ERP with: " + input);
  }
  // simulate calling ERP system and setting reply on the OUT body
  exchange.getOut().setBody("Simulated response from ERP");
  // support propagating headers (by copying headers from IN -> OUT)
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
}

代码示例来源:origin: OpenWiseSolutions/openhub-framework

/**
 * Propagates (copies) the {@code Body}, the {@code Attachments} and the {@code Headers} of the {@link Message}
 * from from IN to OUT.
 *
 * @param exchange the exchange message
 */
public static void propagateMessage(Exchange exchange) {
  Assert.notNull(exchange, "the exchange must not be null");
  // copy headers from IN to OUT to propagate them
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  // copy attachments from IN to OUT to propagate them
  exchange.getOut().setAttachments(exchange.getIn().getAttachments());
  // copy body from IN to OUT to propagate it
  exchange.getOut().setBody(exchange.getIn().getBody());
}

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

@Override
public void onResponse(Object response, Map<String, String> responseHeaders) {
  // producer returns a single response, even for methods with List return types
  exchange.getOut().setBody(response);
  // copy headers
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  
  // Add http response headers
  exchange.getOut().setHeader(Olingo2Constants.PROPERTY_PREFIX + RESPONSE_HTTP_HEADERS, responseHeaders);
  interceptResult(response, exchange);
  callback.done(false);
}

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

public static void copyHeaders(Exchange ex) {
  // get in headers
  Map<String, Object> headers = ex.getIn().getHeaders();
  // DELETE item id
  if (headers.containsKey(HazelcastConstants.OBJECT_ID)) {
    headers.remove(HazelcastConstants.OBJECT_ID);
  }
  if (headers.containsKey(HazelcastConstants.OPERATION)) {
    headers.remove(HazelcastConstants.OPERATION);
  }
  // propagate headers if OUT message created
  if (ex.hasOut()) {
    ex.getOut().setHeaders(headers);
  }
}

代码示例来源:origin: redhat-developer-demos/istio-tutorial

private void handleHttpFailure(Exchange exchange) {
  HttpOperationFailedException e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class);
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  exchange.getOut().setBody(String.format(RESPONSE_STRING_FORMAT,
      String.format("%d %s", e.getStatusCode(), e.getResponseBody())
  ));
}

代码示例来源:origin: redhat-developer-demos/istio-tutorial

private void handleHttpFailure(Exchange exchange) {
    HttpOperationFailedException e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class);
    exchange.getOut().setHeaders(exchange.getIn().getHeaders());
    exchange.getOut().setBody(String.format(RESPONSE_STRING_FORMAT,
        String.format("%d %s", e.getStatusCode(), e.getResponseBody())
    ));
  }
}

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

@Override
public void onResponse(Object response) {
  // producer returns a single response, even for methods with List return types
  exchange.getOut().setBody(response);
  // copy headers
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  interceptResult(response, exchange);
  callback.done(false);
}

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

/**
 * Creates an <code>exchange.getOut()</code> message that containing the 
 * access token and the access token secret in the message header.
 *
 * @see #GAUTH_ACCESS_TOKEN
 * @see #GAUTH_ACCESS_TOKEN_SECRET
 */
public Exchange readResponse(GAuthEndpoint endpoint, Exchange exchange, GoogleOAuthParameters response) throws IOException {
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN, canonicalizeToken(response.getOAuthToken()));
  exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN_SECRET, canonicalizeToken(response.getOAuthTokenSecret()));
  return exchange;
}

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

protected void readResponseHeaders(GHttpEndpoint endpoint, Exchange exchange, HTTPResponse response) {
  HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
  
  Message in = exchange.getIn();
  Message out = exchange.getOut();
  
  out.setHeaders(in.getHeaders());
  out.setHeader(Exchange.HTTP_RESPONSE_CODE, response.getResponseCode());
  
  String contentType = getResponseHeader("Content-Type", response);
  if (contentType != null) {
    out.setHeader(Exchange.CONTENT_TYPE, contentType);
  }
  
  for (HTTPHeader header : response.getHeaders()) {
    String name = header.getName();
    String value = header.getValue();
    if (strategy != null && !strategy.applyFilterToExternalHeaders(name, value, exchange)) {
      out.setHeader(name, value);
    }
  }
}

代码示例来源:origin: org.openehealth.ipf.platform-camel/ipf-platform-camel-flow

/**
 * Creates a new {@link Exchange} from <code>packet</code> using the
 * current {@link CamelContext}.
 * 
 * @param packet message packet.
 * @return a new message exchange.
 */
protected Exchange createExchange(PlatformPacket packet) {
  DefaultExchange exchange = new DefaultExchange(camelContext);
  
  exchange.setUnitOfWork(new DefaultUnitOfWork(exchange));
  exchange.setProperties(new HashMap<>(packet.getExchangeProperties()));
  exchange.getIn().setHeaders(new HashMap<>(packet.getMessageProperties()));
  setInBody(packet.getMessageBody(), exchange);

  return exchange;
}

代码示例来源: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()));
      }
    }
  }
}

相关文章