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


Java Message.setHeaders方法代码示例

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


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

示例1: build

import org.apache.camel.Message; //导入方法依赖的package包/类
/**
 * Build up the exchange from the exchange builder
 *
 * @return exchange 
 */
public Exchange build() {
    Exchange exchange = new DefaultExchange(context);
    Message message = exchange.getIn();
    message.setBody(body);
    if (headers.size() > 0) {
        message.setHeaders(headers);
    }
    // setup the properties on the exchange
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        exchange.setProperty(entry.getKey(), entry.getValue());
    }
    if (pattern != null) {
        exchange.setPattern(pattern);
    }

    return exchange;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:ExchangeBuilder.java

示例2: testCopyFromSameHeadersInstance

import org.apache.camel.Message; //导入方法依赖的package包/类
public void testCopyFromSameHeadersInstance() {
    Exchange exchange = new DefaultExchange(context);

    Message in = exchange.getIn();
    Map<String, Object> headers = in.getHeaders();
    headers.put("foo", 123);

    Message out = new DefaultMessage();
    out.setBody("Bye World");
    out.setHeaders(headers);

    out.copyFrom(in);

    assertEquals(123, headers.get("foo"));
    assertEquals(123, in.getHeader("foo"));
    assertEquals(123, out.getHeader("foo"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:MessageSupportTest.java

示例3: onExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    StringWriter buffer = new StringWriter();
    
    @SuppressWarnings("unchecked")
    Map<String, Object> variableMap = exchange.getIn().getHeader(StringTemplateConstants.STRINGTEMPLATE_VARIABLE_MAP, Map.class);
    if (variableMap == null) {
        variableMap = ExchangeHelper.createVariableMap(exchange);
    }

    // getResourceAsInputStream also considers the content cache
    String text = exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, getResourceAsInputStream());
    ST template = new ST(text, delimiterStart, delimiterStop);
    for (Map.Entry<String, Object> entry : variableMap.entrySet()) {
        template.add(entry.getKey(), entry.getValue());
    }
    log.debug("StringTemplate is writing using attributes: {}", variableMap);
    template.write(new NoIndentWriter(buffer));

    // now lets output the results to the exchange
    Message out = exchange.getOut();
    out.setBody(buffer.toString());
    out.setHeaders(exchange.getIn().getHeaders());
    out.setHeader(StringTemplateConstants.STRINGTEMPLATE_RESOURCE_URI, getResourceUri());
    out.setAttachments(exchange.getIn().getAttachments());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:StringTemplateEndpoint.java

示例4: createExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
private Exchange createExchange(ExchangePattern pattern, com.amazonaws.services.sqs.model.Message msg) {
    Exchange exchange = super.createExchange(pattern);
    Message message = exchange.getIn();
    message.setBody(msg.getBody());
    message.setHeaders(new HashMap<String, Object>(msg.getAttributes()));
    message.setHeader(SqsConstants.MESSAGE_ID, msg.getMessageId());
    message.setHeader(SqsConstants.MD5_OF_BODY, msg.getMD5OfBody());
    message.setHeader(SqsConstants.RECEIPT_HANDLE, msg.getReceiptHandle());
    message.setHeader(SqsConstants.ATTRIBUTES, msg.getAttributes());
    message.setHeader(SqsConstants.MESSAGE_ATTRIBUTES, msg.getMessageAttributes());
    
    //Need to apply the SqsHeaderFilterStrategy this time
    HeaderFilterStrategy headerFilterStrategy = getHeaderFilterStrategy();
    //add all sqs message attributes as camel message headers so that knowledge of 
    //the Sqs class MessageAttributeValue will not leak to the client
    for (Entry<String, MessageAttributeValue> entry : msg.getMessageAttributes().entrySet()) {
        String header = entry.getKey();
        Object value = translateValue(entry.getValue());
        if (!headerFilterStrategy.applyFilterToExternalHeaders(header, value, exchange)) {
            message.setHeader(header, value);
        }
    }
    return exchange;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:SqsEndpoint.java

示例5: 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

示例6: 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

示例7: createCamelMessage

import org.apache.camel.Message; //导入方法依赖的package包/类
public Message createCamelMessage(ServerSession remote, ServerMessage cometdMessage, Object data) {
    if (cometdMessage != null) {
        data = cometdMessage.getData();
    }

    Message message = new DefaultMessage();
    message.setBody(data);
    Map headers = getHeadersFromMessage(cometdMessage);
    if (headers != null) {
        message.setHeaders(headers);
    }
    message.setHeader(COMETD_CLIENT_ID_HEADER_NAME, remote.getId());

    if (cometdMessage != null && cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME) != null) {
        message.setHeader(COMETD_SUBSCRIPTION_HEADER_NAME, cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME));
    }
    
    if (enableSessionHeader) {
        addSessionAttributesToMessageHeaders(remote, message);
    }

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

示例8: populateMessage

import org.apache.camel.Message; //导入方法依赖的package包/类
public void populateMessage(Exchange exchange, long messageIndex) throws Exception {
    Message in = exchange.getIn();
    in.setBody(createMessageBody(messageIndex));
    in.setHeaders(getDefaultHeaders());
    applyHeaders(exchange, messageIndex);

    if (outputTransformer != null) {
        outputTransformer.process(exchange);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:DataSetSupport.java

示例9: onExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    boolean fromTemplate;
    String newResourceUri = exchange.getIn().getHeader(CHUNK_RESOURCE_URI, String.class);
    if (newResourceUri == null) {
        String newTemplate = exchange.getIn().getHeader(CHUNK_TEMPLATE, String.class);
        Chunk newChunk;
        if (newTemplate == null) {
            fromTemplate = false;
            newChunk = getOrCreateChunk(theme, fromTemplate);
        } else {
            fromTemplate = true;
            newChunk = createChunk(new StringReader(newTemplate), theme, fromTemplate);
            exchange.getIn().removeHeader(CHUNK_TEMPLATE);
        }

        // Execute Chunk
        Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);
        StringWriter writer = new StringWriter();
        newChunk.putAll(variableMap);
        newChunk.render(writer);
        writer.flush();

        // Fill out message
        Message out = exchange.getOut();
        out.setBody(newChunk.toString());
        out.setHeaders(exchange.getIn().getHeaders());
        out.setAttachments(exchange.getIn().getAttachments());
    } else {
        exchange.getIn().removeHeader(ChunkConstants.CHUNK_RESOURCE_URI);
        ChunkEndpoint newEndpoint = getCamelContext().getEndpoint(CHUNK_ENDPOINT_URI_PREFIX + newResourceUri, ChunkEndpoint.class);
        newEndpoint.onExchange(exchange);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:35,代码来源:ChunkEndpoint.java

示例10: onExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    String path = getResourceUri();
    ObjectHelper.notNull(path, "resourceUri");

    String newResourceUri = exchange.getIn().getHeader(JoltConstants.JOLT_RESOURCE_URI, String.class);
    if (newResourceUri != null) {
        exchange.getIn().removeHeader(JoltConstants.JOLT_RESOURCE_URI);

        log.debug("{} set to {} creating new endpoint to handle exchange", JoltConstants.JOLT_RESOURCE_URI, newResourceUri);
        JoltEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
        newEndpoint.onExchange(exchange);
        return;
    }
    Object input;
    if (getInputType() == JoltInputOutputType.JsonString) {
        input = JsonUtils.jsonToObject(exchange.getIn().getBody(InputStream.class));
    } else {
        input = exchange.getIn().getBody();
    }
    Object output = getTransform().transform(input);
            
    // now lets output the results to the exchange
    Message out = exchange.getOut();
    if (getOutputType() == JoltInputOutputType.JsonString) {
        out.setBody(JsonUtils.toJsonString(output));
    } else {
        out.setBody(output);
    }
    out.setHeaders(exchange.getIn().getHeaders());
    out.setAttachments(exchange.getIn().getAttachments());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:JoltEndpoint.java

示例11: onExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    String newResourceUri = exchange.getIn().getHeader(MUSTACHE_RESOURCE_URI, String.class);
    if (newResourceUri == null) {
        // Get Mustache
        String newTemplate = exchange.getIn().getHeader(MUSTACHE_TEMPLATE, String.class);
        Mustache newMustache;
        if (newTemplate == null) {
            newMustache = getOrCreateMustache();
        } else {
            newMustache = createMustache(new StringReader(newTemplate), "mustache:temp#" + newTemplate.hashCode());
            exchange.getIn().removeHeader(MUSTACHE_TEMPLATE);
        }

        // Execute Mustache
        Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);
        StringWriter writer = new StringWriter();
        newMustache.execute(writer, variableMap);
        writer.flush();

        // Fill out message
        Message out = exchange.getOut();
        out.setBody(writer.toString());
        out.setHeaders(exchange.getIn().getHeaders());
        out.setAttachments(exchange.getIn().getAttachments());
    } else {
        exchange.getIn().removeHeader(MustacheConstants.MUSTACHE_RESOURCE_URI);
        MustacheEndpoint newEndpoint = getCamelContext().getEndpoint(MUSTACHE_ENDPOINT_URI_PREFIX + newResourceUri, MustacheEndpoint.class);
        newEndpoint.onExchange(exchange);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:32,代码来源:MustacheEndpoint.java

示例12: populateResponse

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

    Message answer = exchange.getOut();

    answer.setHeaders(in.getHeaders());
    answer.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode);
    answer.setBody("Not exactly the message the server returned.");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:JettyHttpBindingRefTest.java

示例13: onExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    Message incomingMessage = exchange.getIn();
    String newResourceUri = incomingMessage.getHeader(AtlasConstants.ATLAS_RESOURCE_URI, String.class);
    if (newResourceUri != null) {
        incomingMessage.removeHeader(AtlasConstants.ATLAS_RESOURCE_URI);

        log.debug("{} set to {} creating new endpoint to handle exchange", AtlasConstants.ATLAS_RESOURCE_URI,
                newResourceUri);
        AtlasEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
        newEndpoint.onExchange(exchange);
        return;
    }

    AtlasSession atlasSession = getAtlasContext(incomingMessage).createSession();
    boolean sourceIsXmlOrJson = isSourceXmlOrJson(atlasSession.getMapping());
    Object body = incomingMessage.getBody();
    if (sourceIsXmlOrJson && body instanceof InputStream) {
        // read the whole stream into a String
        // the XML and JSON parsers expect that
        body = incomingMessage.getBody(String.class);
    }

    // TODO Lookup multiple inputs and map with corresponding source docId
    //      https://github.com/atlasmap/camel-atlasmap/issues/18
    atlasSession.setInput(body);
    atlasContext.process(atlasSession);

    List<Audit> errors = new ArrayList<>();
    for (Audit audit : atlasSession.getAudits().getAudit()) {
        switch (audit.getStatus()) {
        case ERROR:
            errors.add(audit);
            break;
        case WARN:
            LOG.warn("{}: docId='{}', path='{}'", audit.getMessage(), audit.getDocId(), audit.getPath());
            break;
        default:
            LOG.info("{}: docId='{}', path='{}'", audit.getMessage(), audit.getDocId(), audit.getPath());
        }
    }
    if (!errors.isEmpty()) {
        StringBuilder buf = new StringBuilder("Errors: ");
        errors.stream().forEach(a -> buf.append(
                String.format("[%s: docId='%s', path='%s'], ", a.getMessage(), a.getDocId(), a.getPath())));
        throw new AtlasException(buf.toString());
    }

    // now lets output the results to the exchange
    Message out = exchange.getOut();
    out.setBody(atlasSession.getOutput());
    out.setHeaders(incomingMessage.getHeaders());
    out.setAttachments(incomingMessage.getAttachments());
}
 
开发者ID:atlasmap,项目名称:camel-atlasmap,代码行数:55,代码来源:AtlasEndpoint.java

示例14: onExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    String path = getResourceUri();
    ObjectHelper.notNull(path, "resourceUri");

    String newResourceUri = exchange.getIn().getHeader(VelocityConstants.VELOCITY_RESOURCE_URI, String.class);
    if (newResourceUri != null) {
        exchange.getIn().removeHeader(VelocityConstants.VELOCITY_RESOURCE_URI);

        log.debug("{} set to {} creating new endpoint to handle exchange", VelocityConstants.VELOCITY_RESOURCE_URI, newResourceUri);
        VelocityEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
        newEndpoint.onExchange(exchange);
        return;
    }

    Reader reader;
    String content = exchange.getIn().getHeader(VelocityConstants.VELOCITY_TEMPLATE, String.class);
    if (content != null) {
        // use content from header
        reader = new StringReader(content);
        if (log.isDebugEnabled()) {
            log.debug("Velocity content read from header {} for endpoint {}", VelocityConstants.VELOCITY_TEMPLATE, getEndpointUri());
        }
        // remove the header to avoid it being propagated in the routing
        exchange.getIn().removeHeader(VelocityConstants.VELOCITY_TEMPLATE);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Velocity content read from resource {} with resourceUri: {} for endpoint {}", new Object[]{getResourceUri(), path, getEndpointUri()});
        }
        reader = getEncoding() != null ? new InputStreamReader(getResourceAsInputStream(), getEncoding()) : new InputStreamReader(getResourceAsInputStream());
    }

    // getResourceAsInputStream also considers the content cache
    StringWriter buffer = new StringWriter();
    String logTag = getClass().getName();
    Context velocityContext = exchange.getIn().getHeader(VelocityConstants.VELOCITY_CONTEXT, Context.class);
    if (velocityContext == null) {
        Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);

        @SuppressWarnings("unchecked")
        Map<String, Object> supplementalMap = exchange.getIn().getHeader(VelocityConstants.VELOCITY_SUPPLEMENTAL_CONTEXT, Map.class);
        if (supplementalMap != null) {
            variableMap.putAll(supplementalMap);
        }

        velocityContext = new VelocityContext(variableMap);
    }

    // let velocity parse and generate the result in buffer
    VelocityEngine engine = getVelocityEngine();
    log.debug("Velocity is evaluating using velocity context: {}", velocityContext);
    engine.evaluate(velocityContext, buffer, logTag, reader);

    // now lets output the results to the exchange
    Message out = exchange.getOut();
    out.setBody(buffer.toString());
    out.setHeaders(exchange.getIn().getHeaders());
    out.setAttachments(exchange.getIn().getAttachments());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:60,代码来源:VelocityEndpoint.java

