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


Java Message.setHeader方法代码示例

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


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

示例1: testCopyHeadersWithHeaderFilterStrategy

import org.apache.camel.Message; //导入方法依赖的package包/类
public void testCopyHeadersWithHeaderFilterStrategy() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.start();

    message = new DefaultExchange(context).getIn();
    
    Message source = message;
    Message target = message.getExchange().getOut();
    
    DefaultHeaderFilterStrategy headerFilterStrategy = new DefaultHeaderFilterStrategy();
    headerFilterStrategy.setInFilterPattern("foo");
    
    source.setHeader("foo", 123);
    source.setHeader("bar", 456);
    target.setHeader("bar", "yes");
    
    MessageHelper.copyHeaders(source, target, headerFilterStrategy, true);
    
    assertEquals(null, target.getHeader("foo"));
    assertEquals(456, target.getHeader("bar"));
    context.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:MessageHelperTest.java

示例2: applyGetResults

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * 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()));
            }
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:HeaderMappingStrategy.java

示例3: applyScanResults

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * 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++;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:HeaderMappingStrategy.java

示例4: jsonMarshalIfRequired

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * Lets marshal the body to JSON using Jackson if we require it.
 * <br>
 * The current rules are to only marshal to JSON if we don't have a {@link Exchange#CONTENT_TYPE} header.
 * If we can convert the body to a String then we test if its already JSON and if not we marshal it using the JSON
 * data format with the Jackson library
 */
