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

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

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

  1. @Override
  2. public void process(Exchange exchange) throws Exception {
  3. exchange.getIn().setBody(payload);
  4. exchange.getIn().setHeaders(headers);
  5. }
  6. }

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

  1. @Override
  2. public void process(Exchange exchange) throws Exception {
  3. exchange.getIn().setBody(payload);
  4. exchange.getIn().setHeaders(headers);
  5. }
  6. }

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

  1. @Override
  2. public void process(Exchange exchange) throws Exception {
  3. exchange.getIn().setBody(body);
  4. exchange.getIn().setHeaders(headers);
  5. }
  6. }

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

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

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

  1. @Override
  2. public void onComplete(Object response) {
  3. exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  4. if (response == null) {
  5. exchange.getOut().setBody(response);
  6. } else {
  7. exchange.getOut().setBody(response, response.getClass());
  8. }
  9. callback.done(false);
  10. }

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

  1. public class CustomService {
  2. public List split(Exchange exchange) {
  3. List list = new ArrayList();
  4. Map map = exchange.getIn().getBody(Map.class);
  5. for (Object value : map.values()) {
  6. // either copy or create a new DefaultMessage
  7. Message msg = new DefaultMessage();
  8. msg.setBody(value);
  9. // we want to copy the existing headers
  10. msg.setHeaders(exchange.getIn().getHeaders();
  11. // and then customize the headers
  12. msg.setHeader("foo", "bar");
  13. list.add(msg);
  14. }
  15. return list;
  16. }
  17. }

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

  1. public static void setOut(Exchange exchange, Object payload) {
  2. if (payload instanceof DefaultExchangeHolder) {
  3. DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) payload);
  4. } else {
  5. // normal transfer using the body only and preserve the headers
  6. exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  7. exchange.getOut().setBody(payload);
  8. }
  9. }

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

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

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

  1. @Override
  2. @SuppressWarnings("unchecked")
  3. public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
  4. if (oldExchange == null) {
  5. oldExchange = new DefaultExchange(newExchange);
  6. oldExchange.getIn().setHeaders(newExchange.getIn().getHeaders());
  7. List<Object> body = new ArrayList<Object>();
  8. oldExchange.getIn().setBody(body);
  9. oldExchange.getExchangeId();
  10. }
  11. oldExchange.getIn().getBody(List.class).add(newExchange.getIn().getBody());
  12. return oldExchange;
  13. }

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

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

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

  1. /**
  2. * Propagates (copies) the {@code Body}, the {@code Attachments} and the {@code Headers} of the {@link Message}
  3. * from from IN to OUT.
  4. *
  5. * @param exchange the exchange message
  6. */
  7. public static void propagateMessage(Exchange exchange) {
  8. Assert.notNull(exchange, "the exchange must not be null");
  9. // copy headers from IN to OUT to propagate them
  10. exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  11. // copy attachments from IN to OUT to propagate them
  12. exchange.getOut().setAttachments(exchange.getIn().getAttachments());
  13. // copy body from IN to OUT to propagate it
  14. exchange.getOut().setBody(exchange.getIn().getBody());
  15. }

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

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

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

  1. public static void copyHeaders(Exchange ex) {
  2. // get in headers
  3. Map<String, Object> headers = ex.getIn().getHeaders();
  4. // DELETE item id
  5. if (headers.containsKey(HazelcastConstants.OBJECT_ID)) {
  6. headers.remove(HazelcastConstants.OBJECT_ID);
  7. }
  8. if (headers.containsKey(HazelcastConstants.OPERATION)) {
  9. headers.remove(HazelcastConstants.OPERATION);
  10. }
  11. // propagate headers if OUT message created
  12. if (ex.hasOut()) {
  13. ex.getOut().setHeaders(headers);
  14. }
  15. }

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

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

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

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

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

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

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

  1. /**
  2. * Creates an <code>exchange.getOut()</code> message that containing the
  3. * access token and the access token secret in the message header.
  4. *
  5. * @see #GAUTH_ACCESS_TOKEN
  6. * @see #GAUTH_ACCESS_TOKEN_SECRET
  7. */
  8. public Exchange readResponse(GAuthEndpoint endpoint, Exchange exchange, GoogleOAuthParameters response) throws IOException {
  9. exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  10. exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN, canonicalizeToken(response.getOAuthToken()));
  11. exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN_SECRET, canonicalizeToken(response.getOAuthTokenSecret()));
  12. return exchange;
  13. }

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

  1. protected void readResponseHeaders(GHttpEndpoint endpoint, Exchange exchange, HTTPResponse response) {
  2. HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
  3. Message in = exchange.getIn();
  4. Message out = exchange.getOut();
  5. out.setHeaders(in.getHeaders());
  6. out.setHeader(Exchange.HTTP_RESPONSE_CODE, response.getResponseCode());
  7. String contentType = getResponseHeader("Content-Type", response);
  8. if (contentType != null) {
  9. out.setHeader(Exchange.CONTENT_TYPE, contentType);
  10. }
  11. for (HTTPHeader header : response.getHeaders()) {
  12. String name = header.getName();
  13. String value = header.getValue();
  14. if (strategy != null && !strategy.applyFilterToExternalHeaders(name, value, exchange)) {
  15. out.setHeader(name, value);
  16. }
  17. }
  18. }

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

  1. /**
  2. * Creates a new {@link Exchange} from <code>packet</code> using the
  3. * current {@link CamelContext}.
  4. *
  5. * @param packet message packet.
  6. * @return a new message exchange.
  7. */
  8. protected Exchange createExchange(PlatformPacket packet) {
  9. DefaultExchange exchange = new DefaultExchange(camelContext);
  10. exchange.setUnitOfWork(new DefaultUnitOfWork(exchange));
  11. exchange.setProperties(new HashMap<>(packet.getExchangeProperties()));
  12. exchange.getIn().setHeaders(new HashMap<>(packet.getMessageProperties()));
  13. setInBody(packet.getMessageBody(), exchange);
  14. return exchange;
  15. }

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

相关文章