当前位置: 首页>>代码示例>>Java>>正文


Java Message.hasHeaders方法代码示例

本文整理汇总了Java中org.apache.camel.Message.hasHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java Message.hasHeaders方法的具体用法?Java Message.hasHeaders怎么用?Java Message.hasHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.Message的用法示例。


在下文中一共展示了Message.hasHeaders方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyHeaders

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * Copies the headers from the source to the target message.
 * 
 * @param source the source message
 * @param target the target message
 * @param strategy the header filter strategy which could help us to filter the protocol message headers
 * @param override whether to override existing headers
 */
public static void copyHeaders(Message source, Message target, HeaderFilterStrategy strategy, boolean override) {
    if (!source.hasHeaders()) {
        return;
    }

    for (Map.Entry<String, Object> entry : source.getHeaders().entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();

        if (target.getHeader(key) == null || override) {
            if (strategy == null) {
                target.setHeader(key, value);
            } else if (!strategy.applyFilterToExternalHeaders(key, value, target.getExchange())) {
                // Just make sure we don't copy the protocol headers to target
                target.setHeader(key, value);
            }
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:MessageHelper.java

示例2: getDeliveryOptions

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * Creates {@link DeliveryOptions} from the given {@code message}. It simply copies the headers if the {@code
 * headerCopy} parameter is set to {@code true}.
 *
 * @param msg        the message from Camel, must not be {@code null}
 * @param headerCopy whether or not the headers need to be copied
 * @return the created {@link DeliveryOptions}
 */
static DeliveryOptions getDeliveryOptions(Message msg, boolean headerCopy) {
  DeliveryOptions delivery = new DeliveryOptions();
  if (headerCopy && msg.hasHeaders()) {
    msg.getHeaders().entrySet().stream().forEach(entry -> {
      if (entry.getValue() != null) {
        delivery.addHeader(entry.getKey(), entry.getValue().toString());
      }
    });
  }
  return delivery;
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:20,代码来源:CamelHelper.java

示例3: copyFrom

import org.apache.camel.Message; //导入方法依赖的package包/类
public void copyFrom(Message that) {
    if (that == this) {
        // the same instance so do not need to copy
        return;
    }

    setMessageId(that.getMessageId());
    setBody(that.getBody());
    setFault(that.isFault());

    // the headers may be the same instance if the end user has made some mistake
    // and set the OUT message with the same header instance of the IN message etc
    boolean sameHeadersInstance = false;
    if (hasHeaders() && that.hasHeaders() && getHeaders() == that.getHeaders()) {
        sameHeadersInstance = true;
    }

    if (!sameHeadersInstance) {
        if (hasHeaders()) {
            // okay its safe to clear the headers
            getHeaders().clear();
        }
        if (that.hasHeaders()) {
            getHeaders().putAll(that.getHeaders());
        }
    }

    copyAttachments(that);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:30,代码来源:MessageSupport.java

示例4: performAssertions

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * Performs the assertions on the incoming exchange.
 *
 * @param exchange   the actual exchange
 * @param copy       a copy of the exchange (only store this)
 * @throws Exception can be thrown if something went wrong
 */
protected void performAssertions(Exchange exchange, Exchange copy) throws Exception {
    Message in = copy.getIn();
    Object actualBody = in.getBody();

    if (expectedHeaderValues != null) {
        if (actualHeaderValues == null) {
            actualHeaderValues = new CaseInsensitiveMap();
        }
        if (in.hasHeaders()) {
            actualHeaderValues.putAll(in.getHeaders());
        }
    }

    if (expectedPropertyValues != null) {
        if (actualPropertyValues == null) {
            actualPropertyValues = new ConcurrentHashMap<String, Object>();
        }
        actualPropertyValues.putAll(copy.getProperties());
    }

    if (expectedBodyValues != null) {
        int index = actualBodyValues.size();
        if (expectedBodyValues.size() > index) {
            Object expectedBody = expectedBodyValues.get(index);
            if (expectedBody != null) {
                // prefer to convert body early, for example when using files
                // we need to read the content at this time
                Object body = in.getBody(expectedBody.getClass());
                if (body != null) {
                    actualBody = body;
                }
            }
            actualBodyValues.add(actualBody);
        }
    }

    // let counter be 0 index-based in the logs
    if (LOG.isDebugEnabled()) {
        String msg = getEndpointUri() + " >>>> " + counter + " : " + copy + " with body: " + actualBody;
        if (copy.getIn().hasHeaders()) {
            msg += " and headers:" + copy.getIn().getHeaders();
        }
        LOG.debug(msg);
    }

    // record timestamp when exchange was received
    copy.setProperty(Exchange.RECEIVED_TIMESTAMP, new Date());

    // add a copy of the received exchange
    addReceivedExchange(copy);
    // and then increment counter after adding received exchange
    ++counter;

    Processor processor = processors.get(getReceivedCounter()) != null
            ? processors.get(getReceivedCounter()) : defaultProcessor;

    if (processor != null) {
        try {
            // must process the incoming exchange and NOT the copy as the idea
            // is the end user can manipulate the exchange
            processor.process(exchange);
        } catch (Exception e) {
            // set exceptions on exchange so we can throw exceptions to simulate errors
            exchange.setException(e);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:75,代码来源:MockEndpoint.java

示例5: addHeadersToMessage

import org.apache.camel.Message; //导入方法依赖的package包/类
public void addHeadersToMessage(ServerMessage.Mutable cometdMessage, Message camelMessage) {
    if (camelMessage.hasHeaders()) {
        Map<String, Object> ext = cometdMessage.getExt(true);
        ext.put(HEADERS_FIELD, filterHeaders(camelMessage.getHeaders()));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:CometdBinding.java


注:本文中的org.apache.camel.Message.hasHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。