public void jsonMarshalIfRequired(Exchange exchange) throws Exception {
    Message in = exchange.getIn();
    if (in == null) {
        return;
    }
    String contentType = in.getHeader(Exchange.CONTENT_TYPE, String.class);
    if (!Strings.isEmpty(contentType)) {
        // lets preserve existing content types as it could be XML, YAML or something else
        return;
    }
    Object body = in.getBody();
    if (body != null) {
        if (isPossibleJsonClass(exchange, body.getClass(), body)) {
            try {
                String text = in.getBody(String.class);
                if (text != null) {
                    if (isJsonLookingString(text.trim())) {
                        in.setHeader(Exchange.CONTENT_TYPE, JSON_CONTENT_TYPE);
                    }
                    in.setBody(text);
                    return;
                }
            } catch (Exception e) {
                // ignore
            }
        }

        in.setHeader(Exchange.CONTENT_TYPE, JSON_CONTENT_TYPE);

        jsonMarshalProducer.process(exchange);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:40,代码来源:JsonEndpoint.java

示例5: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public void process(final Exchange exchange) throws Exception {
    // parse input json and extract Id field
    final Message in = exchange.getIn();
    final String body = in.getBody(String.class);

    if (body == null) {
        return;
    }

    final ObjectNode node = (ObjectNode) MAPPER.readTree(body);

    final String idPropertyName = determineIdProperty(exchange);

    final JsonNode idProperty = node.remove(idPropertyName);
    if (idProperty == null) {
        exchange.setException(
            new SalesforceException("Missing option value for Id or " + SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, 404));

        return;
    }

    final String idValue = idProperty.textValue();
    if ("Id".equals(idPropertyName)) {
        in.setHeader(SalesforceEndpointConfig.SOBJECT_ID, idValue);
    } else {
        in.setHeader(SalesforceEndpointConfig.SOBJECT_EXT_ID_VALUE, idValue);
    }

    // base fields are not allowed to be updated
    clearBaseFields(node);

    // update input json
    in.setBody(MAPPER.writeValueAsString(node));
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:36,代码来源:AdaptObjectForUpdateProcessor.java

示例6: process

import org.apache.camel.Message; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
	
	Message in = exchange.getIn();
	Map<String,Object> tuple= (Map<String, Object>) in.getBody();
	MoneyTransfer mt = new  MoneyTransfer();
	mt.setId((Long)tuple.get(MoneyTransfer.FIELD_ID));
	mt.setKeycode((String)tuple.get(MoneyTransfer.FIELD_KEYCODE));
	mt.setPaymentMethod((String)tuple.get(MoneyTransfer.FIELD_PAYMENT_METHOD));
	mt.setAmount_hf_sender_currency((BigDecimal)tuple.get(MoneyTransfer.FIELD_AMOUNT_HF_SENDER_CUR));
	mt.setStatus((String)tuple.get(MoneyTransfer.FIELD_STATUS));
	in.setBody(mt);
	in.setHeader(InfinispanConstants.KEY, mt.getKeycode());

}
 
开发者ID:PacktPublishing,项目名称:JBoss-Developers-Guide,代码行数:15,代码来源:AFProcessor.java

示例7: put

import org.apache.camel.Message; //导入方法依赖的package包/类
@InvokeOnHeader(ConsulKeyValueActions.PUT)
protected void put(Message message) throws Exception {
    message.setHeader(
        ConsulConstants.CONSUL_RESULT,
        getClient().putValue(
            getMandatoryKey(message),
            message.getBody(String.class),
            message.getHeader(ConsulConstants.CONSUL_FLAGS, 0L, Long.class),
            getOption(message, PutOptions.BLANK, PutOptions.class)
        )
    );
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:ConsulKeyValueProducer.java

示例8: populateResponse

import org.apache.camel.Message; //导入方法依赖的package包/类
protected void populateResponse(Exchange exchange, JettyContentExchange httpExchange,
                                Message in, HeaderFilterStrategy strategy, int responseCode) throws IOException {
    Message answer = exchange.getOut();

    answer.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);

    // must use response fields to get the http headers as
    // httpExchange.getHeaders() does not work well with multi valued headers
    Map<String, Collection<String>> headers = httpExchange.getResponseHeaders();
    for (Map.Entry<String, Collection<String>> ent : headers.entrySet()) {
        String name = ent.getKey();
        Collection<String> values = ent.getValue();
        for (String value : values) {
            if (name.toLowerCase().equals("content-type")) {
                name = Exchange.CONTENT_TYPE;
                exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.getCharsetNameFromContentType(value));
            }
            if (strategy != null && !strategy.applyFilterToExternalHeaders(name, value, exchange)) {
                HttpHelper.appendHeader(answer.getHeaders(), name, value);
            }
        }
    }

    // preserve headers from in by copying any non existing headers
    // to avoid overriding existing headers with old values
    MessageHelper.copyHeaders(exchange.getIn(), answer, false);

    // extract body after headers has been set as we want to ensure content-type from Jetty HttpExchange
    // has been populated first
    answer.setBody(extractResponseBody(exchange, httpExchange));
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:32,代码来源:DefaultJettyHttpBinding.java

示例9: extractAttachment

import org.apache.camel.Message; //导入方法依赖的package包/类
private Message extractAttachment(Message inMessage, String attachmentName) throws Exception {
    final Message outMessage = new DefaultMessage();
    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;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:SplitAttachmentsExpression.java

示例10: createExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
protected Exchange createExchange(Object data) {
    final Exchange exchange = getEndpoint().createExchange(ExchangePattern.InOnly);
    Message msg = exchange.getIn();
    if (getEndpoint().getOutputHeader() != null) {
        msg.setHeader(getEndpoint().getOutputHeader(), data);
    } else {
        msg.setBody(data);
    }
    return exchange;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:SqlConsumer.java

示例11: transformNodeToByteArrayAndSetToOutputMessage

import org.apache.camel.Message; //导入方法依赖的package包/类
protected void transformNodeToByteArrayAndSetToOutputMessage(Input input, Message output, Node node)
    throws Exception {

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    XmlSignatureHelper.transformToOutputStream(node, os, omitXmlDeclaration(output, input), input.getOutputXmlEncoding());
    output.setBody(os.toByteArray());
    if (input.getOutputXmlEncoding() != null) {
        output.setHeader(Exchange.CHARSET_NAME, input.getOutputXmlEncoding());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:DefaultXmlSignature2Message.java

示例12: process

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
    PutRecordRequest request = createRequest(exchange);
    PutRecordResult putRecordResult = getEndpoint().getClient().putRecord(request);
    Message message = getMessageForResponse(exchange);
    message.setHeader(KinesisConstants.SEQUENCE_NUMBER, putRecordResult.getSequenceNumber());
    message.setHeader(KinesisConstants.SHARD_ID, putRecordResult.getShardId());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:KinesisProducer.java

示例13: addSessionAttributesToMessageHeaders

import org.apache.camel.Message; //导入方法依赖的package包/类
private void addSessionAttributesToMessageHeaders(ServerSession remote, Message message) {
    Set<String> attributeNames = remote.getAttributeNames();
    for (String attributeName : attributeNames) {
        Object attribute = remote.getAttribute(attributeName);

        if (attribute instanceof Integer || attribute instanceof String || attribute instanceof Long
            || attribute instanceof Double || attribute instanceof Boolean) {
            message.setHeader(attributeName, attribute);
        } else {
            // Do we need to support other type of session objects ?
            LOG.info(String.format(IMPROPER_SESSTION_ATTRIBUTE_TYPE_MESSAGE, attributeName, attribute));
        }

    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:CometdBinding.java

示例14: createCacheExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
public Exchange createCacheExchange(String operation, String key, Object value) {
    Exchange exchange = super.createExchange();
    Message message = exchange.getIn();
    message.setHeader(CacheConstants.CACHE_OPERATION, operation);
    message.setHeader(CacheConstants.CACHE_KEY, key);
    message.setBody(value);
    return exchange;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:CacheEndpoint.java

示例15: createLetter

import org.apache.camel.Message; //导入方法依赖的package包/类
private Exchange createLetter() {
    Exchange exchange = context.getEndpoint("direct:a").createExchange();
    Message msg = exchange.getIn();
    msg.setHeader("firstName", "Claus");
    msg.setHeader("lastName", "Ibsen");
    msg.setHeader("item", "Camel in Action");
    msg.setBody("PS: Next beer is on me, James");
    return exchange;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:VelocityLetterTest.java


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