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

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

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

Message.getAttachments介绍

暂无

代码示例

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

/**
 * Populate SOAP attachments from in or out exchange message. This the
 * convenient method for overriding.
 * 
 * @param inOrOut
 * @param response
 */
protected void doProcessSoapAttachments(Message inOrOut, SoapMessage response) {
  Map<String, DataHandler> attachments = inOrOut.getAttachments();
  Set<String> keySet = new HashSet<>(attachments.keySet());
  for (String key : keySet) {
    response.addAttachment(key, attachments.get(key));
  }
}

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

/**
 * Populates message attachments from soap response attachments 
 * @param inOrOut {@link Message}
 * @param soapMessage {@link SoapMessage}
 */
private void populateMessageAttachmentsFromResponse(Message inOrOut, Iterator<Attachment> attachments) {
  while (attachments.hasNext()) {
    Attachment attachment = attachments.next();
    inOrOut.getAttachments().put(attachment.getContentId(), attachment.getDataHandler());
  }
}

代码示例来源: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-mail

@Override
public Object evaluate(Exchange exchange) {
  // must use getAttachments to ensure attachments is initial populated
  if (exchange.getIn().getAttachments().isEmpty()) {
    return null;
  }
  try {
    List<Message> answer = new ArrayList<>();
    Message inMessage = exchange.getIn();
    for (Map.Entry<String, Attachment> entry : inMessage.getAttachmentObjects().entrySet()) {
      Message attachmentMessage;
      if (extractAttachments) {
        attachmentMessage = extractAttachment(inMessage, entry.getKey());
      } else {
        attachmentMessage = splitAttachment(inMessage, entry.getKey(), entry.getValue());
      }
      if (attachmentMessage != null) {
        answer.add(attachmentMessage);
      }
    }
    return answer;
  } catch (Exception e) {
    throw new RuntimeCamelException("Unable to split attachments from MimeMultipart message", e);
  }
}

代码示例来源: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-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-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-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-mail

exchange.getIn().getBody();
exchange.getIn().getHeaders();
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: org.switchyard.components/switchyard-component-common-camel

for (Entry<String, DataHandler> entry : sourceMessage.getAttachments().entrySet()) {
  message.addAttachment(entry.getKey(), entry.getValue().getDataSource());

代码示例来源: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: jboss-switchyard/components

for (Entry<String, DataHandler> entry : sourceMessage.getAttachments().entrySet()) {
  message.addAttachment(entry.getKey(), entry.getValue().getDataSource());

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

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

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

@Override
public void copyFrom(org.apache.camel.Message that) {
  if (that == this) {
    // the same instance so do not need to copy
    return;
  }
  if (that instanceof CamelContextAware) {
    this.setCamelContext(((CamelContextAware) that).getCamelContext());
  }
  // cover over exchange if none has been assigned
  if (getExchange() == null) {
    setExchange(that.getExchange());
  }
  setMessageId(that.getMessageId());
  setBody(that.getBody());
  super.getHeaders().putAll(that.getHeaders());
  if (that instanceof SpringIntegrationMessage) {
    SpringIntegrationMessage orig = (SpringIntegrationMessage) that;
    setMessage(orig.getMessage());
  }
  getAttachments().putAll(that.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());

相关文章