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

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

本文整理了Java中org.apache.camel.Message.setAttachments()方法的一些代码示例,展示了Message.setAttachments()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setAttachments()方法的具体详情如下:
包路径:org.apache.camel.Message
类名称:Message
方法名:setAttachments

Message.setAttachments介绍

暂无

代码示例

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

/**
 * Propagates (copies) the {@code Body}, the {@code Attachments} and the {@code Headers} of the {@link Message}
 * from from IN to OUT.
 *
 * @param exchange the exchange message
 */
public static void propagateMessage(Exchange exchange) {
  Assert.notNull(exchange, "the exchange must not be null");
  // copy headers from IN to OUT to propagate them
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  // copy attachments from IN to OUT to propagate them
  exchange.getOut().setAttachments(exchange.getIn().getAttachments());
  // copy body from IN to OUT to propagate it
  exchange.getOut().setBody(exchange.getIn().getBody());
}

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

public void process(Exchange exchange) throws Exception {
  String filter = exchange.getIn().getBody(String.class);
  DirContext dirContext = getDirContext();
  try {
    // could throw NamingException
    List<SearchResult> data;
    if (pageSize == null) {
      data = simpleSearch(dirContext, filter);
    } else {
      if (!(dirContext instanceof LdapContext)) {
        throw new IllegalArgumentException("When using attribute 'pageSize' for a ldap endpoint, you must provide a LdapContext (subclass of DirContext)");
      }
      data = pagedSearch((LdapContext) dirContext, filter);
    }
    exchange.getOut().setBody(data);
    exchange.getOut().setHeaders(exchange.getIn().getHeaders());
    exchange.getOut().setAttachments(exchange.getIn().getAttachments());
  } finally {
    if (dirContext != null) {
      dirContext.close();
    }
  }
}

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

@Override
public void process(Exchange exchange) throws Exception {
  TikaOperation operation = this.tikaConfiguration.getOperation();
  Object result;
  switch (operation) {
  case detect:
    result = doDetect(exchange);
    break;
  case parse:
    result = doParse(exchange);
    break;
  default:
    throw new IllegalArgumentException(String.format("Unknown operation %s", tikaConfiguration.getOperation()));
  }
  // propagate headers
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  exchange.getOut().setAttachments(exchange.getIn().getAttachments());
  // and set result
  exchange.getOut().setBody(result);
}

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

exchange.getOut().setAttachments(exchange.getIn().getAttachments());
  exchange.getOut().setBody(dataStore.get(key));
} else if (KratiConstants.KRATI_OPERATION_DELETE.equals(operation) && key != null) {
    exchange.getOut().setAttachments(exchange.getIn().getAttachments());
    exchange.getOut().setHeader(KratiConstants.KRATI_OPERATION_STATUS, KratiConstants.KRATI_OPERATION_SUCESSFUL);
  } else {
    exchange.getOut().setHeaders(exchange.getIn().getHeaders());
    exchange.getOut().setAttachments(exchange.getIn().getAttachments());
    exchange.getOut().setHeader(KratiConstants.KRATI_OPERATION_STATUS, KratiConstants.KRATI_OPERATION_FAILURE);
    dataStore.clear();
    exchange.getOut().setHeaders(exchange.getIn().getHeaders());
    exchange.getOut().setAttachments(exchange.getIn().getAttachments());
    exchange.getOut().setHeader(KratiConstants.KRATI_OPERATION_STATUS, KratiConstants.KRATI_OPERATION_SUCESSFUL);
  } catch (Exception e) {

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

@Override
public void process(Exchange exchange) throws Exception {
  Object result;
  switch (pdfConfiguration.getOperation()) {
  case append:
    result = doAppend(exchange);
    break;
  case create:
    result = doCreate(exchange);
    break;
  case extractText:
    result = doExtractText(exchange);
    break;
  default:
    throw new IllegalArgumentException(String.format("Unknown operation %s", pdfConfiguration.getOperation()));
  }
  // propagate headers
  exchange.getOut().setHeaders(exchange.getIn().getHeaders());
  exchange.getOut().setAttachments(exchange.getIn().getAttachments());
  // and set result
  exchange.getOut().setBody(result);
}

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

@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);
  }
}

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

@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());
  }
}

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

out.setBody(buffer.toString());
out.setHeaders(exchange.getIn().getHeaders());
out.setAttachments(exchange.getIn().getAttachments());

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

@Override
  public void process(Exchange exchange) throws Exception {
    final Message in = exchange.getIn();
    String command = in.getMandatoryBody(String.class);

    final Map<String, Object> headers = exchange.getIn().getHeaders();

    try {
      String knownHostResource = endpoint.getKnownHostsResource();
      if (knownHostResource != null) {
        client.setServerKeyVerifier(new ResourceBasedSSHKeyVerifier(exchange.getContext(), knownHostResource,
            endpoint.isFailOnUnknownHost()));
      }
      SshResult result = SshHelper.sendExecCommand(headers, command, endpoint, client);
      exchange.getOut().setBody(result.getStdout());
      exchange.getOut().setHeader(SshResult.EXIT_VALUE, result.getExitValue());
      exchange.getOut().setHeader(SshResult.STDERR, result.getStderr());
    } catch (Exception e) {
      throw new CamelExchangeException("Cannot execute command: " + command, exchange, e);
    }

    // propagate headers and attachments
    exchange.getOut().getHeaders().putAll(in.getHeaders());
    exchange.getOut().setAttachments(in.getAttachments());
  }
}

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

out.setBody(newChunk.toString());
  out.setHeaders(exchange.getIn().getHeaders());
  out.setAttachments(exchange.getIn().getAttachments());
} else {
  exchange.getIn().removeHeader(ChunkConstants.CHUNK_RESOURCE_URI);

代码示例来源:origin: io.atlasmap/camel-atlasmap

private void populateTargetDocuments(AtlasSession session, Exchange exchange) {
  Message outMessage = exchange.getOut();
  outMessage.setHeaders(exchange.getIn().getHeaders());
  outMessage.setAttachments(exchange.getIn().getAttachments());

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

out.setBody(result.toString());
out.setHeaders(exchange.getIn().getHeaders());
out.setAttachments(exchange.getIn().getAttachments());

代码示例来源:origin: org.milyn/milyn-smooks-all

exchange.getOut().setAttachments(exchange.getIn().getAttachments());

代码示例来源:origin: org.dhatim/milyn-smooks-camel

exchange.getOut().setAttachments(exchange.getIn().getAttachments());

相关文章