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

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

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

Message.copyFromWithNewBody介绍

暂无

代码示例

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

@Override
  public void doWithMessage(WebServiceMessage responseMessage) throws IOException, TransformerException {
    SoapMessage soapMessage = (SoapMessage) responseMessage;
    if (ExchangeHelper.isOutCapable(exchange)) {
      exchange.getOut().copyFromWithNewBody(exchange.getIn(), soapMessage.getPayloadSource());
      populateHeaderAndAttachmentsFromResponse(exchange.getOut(), soapMessage);
    } else {
      exchange.getIn().setBody(soapMessage.getPayloadSource());
      populateHeaderAndAttachmentsFromResponse(exchange.getIn(), soapMessage);
    }
  }
});

代码示例来源:origin: io.syndesis.connector/connector-support-processor

@Override
public void process(Exchange exchange) throws Exception {
  final Message message = exchange.getIn();
  final Object body = message.getBody();
  final ObjectNode rootNode = Json.copyObjectMapperConfiguration().createObjectNode();
  if (!parameters.isEmpty()) {
    final ObjectNode parametersNode = rootNode.putObject("parameters");
    for (String parameter : parameters) {
      parametersNode.put(parameter, message.getHeader(parameter, String.class));
    }
  }
  if (body instanceof String) {
    final String string = (String) body;
    if (ObjectHelper.isNotEmpty(string)) {
      rootNode.set("body", READER.readValue(string));
    }
  } else if (body instanceof InputStream) {
    try (InputStream stream = (InputStream) body) {
      if (stream.available() > 0) {
        rootNode.set("body", READER.readValue(stream));
      }
    }
  } else if (body != null) {
    rootNode.putPOJO("body", body);
  }
  final String newBody = Json.toString(rootNode);
  final Message replacement = new DefaultMessage(exchange.getContext());
  replacement.copyFromWithNewBody(message, newBody);
  ExchangeHelper.replaceMessage(exchange, replacement, false);
}

相关文章