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


Java Message.setAttachments方法代码示例

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


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

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

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

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

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

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

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

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

示例8: 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(MvelConstants.MVEL_RESOURCE_URI, String.class);
    if (newResourceUri != null) {
        exchange.getIn().removeHeader(MvelConstants.MVEL_RESOURCE_URI);

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

    CompiledTemplate compiled;
    ParserContext mvelContext = ParserContext.create();
    Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);

    String content = exchange.getIn().getHeader(MvelConstants.MVEL_TEMPLATE, String.class);
    if (content != null) {
        // use content from header
        if (log.isDebugEnabled()) {
            log.debug("Mvel content read from header {} for endpoint {}", MvelConstants.MVEL_TEMPLATE, getEndpointUri());
        }
        // remove the header to avoid it being propagated in the routing
        exchange.getIn().removeHeader(MvelConstants.MVEL_TEMPLATE);
        compiled = TemplateCompiler.compileTemplate(content, mvelContext);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Mvel content read from resource {} with resourceUri: {} for endpoint {}", new Object[]{getResourceUri(), path, getEndpointUri()});
        }
        // getResourceAsInputStream also considers the content cache
        Reader reader = getEncoding() != null ? new InputStreamReader(getResourceAsInputStream(), getEncoding()) : new InputStreamReader(getResourceAsInputStream());
        String template = IOConverter.toString(reader);
        if (!template.equals(this.template)) {
            this.template = template;
            this.compiled = TemplateCompiler.compileTemplate(template, mvelContext);
        }
        compiled = this.compiled;
    }

    // let mvel parse and execute the template
    log.debug("Mvel is evaluating using mvel context: {}", variableMap);
    Object result = TemplateRuntime.execute(compiled, mvelContext, variableMap);

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


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