示例15: onExchange

import org.apache.camel.Message; //导入方法依赖的package包/类
@Override
protected void onExchange(Exchange exchange) throws Exception {
    String path = getResourceUri();
    ObjectHelper.notNull(configuration, "configuration");
    ObjectHelper.notNull(path, "resourceUri");

    String newResourceUri = exchange.getIn().getHeader(FreemarkerConstants.FREEMARKER_RESOURCE_URI, String.class);
    if (newResourceUri != null) {
        exchange.getIn().removeHeader(FreemarkerConstants.FREEMARKER_RESOURCE_URI);

        log.debug("{} set to {} creating new endpoint to handle exchange", FreemarkerConstants.FREEMARKER_RESOURCE_URI, newResourceUri);
        FreemarkerEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri);
        newEndpoint.onExchange(exchange);
        return;
    }

    Reader reader = null;
    String content = exchange.getIn().getHeader(FreemarkerConstants.FREEMARKER_TEMPLATE, String.class);
    if (content != null) {
        // use content from header
        reader = new StringReader(content);
        // remove the header to avoid it being propagated in the routing
        exchange.getIn().removeHeader(FreemarkerConstants.FREEMARKER_TEMPLATE);
    }
    Object dataModel = exchange.getIn().getHeader(FreemarkerConstants.FREEMARKER_DATA_MODEL, Object.class);
    if (dataModel == null) {
        dataModel = ExchangeHelper.createVariableMap(exchange);
    }
    // let freemarker parse and generate the result in buffer
    Template template;

    if (reader != null) {
        log.debug("Freemarker is evaluating template read from header {} using context: {}", FreemarkerConstants.FREEMARKER_TEMPLATE, dataModel);
        template = new Template("temp", reader, new Configuration());
    } else {
        log.debug("Freemarker is evaluating {} using context: {}", path, dataModel);
        if (getEncoding() != null) {
            template = configuration.getTemplate(path, getEncoding());
        } else {
            template = configuration.getTemplate(path);
        }
    }
    StringWriter buffer = new StringWriter();
    template.process(dataModel, buffer);
    buffer.flush();

    // now lets output the results to the exchange
    Message out = exchange.getOut();
    out.setBody(buffer.toString());
    out.setHeaders(exchange.getIn().getHeaders());
    out.setAttachments(exchange.getIn().getAttachments());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:53,代码来源:FreemarkerEndpoint.java


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